public bool FindHitEdge(Ray3f sceneRay, MeshEditorOpType.BoundaryType boundaryMode, bool snap_to_center, ref Frame3f hitFrameS, ref int hitEID) { Ray3f objRay = SceneTransforms.SceneToObject(Target, sceneRay); int hit_tri = PreviewSpatial.FindNearestHitTriangle(objRay); if (hit_tri == DMesh3.InvalidID) { return(false); } if (allow_backface_hits == false && is_back_facing(hit_tri)) { return(false); } var intr = MeshQueries.TriangleIntersection(PreviewMesh, hit_tri, objRay); int e_idx = -1; double near_sqr = double.MaxValue; DistRay3Segment3 near_dist = null; for (int j = 0; j < 3; ++j) { Segment3d seg = new Segment3d(intr.Triangle[j], intr.Triangle[(j + 1) % 3]); DistRay3Segment3 dist = new DistRay3Segment3(objRay, seg); if (dist.GetSquared() < near_sqr) { near_sqr = dist.GetSquared(); near_dist = dist; e_idx = j; } } int eid = PreviewMesh.GetTriEdge(hit_tri, e_idx); if (boundaryMode != MeshEditorOpType.BoundaryType.Any) { bool is_boundary = PreviewMesh.IsBoundaryEdge(eid); if ((is_boundary && boundaryMode == MeshEditorOpType.BoundaryType.OnlyInternal) || (is_boundary == false && boundaryMode == MeshEditorOpType.BoundaryType.OnlyBoundary)) { return(false); } } if (snap_to_center) { Frame3f hitFrameL = new Frame3f(PreviewMesh.GetEdgePoint(eid, 0.5), PreviewMesh.GetTriNormal(hit_tri)); hitFrameS = SceneTransforms.ObjectToScene(previewSO, hitFrameL); } else { Frame3f hitFrameL = new Frame3f(near_dist.SegmentClosest, PreviewMesh.GetTriNormal(hit_tri)); hitFrameS = SceneTransforms.ObjectToScene(previewSO, hitFrameL); } hitEID = eid; return(true); }
public void BridgeEdges(int ea, int eb, bool bInteractive) { if (PreviewMesh.IsEdge(ea) == false || PreviewMesh.IsEdge(eb) == false) { DebugUtil.Log("MeshEditorTool.BridgeEdges: invalid eid!"); return; } if (PreviewMesh.IsBoundaryEdge(ea) == false || PreviewMesh.IsBoundaryEdge(eb) == false) { DebugUtil.Log("MeshEditorTool.BridgeEdges: edge is not boundary edge!"); return; } Index2i eva = PreviewMesh.GetOrientedBoundaryEdgeV(ea); Index2i evb = PreviewMesh.GetOrientedBoundaryEdgeV(eb); AddTrianglesMeshChange addChange = null; previewSO.EditAndUpdateMesh((mesh) => { int shared_v = IndexUtil.find_shared_edge_v(ref eva, ref evb); if (shared_v == DMesh3.InvalidID) { int t1 = mesh.AppendTriangle(eva.b, eva.a, evb.b); int t2 = mesh.AppendTriangle(evb.b, evb.a, eva.b); PreviewSpatial.AddTriangle(t1); PreviewSpatial.AddTriangle(t2); addChange = new AddTrianglesMeshChange(); addChange.InitializeFromExisting(mesh, null, new List <int>() { t1, t2 }); } else { int ovb = (evb.a == shared_v) ? evb.b : evb.a; int t = mesh.AppendTriangle(eva.b, eva.a, ovb); PreviewSpatial.AddTriangle(t); addChange = new AddTrianglesMeshChange(); addChange.InitializeFromExisting(mesh, null, new List <int>() { t }); } }, GeometryEditTypes.ArbitraryEdit); if (addChange != null) { add_change(addChange, bInteractive); } }