示例#1
0
        public bool FindHitVertex(Ray3f sceneRay, MeshEditorOpType.BoundaryType boundaryMode, ref Frame3f hitFrameS, ref int hitVID)
        {
            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);
            }

            Index3i vt = PreviewMesh.GetTriangle(hit_tri);

            hitVID = -1; double near_sqr = double.MaxValue;
            for (int j = 0; j < 3; ++j)
            {
                Vector3f v = (Vector3f)PreviewMesh.GetVertex(vt[j]);
                if (objRay.DistanceSquared(v) < near_sqr)
                {
                    near_sqr = objRay.DistanceSquared(v);
                    hitVID   = vt[j];
                }
            }
            if (boundaryMode != MeshEditorOpType.BoundaryType.Any)
            {
                bool is_boundary = PreviewMesh.IsBoundaryVertex(hitVID);
                if ((is_boundary && boundaryMode == MeshEditorOpType.BoundaryType.OnlyInternal) ||
                    (is_boundary == false && boundaryMode == MeshEditorOpType.BoundaryType.OnlyBoundary))
                {
                    return(false);
                }
            }

            Frame3f hitFrameL = new Frame3f(PreviewMesh.GetVertex(hitVID), PreviewMesh.GetTriNormal(hit_tri));

            hitFrameS = SceneTransforms.ObjectToScene(previewSO, hitFrameL);

            return(true);
        }
示例#2
0
        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);
            }
        }