Example #1
0
        public static bool ClosestPointOnSurface(Collider col, Vector3 to, float radius, out Vector3 concatPoint)
        {
            bool isConcated = true;

            if (col is BoxCollider)
            {
                concatPoint = ClosestOnOBB((BoxCollider)col, to);
            }
            else if (col is SphereCollider)
            {
                concatPoint = col.ClosestPointOnBounds(to);
            }
            else if (col is MeshCollider)
            {
                BSPTree bsp = col.gameObject.GetComponent <BSPTree>();
                if (bsp != null)
                {
                    concatPoint = bsp.ClosestPointOn(to, radius);
                }
                else
                {
                    concatPoint = col.ClosestPointOnBounds(to);
                }
            }
            else
            {
                concatPoint = Vector3.zero;
                isConcated  = false;
            }

            return(isConcated);
        }
Example #2
0
    public static Vector3 ClosestPointOnSurface(Collider collider, Vector3 to, float radius)
    {
        if (collider is BoxCollider)
        {
            return(SuperCollider.ClosestPointOnSurface((BoxCollider)collider, to));
        }
        else if (collider is SphereCollider)
        {
            return(SuperCollider.ClosestPointOnSurface((SphereCollider)collider, to));
        }
        else if (collider is CapsuleCollider)
        {
            return(SuperCollider.ClosestPointOnSurface((CapsuleCollider)collider, to));
        }
        else if (collider is MeshCollider)
        {
            BSPTree bsp = collider.GetComponent <BSPTree>();

            if (bsp != null)
            {
                return(bsp.ClosestPointOn(to, radius));
            }

            BruteForceMesh bfm = collider.GetComponent <BruteForceMesh>();

            if (bfm != null)
            {
                return(bfm.ClosestPointOn(to));
            }
        }

        return(Vector3.zero);
    }
Example #3
0
    public static bool ClosestPointOnSurface(Collider collider, Vector3 to, float radius, out Vector3 closestPointOnSurface)
    {
        if (collider is BoxCollider)
        {
            closestPointOnSurface = SuperCollider.ClosestPointOnSurface((BoxCollider)collider, to);
            return(true);
        }
        else if (collider is SphereCollider)
        {
            closestPointOnSurface = SuperCollider.ClosestPointOnSurface((SphereCollider)collider, to);
            return(true);
        }
        else if (collider is CapsuleCollider)
        {
            closestPointOnSurface = SuperCollider.ClosestPointOnSurface((CapsuleCollider)collider, to);
            return(true);
        }
        else if (collider is MeshCollider)
        {
            BSPTree bspTree = collider.GetComponent <BSPTree>();

            if (bspTree != null)
            {
                closestPointOnSurface = bspTree.ClosestPointOn(to, radius);
                return(true);
            }

            BSPTree bsp = collider.GetComponent <BSPTree>();

            if (bsp != null)
            {
                closestPointOnSurface = bsp.ClosestPointOn(to, radius);
                return(true);
            }

            BruteForceMesh bfm = collider.GetComponent <BruteForceMesh>();

            if (bfm != null)
            {
                closestPointOnSurface = bfm.ClosestPointOn(to);
                return(true);
            }
        }
        else if (collider is TerrainCollider)
        {
            closestPointOnSurface = SuperCollider.ClosestPointOnSurface((TerrainCollider)collider, to, radius, false);
            return(true);
        }

        Debug.LogError(string.Format("{0} does not have an implementation for ClosestPointOnSurface; GameObject.Name='{1}'", collider.GetType(), collider.gameObject.name));
        closestPointOnSurface = Vector3.zero;
        return(false);
    }
Example #4
0
    public static Vector3 ClosestPointOnSurface(Collider collider, Vector3 to, float radius)
    {
        if (collider is BoxCollider)
        {
            return(SuperCollider.ClosestPointOnSurface((BoxCollider)collider, to));
        }
        else if (collider is SphereCollider)
        {
            return(SuperCollider.ClosestPointOnSurface((SphereCollider)collider, to));
        }
        else if (collider is CapsuleCollider)
        {
            return(SuperCollider.ClosestPointOnSurface((CapsuleCollider)collider, to));
        }
        else if (collider is MeshCollider)
        {
            RPGMesh rpgMesh = collider.GetComponent <RPGMesh>();

            if (rpgMesh != null)
            {
                return(rpgMesh.ClosestPointOn(to, radius, false, false));
            }

            BSPTree bsp = collider.GetComponent <BSPTree>();

            if (bsp != null)
            {
                return(bsp.ClosestPointOn(to, radius));
            }

            BruteForceMesh bfm = collider.GetComponent <BruteForceMesh>();

            if (bfm != null)
            {
                return(bfm.ClosestPointOn(to));
            }
        }
        else if (collider is TerrainCollider)
        {
            return(SuperCollider.ClosestPointOnSurface((TerrainCollider)collider, to, radius, false));
        }

        Debug.LogError(string.Format("{0} does not have an implementation for ClosestPointOnSurface", collider.GetType()));

        return(Vector3.zero);
    }