//---------------------------------------------------- void CEditableMesh::Transform(const Fmatrix& parent) { // transform position for(u32 k=0; k<m_VertCount; k++) parent.transform_tiny(m_Verts[k]); // RecomputeBBox RecomputeBBox (); // update normals & cform #ifdef _EDITOR UnloadRenderBuffers (); UnloadCForm (); #endif UnloadFNormals (true); UnloadVNormals (true); UnloadSVertices (true); }
void CEditableMesh::Clear() { #ifdef _EDITOR UnloadRenderBuffers (); #endif UnloadAdjacency (); UnloadCForm (); UnloadFNormals (); UnloadVNormals (); UnloadSVertices (); VERIFY (m_FNormalsRefs==0 && m_VNormalsRefs==0 && m_AdjsRefs==0 && m_SVertRefs==0); xr_free (m_Verts); xr_free (m_Faces); for (VMapIt vm_it=m_VMaps.begin(); vm_it!=m_VMaps.end(); vm_it++) xr_delete (*vm_it); m_VMaps.clear (); m_SurfFaces.clear (); for (VMRefsIt ref_it=m_VMRefs.begin(); ref_it!=m_VMRefs.end(); ref_it++) xr_free (ref_it->pts); m_VMRefs.clear (); }
void CEditableMesh::Optimize(BOOL NoOpt) { if (!NoOpt){ #ifdef _EDITOR UnloadRenderBuffers (); UnloadCForm (); #endif UnloadFNormals (true); UnloadVNormals (true); UnloadSVertices (true); UnloadAdjacency (true); // clear static data for (int x=0; x<MX+1; x++) for (int y=0; y<MY+1; y++) for (int z=0; z<MZ+1; z++) VM[x][y][z].clear(); VMscale.set(m_Box.max.x-m_Box.min.x+EPS_S, m_Box.max.y-m_Box.min.y+EPS_S, m_Box.max.z-m_Box.min.z+EPS_S); VMmin.set(m_Box.min.x, m_Box.min.y, m_Box.min.z); VMeps.set(VMscale.x/MX/2,VMscale.y/MY/2,VMscale.z/MZ/2); VMeps.x = (VMeps.x<EPS_L)?VMeps.x:EPS_L; VMeps.y = (VMeps.y<EPS_L)?VMeps.y:EPS_L; VMeps.z = (VMeps.z<EPS_L)?VMeps.z:EPS_L; m_NewPoints.clear(); m_NewPoints.reserve(m_VertCount); boolVec faces_mark; faces_mark.resize(m_FaceCount,false); int i_del_face = 0; for (u32 k=0; k<m_FaceCount; k++){ if (!OptimizeFace(m_Faces[k])){ faces_mark[k] = true; i_del_face ++; } } m_VertCount = m_NewPoints.size(); xr_free (m_Verts); m_Verts = xr_alloc<Fvector>(m_VertCount); Memory.mem_copy (m_Verts,&*m_NewPoints.begin(),m_NewPoints.size()*sizeof(Fvector)); if (i_del_face){ st_Face* old_faces = m_Faces; u32* old_sg = m_SGs; m_Faces = xr_alloc<st_Face> (m_FaceCount-i_del_face); m_SGs = xr_alloc<u32> (m_FaceCount-i_del_face); u32 new_dk = 0; for (u32 dk=0; dk<m_FaceCount; dk++){ if (faces_mark[dk]){ for (SurfFacesPairIt plp_it=m_SurfFaces.begin(); plp_it!=m_SurfFaces.end(); plp_it++){ IntVec& pol_lst = plp_it->second; for (int k=0; k<int(pol_lst.size()); k++){ int& f = pol_lst[k]; if (f>(int)dk){ f--; }else if (f==(int)dk){ pol_lst.erase(pol_lst.begin()+k); k--; } } } continue; } m_Faces[new_dk] = old_faces[dk]; m_SGs[new_dk] = old_sg[dk]; new_dk++; } m_FaceCount = m_FaceCount-i_del_face; xr_free (old_faces); xr_free (old_sg); } } }