コード例 #1
0
        void OnSceneGUI(SceneView sceneView)
        {
            Event e = Event.current;

            switch (e.type)
            {
            case EventType.KeyDown:
            {
                if (Event.current.keyCode == (KeyCode.Return))
                {
                    if (BoneCreation && Event.current.control != true)
                    {
                        Puppet3D.BoneCreation.BoneFinishCreation();
                    }
                    if (SplineCreation)
                    {
                        SplineEditor.SplineFinishCreation();
                    }

                    Repaint();
                }
                if (Event.current.keyCode == (KeyCode.KeypadPlus) && SkinWeightsPaint)
                {
                    EditSkinWeightRadius += 0.2f;
                }
                if (Event.current.keyCode == (KeyCode.KeypadMinus) && SkinWeightsPaint)
                {
                    EditSkinWeightRadius -= 0.2f;
                }
                if (BoneCreation && Event.current.control != true)
                {
                    if (Event.current.keyCode == (KeyCode.Backspace))
                    {
                        Puppet3D.BoneCreation.BoneDeleteMode();
                    }
                }
                if (SkinWeightsPaint)
                {
                    if (Event.current.keyCode == (KeyCode.N))
                    {
                        Ray worldRay = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition);

                        if (!ChangingRadius)
                        {
                            ChangeRadiusStartPosition = worldRay.GetPoint(0);
                            ChangeRadiusStartValue    = paintWeightsStrength;
                        }

                        Skinning.ChangePaintStrength(worldRay.GetPoint(0));
                        ChangingRadius = true;
                    }
                    if (Event.current.keyCode == (KeyCode.B))
                    {
                        Ray worldRay = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition);

                        if (!ChangingRadius)
                        {
                            ChangeRadiusStartPosition = worldRay.GetPoint(0);
                            ChangeRadiusStartValue    = EditSkinWeightRadius;
                        }

                        Skinning.ChangePaintRadius(worldRay.GetPoint(0));
                        ChangingRadius = true;
                    }
                }
                break;
            }

            case EventType.MouseMove:
            {
                if (Event.current.button == 0)
                {
                    if (BoneCreation && Event.current.control != true)
                    {
                        Ray worldRay = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition);


                        if (Event.current.shift == true)
                        {
                            Puppet3D.BoneCreation.BoneMoveIndividualMode(worldRay.GetPoint(0), worldRay);
                        }
                    }
                    if (SplineCreation && Event.current.control != true)
                    {
                        Ray worldRay = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition);

                        if ((Event.current.shift == true))
                        {
                            MoveControl(worldRay.GetPoint(0), worldRay);
                        }
                    }
                }
                break;
            }

            case EventType.MouseDown:
            {
                if (Event.current.button == 0)
                {
                    if (BoneCreation && Event.current.control != true)
                    {
                        Ray worldRay = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition);


                        Puppet3D.BoneCreation.BoneCreationMode(worldRay.GetPoint(0), worldRay);
                    }
                    else if (SplineCreation && Event.current.control != true)
                    {
                        Ray worldRay = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition);

                        SplineEditor.SplineCreationMode(worldRay.GetPoint(0), worldRay);
                    }
                    else if (SkinWeightsPaint)
                    {
                        Undo.RegisterCompleteObjectUndo(currentSelectionMesh, "Paint Weights");

                        GameObject c = HandleUtility.PickGameObject(Event.current.mousePosition, true);
                        if (c && c.GetComponent <Bone>())
                        {
                            Selection.activeGameObject = c;
                        }
                    }
                }

                else if (Event.current.button == 1)
                {
                    if (BoneCreation && Event.current.control != true)
                    {
                        Puppet3D.BoneCreation.BoneFinishCreation();
                        Selection.activeObject = null;
                        currentActiveBone      = null;
                        BoneCreation           = true;
                    }
                }
                break;
            }

            case EventType.KeyUp:
            {
                if (Event.current.keyCode == (KeyCode.B) || Event.current.keyCode == (KeyCode.N))
                {
                    if (SkinWeightsPaint)
                    {
                        ChangingRadius = false;
                    }
                }
                break;
            }

            case EventType.MouseDrag:
            {
                if (Event.current.button == 0)
                {
                    if (BoneCreation && Event.current.control != true)
                    {
                        Ray worldRay = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition);

                        Puppet3D.BoneCreation.BoneMoveMode(worldRay.GetPoint(0), worldRay);
                    }
                    if (SplineCreation && Event.current.control != true)
                    {
                        Ray worldRay = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition);

                        //if ((Event.current.shift == true))
                        {
                            MoveControl(worldRay.GetPoint(0), worldRay);
                        }
                    }
                }

                paintControlColor = new Color(.8f, 1f, .8f, .5f);



                if (SkinWeightsPaint && !(Event.current.alt))
                {
                    Ray worldRay = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition);
                    if (Event.current.control == true)
                    {
                        paintControlColor = new Color(1f, .8f, .8f, .5f);
                        if (Event.current.button == 0)
                        {
                            Skinning.PaintWeights(worldRay, -1);
                        }
                    }
                    else if (Event.current.shift == true /* Event.current.control == true*/)
                    {
                        paintControlColor = new Color(.8f, .8f, 1f, .5f);

                        if (Event.current.button == 0)
                        {
                            Skinning.PaintSmoothWeightsOld(worldRay);
                        }
                    }

                    else
                    {
                        paintControlColor = new Color(.8f, 1f, .8f, .5f);
                        if (Event.current.button == 0)
                        {
                            Skinning.PaintWeights(worldRay, 1);
                        }
                    }
                }


                break;
            }
            }
            if (SkinWeightsPaint)
            {
                // subscribe to the event


                if ((Event.current.type == EventType.ValidateCommand &&
                     Event.current.commandName == "UndoRedoPerformed"))
                {
                    RefreshMeshColors();
                }


                Ray worldRay = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition);
                if (ChangingRadius)
                {
                    Skinning.DrawHandle(worldRay);
                }
                else
                {
                    Skinning.DrawHandle(worldRay);
                }
                Repaint();
                SceneView.RepaintAll();
            }

            Handles.BeginGUI();

            if (SkinWeightsPaint)
            {
                Handles.color = Color.blue;
                Handles.Label(new Vector3(20, -40, 0),
                              "Select Bones to paint their Weights\n" +
                              "Left Click Adds Weights\n" +
                              "Left Click & Ctrl Removes Weights\n" +
                              "Left Click & Shift Smooths Weights\n" +
                              "Hold B to Change Brush Size\n" +
                              "Hold N to Change Strength");
            }
            Handles.EndGUI();
            if (BoneCreation || SplineCreation)
            {
                if (Event.current.control != true)
                {
                    int controlID2 = GUIUtility.GetControlID(FocusType.Passive);
                    HandleUtility.AddDefaultControl(GUIUtility.GetControlID(FocusType.Passive));
                    HandleUtility.AddDefaultControl(controlID2);
                }
            }
            if (SkinWeightsPaint)
            {
                int controlID2 = GUIUtility.GetControlID(FocusType.Passive);
                HandleUtility.AddDefaultControl(GUIUtility.GetControlID(FocusType.Passive));
                HandleUtility.AddDefaultControl(controlID2);
            }
        }