public Vector3d FindNearestAndOffset(Vector3d pos)
            {
                int tNearestID                 = Spatial.FindNearestTriangle(pos);
                DistPoint3Triangle3 q          = MeshQueries.TriangleDistance(Mesh, tNearestID, pos);
                Vector3d            vHitNormal =
                    (UseFaceNormal == false && Mesh.HasVertexNormals) ?
                    Mesh.GetTriBaryNormal(tNearestID, q.TriangleBaryCoords.x, q.TriangleBaryCoords.y, q.TriangleBaryCoords.z)
                        : Mesh.GetTriNormal(tNearestID);

                return(q.TriangleClosest + Distance * vHitNormal);
            }
示例#2
0
        /// <summary>
        /// Get point-normal frame on surface of mesh. Assumption is that point lies in tID.
        /// returns interpolated vertex-normal frame if available, otherwise tri-normal frame.
        /// </summary>
        public static Frame3f SurfaceFrame(DMesh3 mesh, int tID, Vector3d point)
        {
            if (!mesh.IsTriangle(tID))
            {
                throw new Exception("MeshQueries.SurfaceFrame: triangle " + tID + " does not exist!");
            }
            Triangle3d tri = new Triangle3d();

            mesh.GetTriVertices(tID, ref tri.V0, ref tri.V1, ref tri.V2);
            Vector3d bary = tri.BarycentricCoords(point);

            point = tri.PointAt(bary);
            if (mesh.HasVertexNormals)
            {
                Vector3d normal = mesh.GetTriBaryNormal(tID, bary.x, bary.y, bary.z);
                return(new Frame3f(point, normal));
            }
            else
            {
                return(new Frame3f(point, mesh.GetTriNormal(tID)));
            }
        }