void ConvertToPoly::Convert (TriObject *obj, TimeValue t, MNMesh & mm, Interval & ivalid) { int keepConvex; int limitSize; int maxdeg=0; int keepPlanar; float planarThresh = 0.0f; int elimCollin; pblock->GetValue (turn_keep_convex, t, keepConvex, ivalid); pblock->GetValue (turn_limit_size, t, limitSize, ivalid); if (limitSize) pblock->GetValue (turn_max_size, t, maxdeg, ivalid); pblock->GetValue (turn_planar, t, keepPlanar, ivalid); if (keepPlanar) { pblock->GetValue (turn_thresh, t, planarThresh, ivalid); planarThresh = cosf (planarThresh); } pblock->GetValue (turn_eliminate_collinear, t, elimCollin, ivalid); mm.AddTri (obj->mesh); mm.FillInMesh (); mm.EliminateBadVerts (); if (maxdeg != 3) { if (keepPlanar) mm.FenceNonPlanarEdges (planarThresh, TRUE); mm.MakePolyMesh (maxdeg, elimCollin); if (keepConvex) mm.MakeConvex (); } mm.ClearEFlags (MN_EDGE_INVIS); switch (obj->mesh.selLevel) { case MESH_VERTEX: mm.selLevel = MNM_SL_VERTEX; break; case MESH_EDGE: mm.selLevel = MNM_SL_EDGE; break; case MESH_FACE: mm.selLevel = MNM_SL_FACE; break; default: mm.selLevel = MNM_SL_OBJECT; break; } }
void ConvertToPoly::Convert (PolyObject *obj, TimeValue t, MNMesh & mm, Interval & ivalid) { int keepConvex; int limitSize; int maxdeg=0; int keepPlanar, elimCollin; float planarThresh = 0.0f; pblock->GetValue (turn_keep_convex, t, keepConvex, ivalid); pblock->GetValue (turn_limit_size, t, limitSize, ivalid); if (limitSize) pblock->GetValue (turn_max_size, t, maxdeg, ivalid); pblock->GetValue (turn_planar, t, keepPlanar, ivalid); if (keepPlanar) { pblock->GetValue (turn_thresh, t, planarThresh, ivalid); planarThresh = cosf (planarThresh); } pblock->GetValue (turn_eliminate_collinear, t, elimCollin, ivalid); mm = obj->mm; // Luna task 747 // We cannot support specified normals in Convert to Poly at this time. mm.ClearSpecifiedNormals(); if (!mm.GetFlag (MN_MESH_FILLED_IN)) mm.FillInMesh (); if (!mm.GetFlag (MN_MESH_NO_BAD_VERTS)) mm.EliminateBadVerts (); if (maxdeg) mm.RestrictPolySize (maxdeg); if (keepConvex) mm.MakeConvex (); if (maxdeg || keepConvex) mm.ClearEFlags (MN_EDGE_INVIS); if (keepPlanar) mm.MakePlanar (planarThresh); if (elimCollin) mm.EliminateCollinearVerts (); mm.selLevel = obj->mm.selLevel; }
bool PolyOpWeldVertex::WeldShortPolyEdges (MNMesh & mesh, DWORD vertFlag) { // In order to collapse vertices, we turn them into edge selections, // where the edges are shorter than the weld threshold. bool canWeld = false; mesh.ClearEFlags (MN_USER); float threshSq = mThreshold*mThreshold; for (int i=0; i<mesh.nume; i++) { if (mesh.e[i].GetFlag (MN_DEAD)) continue; if (!mesh.v[mesh.e[i].v1].GetFlag (vertFlag)) continue; if (!mesh.v[mesh.e[i].v2].GetFlag (vertFlag)) continue; if (LengthSquared (mesh.P(mesh.e[i].v1) - mesh.P(mesh.e[i].v2)) > threshSq) continue; mesh.e[i].SetFlag (MN_USER); canWeld = true; } if (!canWeld) return false; return MNMeshCollapseEdges (mesh, MN_USER); }
// (This code was copied from EditPolyObj::EpfnCollapse.) bool VWeldMod::WeldShortPolyEdges (MNMesh & mesh, float thresh, DWORD flag) { // In order to collapse vertices, we turn them into edge selections, // where the edges are shorter than the weld threshold. bool canWeld = false; mesh.ClearEFlags (flag); float threshSq = thresh*thresh; for (int i=0; i<mesh.nume; i++) { if (mesh.e[i].GetFlag (MN_DEAD)) continue; if (!mesh.v[mesh.e[i].v1].GetFlag (flag)) continue; if (!mesh.v[mesh.e[i].v2].GetFlag (flag)) continue; if (LengthSquared (mesh.P(mesh.e[i].v1) - mesh.P(mesh.e[i].v2)) > threshSq) continue; mesh.e[i].SetFlag (flag); canWeld = true; } if (!canWeld) return false; MNMeshUtilities mmu(&mesh); return mmu.CollapseEdges (MN_USER); }