Ejemplo n.º 1
0
        void SetupInputPlane(Vector2 mousePosition)
        {
            m_Plane = EditorHandleUtility.FindBestPlane(mousePosition);

            if (ProGridsInterface.SnapEnabled())
            {
                m_Plane.SetNormalAndPosition(
                    m_Plane.normal,
                    ProGridsInterface.ProGridsSnap(m_Plane.normal * -m_Plane.distance));
            }

            var planeNormal = m_Plane.normal;
            var planeCenter = m_Plane.normal * -m_Plane.distance;

            // if hit point on plane is cardinal axis and on grid, snap to grid.
            if (Math.IsCardinalAxis(planeNormal))
            {
                const float epsilon = .00001f;
                float       snapVal = Mathf.Abs(ProGridsInterface.SnapValue());
                float       rem     = Mathf.Abs(snapVal - (Vector3.Scale(planeNormal, planeCenter).magnitude % snapVal));
                polygon.isOnGrid = (rem < epsilon || Mathf.Abs(snapVal - rem) < epsilon);
            }
            else
            {
                polygon.isOnGrid = false;
            }
        }
Ejemplo n.º 2
0
        void SetupInputPlane(Vector2 mousePosition)
        {
            plane = EditorHandleUtility.FindBestPlane(mousePosition);

            var planeNormal = plane.normal;
            var planeCenter = plane.normal * -plane.distance;

            // if hit point on plane is cardinal axis and on grid, snap to grid.
            if (Math.IsCardinalAxis(planeNormal))
            {
                const float epsilon = .00001f;
                bool        offGrid = false;
                Vector3     snapVal = EditorSnapping.activeMoveSnapValue;
                Vector3     center  = Vector3.Scale(ProBuilderSnapping.GetSnappingMaskBasedOnNormalVector(planeNormal), planeCenter);
                for (int i = 0; i < 3; i++)
                {
                    offGrid |= Mathf.Abs(snapVal[i] % center[i]) > epsilon;
                }
                polygon.isOnGrid = !offGrid;
            }
            else
            {
                polygon.isOnGrid = false;
            }
        }