Beispiel #1
0
    private void OnSceneGUI()
    {
        if (Application.isPlaying || !_morphAnimation.IsApprove)
        {
            return;
        }

        MorphHandles.DrawMorphBone(_transform, _boneSize);

        if (_morphAnimation.IsDone)
        {
            return;
        }

        ChangeHandleTool();
        EditBone();
        EditVertex();
    }
Beispiel #2
0
 /// <summary>
 /// 编辑顶点模式
 /// </summary>
 private void EditVertex()
 {
     if (_MAEditType == MAEditType.Vertex)
     {
         if (Event.current.button == 0 && Event.current.isMouse && Event.current.type == EventType.MouseDown)
         {
             RaycastHit hit;
             if (Physics.Raycast(HandleUtility.GUIPointToWorldRay(Event.current.mousePosition), out hit))
             {
                 if (hit.triangleIndex >= 0 && hit.triangleIndex < _morphAnimation.Triangles.Count)
                 {
                     _currentCheckedVertex = GetVertexByClick(_morphAnimation.Triangles[hit.triangleIndex], hit.point);
                 }
             }
             Selection.activeObject = _transform.gameObject;
         }
         if (_currentCheckedVertex != null)
         {
             SetHandlesColor(Color.cyan);
             MorphHandles.DrawMorphVertex(_currentCheckedVertex.Vertex, _vertexIconSize, _vertexHandleType);
             EditBoneWeight();
         }
     }
 }
Beispiel #3
0
    /// <summary>
    /// 编辑骨骼模式
    /// </summary>
    private void EditBone()
    {
        if (_MAEditType == MAEditType.Bone)
        {
            if (_currentCheckedBone != null)
            {
                SetHandlesColor(Color.white);
                switch (_MATool)
                {
                case MATool.Move:
                    Vector3 oldVec = _currentCheckedBone.position;
                    Vector3 newVec = Handles.PositionHandle(oldVec, Quaternion.identity);
                    if (oldVec != newVec)
                    {
                        Undo.RegisterFullObjectHierarchyUndo(_transform.gameObject, "Morph Move");
                        _currentCheckedBone.position = newVec;
                    }
                    break;

                case MATool.Rotate:
                    Quaternion oldRot = _currentCheckedBone.rotation;
                    Quaternion newRot = Handles.RotationHandle(oldRot, _currentCheckedBone.position);
                    if (oldRot != newRot)
                    {
                        Undo.RegisterFullObjectHierarchyUndo(_transform.gameObject, "Morph Rotate");
                        _currentCheckedBone.rotation = newRot;
                    }
                    break;

                case MATool.Scale:
                    Vector3 oldSca = _currentCheckedBone.localScale;
                    Vector3 newSca = Handles.ScaleHandle(oldSca, _currentCheckedBone.position, Quaternion.identity, 0.5f);
                    if (oldSca != newSca)
                    {
                        Undo.RegisterFullObjectHierarchyUndo(_transform.gameObject, "Morph Scale");
                        _currentCheckedBone.localScale = newSca;
                    }
                    break;
                }

                SetHandlesColor(Color.cyan);
                _currentCheckedMorphBone.InternalRange = Handles.RadiusHandle(Quaternion.identity, _currentCheckedBone.position, _currentCheckedMorphBone.InternalRange);

                for (int i = 0; i < _currentCheckedMorphBone.InternalRangeVertexs.Count; i++)
                {
                    MorphHandles.DrawMorphVertex(_currentCheckedMorphBone.InternalRangeVertexs[i].Vertex, _vertexIconSize, _vertexHandleType);
                }

                SetHandlesColor(Color.yellow);
                _currentCheckedMorphBone.ExternalRange = Handles.RadiusHandle(Quaternion.identity, _currentCheckedBone.position, _currentCheckedMorphBone.ExternalRange);

                for (int i = 0; i < _currentCheckedMorphBone.ExternalRangeVertexs.Count; i++)
                {
                    MorphHandles.DrawMorphVertex(_currentCheckedMorphBone.ExternalRangeVertexs[i].Vertex, _vertexIconSize, _vertexHandleType);
                }

                SetHandlesColor(Color.red);
                for (int i = 0; i < _currentCheckedMorphBone.ErrorVertexs.Count; i++)
                {
                    MorphHandles.DrawMorphVertex(_currentCheckedMorphBone.ErrorVertexs[i].Vertex, _vertexIconSize, _vertexHandleType);
                }
            }
        }
    }