BruteForceMesh.ClosestPointOnTriangleToPoint(ref UnityEngine.Vector3, ref UnityEngine.Vector3, ref UnityEngine.Vector3, ref UnityEngine.Vector3, out UnityEngine.Vector3)

Here are the examples of the csharp api BruteForceMesh.ClosestPointOnTriangleToPoint(ref UnityEngine.Vector3, ref UnityEngine.Vector3, ref UnityEngine.Vector3, ref UnityEngine.Vector3, out UnityEngine.Vector3) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

1 Examples 7

19 View Source File : BruteForceMesh.cs
License : MIT License
Project Creator : m969

Vector3 ClosestPointOnTriangle(int[] triangles, Vector3 to)
    {
        float shortestDistance = float.MaxValue;

        Vector3 shortestPoint = Vector3.zero;

        // Iterate through all triangles
        for (int i = 0; i < triangles.Length; i += 3)
        {
            int triangle = i;

            Vector3 p1 = vertices[tris[triangle]];
            Vector3 p2 = vertices[tris[triangle + 1]];
            Vector3 p3 = vertices[tris[triangle + 2]];

            Vector3 nearest;
                
            ClosestPointOnTriangleToPoint(ref p1, ref p2, ref p3, ref to, out nearest);

            float distance = (to - nearest).sqrMagnitude;

            if (distance <= shortestDistance)
            {
                shortestDistance = distance;
                shortestPoint = nearest;
            }
        }

        return shortestPoint;
    }