示例#1
0
        /// <summary>
        /// Find point-normal frame at ray-intersection point on mesh, or return false if no hit.
        /// Returns interpolated vertex-normal frame if available, otherwise tri-normal frame.
        /// </summary>
        public static bool RayHitPointFrame(DMesh3 mesh, ISpatial spatial, Ray3d ray, out Frame3f hitPosFrame, bool bForceFaceNormal = false)
        {
            hitPosFrame = new Frame3f();
            int tid = spatial.FindNearestHitTriangle(ray);

            if (tid == DMesh3.InvalidID)
            {
                return(false);
            }

            var isect = TriangleIntersection(mesh, tid, ray);

            if (isect.Result != IntersectionResult.Intersects)
            {
                return(false);
            }

            Vector3d surfPt = ray.PointAt(isect.RayParameter);

            if (mesh.HasVertexNormals && bForceFaceNormal == false)
            {
                hitPosFrame = SurfaceFrame(mesh, tid, surfPt);                      // TODO isect has bary-coords already!!
            }
            else
            {
                hitPosFrame = new Frame3f(surfPt, mesh.GetTriNormal(tid));
            }

            return(true);
        }