public void FlipEdge(int eid, bool bInteractive) { if (PreviewMesh.IsEdge(eid) == false) { DebugUtil.Log("MeshEditorTool.FlipEdge: invalid eid!"); return; } RemoveTrianglesMeshChange removeChange = null; AddTrianglesMeshChange addChange = null; previewSO.EditAndUpdateMesh((mesh) => { removeChange = new RemoveTrianglesMeshChange(); removeChange.InitializeFromExisting(mesh, get_edge_tris(mesh, eid)); DMesh3.EdgeFlipInfo flipInfo; if (mesh.FlipEdge(eid, out flipInfo) == MeshResult.Ok) { PreviewSpatial.RemoveTriangle(flipInfo.t0); PreviewSpatial.RemoveTriangle(flipInfo.t1); PreviewSpatial.AddTriangle(flipInfo.t0); PreviewSpatial.AddTriangle(flipInfo.t1); addChange = new AddTrianglesMeshChange(); addChange.InitializeFromExisting(mesh, null, get_edge_tris(mesh, eid)); } }, GeometryEditTypes.ArbitraryEdit); if (addChange != null) { add_replace_change(removeChange, addChange, bInteractive); } }
public override OpStatus Cull() { Target = null; RemoveChange = null; AddChange = null; return(OpStatus.Success); }
public void ApplyInitialize(IEnumerable <int> triangles) { if (MeshChange != null) { throw new Exception("RemoveTrianglesChange.ApplyInitialize: change is already initialized!"); } MeshChange = new RemoveTrianglesMeshChange(); Target.EditAndUpdateMesh( (mesh) => { MeshChange.InitializeFromApply(mesh, triangles); }, GeometryEditTypes.ArbitraryEdit ); }
public void SplitEdge(int eid, Frame3f posL, bool bInteractive) { if (PreviewMesh.IsEdge(eid) == false) { DebugUtil.Log("MeshEditorTool.SplitEdge: invalid eid!"); return; } Index2i et = PreviewMesh.GetEdgeT(eid); RemoveTrianglesMeshChange removeChange = null; AddTrianglesMeshChange addChange = null; previewSO.EditAndUpdateMesh((mesh) => { removeChange = new RemoveTrianglesMeshChange(); List <int> input_tris = get_edge_tris(mesh, eid); removeChange.InitializeFromExisting(mesh, input_tris); DMesh3.EdgeSplitInfo splitInfo; if (mesh.SplitEdge(eid, out splitInfo) == MeshResult.Ok) { PreviewSpatial.RemoveTriangle(et.a); if (et.b != DMesh3.InvalidID) { PreviewSpatial.RemoveTriangle(et.b); } PreviewSpatial.AddTriangle(et.a); if (et.b != DMesh3.InvalidID) { PreviewSpatial.AddTriangle(et.b); } PreviewSpatial.AddTriangle(splitInfo.eNewT2); input_tris.Add(splitInfo.eNewT2); if (splitInfo.eNewT3 != DMesh3.InvalidID) { PreviewSpatial.AddTriangle(splitInfo.eNewT3); input_tris.Add(splitInfo.eNewT3); } mesh.SetVertex(splitInfo.vNew, posL.Origin); addChange = new AddTrianglesMeshChange(); addChange.InitializeFromExisting(mesh, new List <int>() { splitInfo.vNew }, input_tris); } }, GeometryEditTypes.ArbitraryEdit); if (addChange != null) { add_replace_change(removeChange, addChange, bInteractive); } }
void add_replace_change(RemoveTrianglesMeshChange remove, AddTrianglesMeshChange add, bool bInteractive) { remove.OnApplyF = remove_from_spatial; remove.OnRevertF = add_to_spatial; add.OnApplyF = add_to_spatial; add.OnRevertF = remove_from_spatial; ReplaceTrianglesChange change = new ReplaceTrianglesChange(previewSO, remove, add); Scene.History.PushChange(change, true); if (bInteractive) { Scene.History.PushInteractionCheckpoint(); } }
void do_remove_triangles(IEnumerable <int> tris, bool bInteractive) { RemoveTrianglesMeshChange remove = new RemoveTrianglesMeshChange() { OnApplyF = remove_from_spatial, OnRevertF = add_to_spatial }; remove.InitializeFromExisting(previewSO.Mesh, tris); RemoveTrianglesChange change = new RemoveTrianglesChange(previewSO, remove); Scene.History.PushChange(change, false); if (bInteractive) { Scene.History.PushInteractionCheckpoint(); } }
public void PokeFace(int tid, Frame3f posL, bool bInteractive) { if (PreviewMesh.IsTriangle(tid) == false) { DebugUtil.Log("MeshEditorTool.PokeFace: invalid tid!"); return; } Vector3d baryCoords = MeshQueries.BaryCoords(PreviewMesh, tid, posL.Origin); RemoveTrianglesMeshChange removeChange = null; AddTrianglesMeshChange addChange = null; previewSO.EditAndUpdateMesh((mesh) => { removeChange = new RemoveTrianglesMeshChange(); removeChange.InitializeFromExisting(mesh, new List <int>() { tid }); DMesh3.PokeTriangleInfo pokeInfo; if (mesh.PokeTriangle(tid, baryCoords, out pokeInfo) == MeshResult.Ok) { PreviewSpatial.RemoveTriangle(tid); PreviewSpatial.AddTriangle(tid); PreviewSpatial.AddTriangle(pokeInfo.new_t1); PreviewSpatial.AddTriangle(pokeInfo.new_t2); addChange = new AddTrianglesMeshChange(); addChange.InitializeFromExisting(mesh, new List <int>() { pokeInfo.new_vid }, new List <int>() { tid, pokeInfo.new_t1, pokeInfo.new_t2 }); } }, GeometryEditTypes.ArbitraryEdit); if (addChange != null) { add_replace_change(removeChange, addChange, bInteractive); } }
public static void test_remove_change_construct() { DMesh3 testMesh = TestUtil.LoadTestInputMesh("bunny_open_base.obj"); Random r = new Random(31337); //int N = 100; int N = 10; int[] indices = TestUtil.RandomIndices(N, r, testMesh.MaxVertexID); for (int ii = 0; ii < N; ++ii) { MeshFaceSelection selection = new MeshFaceSelection(testMesh); selection.SelectVertexOneRing(indices[ii]); selection.ExpandToOneRingNeighbours(8); RemoveTrianglesMeshChange change = new RemoveTrianglesMeshChange(); change.InitializeFromExisting(testMesh, selection); DMesh3 removed = new DMesh3(testMesh); MeshEditor.RemoveTriangles(removed, selection); DMesh3 changeCopy = new DMesh3(testMesh); change.Apply(changeCopy); changeCopy.CheckValidity(true); if (!changeCopy.IsSameMesh(removed, true)) { System.Console.WriteLine("FAILED copy.IsSameMesh() 1"); } change.Revert(changeCopy); changeCopy.CheckValidity(false); if (!changeCopy.IsSameMesh(testMesh, true)) { System.Console.WriteLine("FAILED copy.IsSameMesh() 1"); } } System.Console.WriteLine("test_remove_change_construct ok"); }
public static void test_remove_change_apply() { DMesh3 testMesh = TestUtil.LoadTestInputMesh("bunny_solid.obj"); DMesh3 copy = new DMesh3(testMesh); Vector3d c = testMesh.CachedBounds.Center; MeshFaceSelection selection = new MeshFaceSelection(testMesh); foreach (int tid in testMesh.TriangleIndices()) { if (testMesh.GetTriCentroid(tid).x > c.x) { selection.Select(tid); } } RemoveTrianglesMeshChange change = new RemoveTrianglesMeshChange(); change.InitializeFromApply(testMesh, selection); testMesh.CheckValidity(true); change.Apply(copy); copy.CheckValidity(true); if (!copy.IsSameMesh(testMesh, true)) { System.Console.WriteLine("FAILED copy.IsSameMesh() 1"); } change.Revert(testMesh); testMesh.CheckValidity(false); change.Revert(copy); copy.CheckValidity(false); if (!copy.IsSameMesh(testMesh, true)) { System.Console.WriteLine("FAILED copy.IsSameMesh() 1"); } System.Console.WriteLine("test_remove_change_apply ok"); }
public void CollapseEdge(int eid, Frame3f posL, bool bInteractive) { if (PreviewMesh.IsEdge(eid) == false) { DebugUtil.Log("MeshEditorTool.CollapseEdge: invalid eid!"); return; } Index2i ev = PreviewMesh.GetEdgeV(eid); int keep = ev.a, discard = ev.b; bool boundarya = PreviewMesh.IsBoundaryVertex(keep); bool boundaryb = PreviewMesh.IsBoundaryVertex(discard); if (boundaryb && !boundarya) { keep = ev.b; discard = ev.a; } HashSet <int> removeT = new HashSet <int>(); foreach (int tid in PreviewMesh.VtxTrianglesItr(keep)) { removeT.Add(tid); } foreach (int tid in PreviewMesh.VtxTrianglesItr(discard)) { removeT.Add(tid); } RemoveTrianglesMeshChange removeChange = null; AddTrianglesMeshChange addChange = null; previewSO.EditAndUpdateMesh((mesh) => { removeChange = new RemoveTrianglesMeshChange(); removeChange.InitializeFromExisting(mesh, removeT); DMesh3.EdgeCollapseInfo collapseInfo; if (mesh.CollapseEdge(keep, discard, out collapseInfo) == MeshResult.Ok) { foreach (int tid in removeT) { PreviewSpatial.RemoveTriangle(tid); } foreach (int tid in PreviewMesh.VtxTrianglesItr(keep)) { PreviewSpatial.AddTriangle(tid); } if (boundarya == false & boundaryb == false) { mesh.SetVertex(keep, posL.Origin); } addChange = new AddTrianglesMeshChange(); addChange.InitializeFromExisting(mesh, new List <int>() { keep }, get_vtx_tris(mesh, keep)); } }, GeometryEditTypes.ArbitraryEdit); if (addChange != null) { add_replace_change(removeChange, addChange, bInteractive); } }
public RemoveTrianglesChange(DMeshSO target, RemoveTrianglesMeshChange change) { Target = target; MeshChange = change; }
public ReplaceTrianglesChange(DMeshSO target, RemoveTrianglesMeshChange remove, AddTrianglesMeshChange add) { RemoveChange = remove; AddChange = add; Target = target; }
public override OpStatus Cull() { Target = null; MeshChange = null; return(OpStatus.Success); }