private bool GetPlaneIntersection(Vector2 guiPosition, out Vector3 worldPlanePosition)
        {
#if ENABLE_DEBUG_GRID
            Grid.debugGrid = null;
#endif
            if (worldSlideGrid == null)
            {
                worldPlanePosition = worldSlideOrigin;
                return(false);
            }

            var originSnappedPlane = new Plane(worldSlidePlane.normal, worldSlideOrigin);

            var worldRay = UnityEditor.HandleUtility.GUIPointToWorldRay(guiPosition);
            var dist     = 0.0f;

            var camera  = Camera.current;
            var forward = camera.transform.forward;
            if (Mathf.Abs(Vector3.Dot(originSnappedPlane.normal, forward)) < 0.125f)
            {
                var normal = worldSlideGrid.GetClosestAxisVector(forward);
                var origin = originSnappedPlane.ClosestPointOnPlane(worldSlideOrigin);
                return(GetIntersectionOnAlternativePlane(worldRay, normal, origin, out worldPlanePosition));
            }

            if (!originSnappedPlane.Raycast(worldRay, out dist))
            {
                dist = float.PositiveInfinity;
            }

            float farClipPlaneDistance = camera.farClipPlane * 0.5f;
            if (dist > farClipPlaneDistance)
            {
                var normal = worldSlideGrid.GetClosestAxisVector(forward);
                var origin = originSnappedPlane.ClosestPointOnPlane(camera.transform.position) + (normal * farClipPlaneDistance);
                return(GetIntersectionOnAlternativePlane(worldRay, normal, origin, out worldPlanePosition));
            }
            else
            {
                if (!originSnappedPlane.SignedRaycast(worldRay, out dist))
                {
                    worldPlanePosition = worldSlideOrigin; return(false);
                }

                worldPlanePosition = worldRay.GetPoint(Mathf.Abs(dist));
#if ENABLE_DEBUG_GRID
                {
                    var tangent          = GeometryUtility.CalculateTangent(worldSlidePlane.normal);
                    var planeOrientation = Quaternion.LookRotation(tangent, worldSlidePlane.normal);
                    Grid.debugGrid = new Grid(Matrix4x4.TRS(worldPlanePosition, planeOrientation, Vector3.one));
                }
#endif

                return(true);
            }
        }
示例#2
0
        private bool GetPlaneIntersection(Vector2 guiPosition, out Vector3 worldPlanePosition)
        {
            if (worldSlideGrid == null)
            {
                worldPlanePosition = worldSlideOrigin;
                return(false);
            }

            var worldRay = UnityEditor.HandleUtility.GUIPointToWorldRay(guiPosition);
            var dist     = 0.0f;

            var camera  = Camera.current;
            var forward = camera.transform.forward;

            if (Mathf.Abs(Vector3.Dot(worldSlidePlane.normal, forward)) < 0.125f)
            {
                var normal = worldSlideGrid.GetClosestAxisVector(forward);
                var origin = worldSlidePlane.ClosestPointOnPlane(worldSlideOrigin);
                return(GetIntersectionOnAlternativePlane(worldRay, normal, origin, out worldPlanePosition));
            }

            if (!worldSlidePlane.Raycast(worldRay, out dist))
            {
                dist = float.PositiveInfinity;
            }
            if (dist > camera.farClipPlane)
            {
                var normal = worldSlideGrid.GetClosestAxisVector(forward);
                var origin = worldSlidePlane.ClosestPointOnPlane(camera.transform.position) + (normal * camera.farClipPlane);
                return(GetIntersectionOnAlternativePlane(worldRay, normal, origin, out worldPlanePosition));
            }
            else
            {
                if (!worldSlidePlane.SignedRaycast(worldRay, out dist))
                {
                    worldPlanePosition = worldSlideOrigin; return(false);
                }
                worldPlanePosition = worldRay.GetPoint(dist);
                return(true);
            }
        }