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