Beispiel #1
0
        void VertexHandle()
        {
            PushHandlesMatrix();

            Handles.matrix = handlesTransformMatrix;
            HandleTransform t_pivot = activePivot;

            // Have to apply scale here instead of setting the Handles.matrix to object matrix because
            // handle gizmos are skewed when rendered in a matrix with non-identity scale.
            t_pivot.position = Vector3.Scale(t_pivot.position, selection.transform.lossyScale);

            switch (Tools.current)
            {
            case Tool.Move:
                t_pivot.position = Handles.PositionHandle(t_pivot.position, t_pivot.rotation);
                break;

            case Tool.Rotate:
                t_pivot.rotation = Handles.RotationHandle(t_pivot.rotation, t_pivot.position);
                break;

            case Tool.Scale:
                t_pivot.scale = Handles.ScaleHandle(t_pivot.scale,
                                                    t_pivot.position,
                                                    t_pivot.rotation,
                                                    HandleUtility.GetHandleSize(t_pivot.position));
                break;
            }

            t_pivot.position = DivideBy(t_pivot.position, selection.transform.lossyScale);

            if (t_pivot != activePivot)
            {
                if (!movingVertices)
                {
                    qeUtil.RecordMeshUndo(selection.mesh, "Move vertices");
                    OnBeginVertexMovement();
                }

                Matrix4x4 delta = (t_pivot - originPivot).GetMatrix();
                activePivot = t_pivot;

                Vector3[] v = selection.mesh.vertices;

                for (int i = 0; i < selection.allIndices.Count; i++)
                {
                    Vector3 inv = originPivotMatrix.inverse.MultiplyPoint3x4(vertexCache[selection.allIndices[i]]);
                    inv = delta.MultiplyPoint3x4(inv);
                    v[selection.allIndices[i]] = originPivotMatrix.MultiplyPoint3x4(inv);
                }

                selection.mesh.cloneMesh.vertices = v;

                UpdateGraphics();
            }

            PopHandlesMatrix();
        }
Beispiel #2
0
        /**
         * Returns the average position of the selected vertices in model space.
         */
        public HandleTransform GetHandleTransform()
        {
            Vector3 v   = Vector3.zero;
            int     len = _userIndices.Count;

            Vector3[] vertices = mesh.vertices;

            for (int i = 0; i < len; i++)
            {
                v += vertices[_userIndices[i]];
            }

            HandleTransform handle = new HandleTransform();

            if (len > 0)
            {
                handle.position = v / (float)len;
            }
            handle.rotation = Quaternion.identity;
            handle.scale    = Vector3.one;

            return(handle);
        }