示例#1
0
    static void MakeSpine(Transform _hipPoint, Transform _chestPoint, Vector3 GroundPos)
    {
        //Spine
        float   hips2GroundScale = (_hipPoint.position.y - GroundPos.y);
        float   spineScale       = (.01f * hips2GroundScale) / 2.5f;
        Vector3 scaledChestPos   = (_chestPoint.position - _hipPoint.position) / spineScale;

        scaledChestPos += _hipPoint.position;
        Puppet2D_Spline.CreateSplineTool();
        Puppet2D_Spline.SplineCreationMode(_hipPoint.position);
        Puppet2D_Spline.SplineCreationMode(scaledChestPos);
        Puppet2D_Spline.SplineFinishCreation();
        Transform splineRoot       = GameObject.Find("spline_GRP_1").transform;
        Transform splineRootChild1 = GameObject.Find("spline_Ctrl_GRP_1").transform;
        Transform splineRootChild2 = GameObject.Find("spline_Ctrl_GRP_2").transform;

        splineRootChild1.parent = null;
        splineRootChild2.parent = null;
        splineRoot.position     = _hipPoint.position;
        splineRootChild1.parent = splineRoot;
        splineRootChild2.parent = splineRoot;
        splineRoot.localScale   = new Vector3(spineScale, spineScale, spineScale);
        Undo.RegisterCompleteObjectUndo(splineRoot, "spineScale");

        GameObject.Find("bone_1").name = "Spine_01";
        GameObject.Find("bone_2").name = "Spine_02";
        GameObject.Find("bone_3").name = "Spine_03";
        GameObject.Find("bone_4").name = "Spine_04";
        GameObject.Find("bone_5").name = "Spine_05";
    }
示例#2
0
    void OnSceneGUI(SceneView sceneView)
    {
        Event e = Event.current;

        switch (e.type)
        {
        case EventType.keyDown:
        {
            if (Event.current.keyCode == (KeyCode.Return))
            {
                if (BoneCreation)
                {
                    Puppet2D_BoneCreation.BoneFinishCreation();
                }
                if (SplineCreation)
                {
                    Puppet2D_Spline.SplineFinishCreation();
                }
                if (FFDCreation)
                {
                    FFDCreation = false;
                    Puppet2D_FFD.FFDFinishCreation();
                }
                Repaint();
            }
            if (Event.current.keyCode == (KeyCode.KeypadPlus) && SkinWeightsPaint)
            {
                EditSkinWeightRadius += 0.2f;
            }
            if (Event.current.keyCode == (KeyCode.KeypadMinus) && SkinWeightsPaint)
            {
                EditSkinWeightRadius -= 0.2f;
            }
            if (BoneCreation)
            {
                if (Event.current.keyCode == (KeyCode.Backspace))
                {
                    Puppet2D_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;
                    }

                    Puppet2D_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;
                    }

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

        case EventType.mouseMove:
        {
            if (Event.current.button == 0)
            {
                if (BoneCreation)
                {
                    Ray worldRay = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition);

                    if (Event.current.control == true)
                    {
                        Puppet2D_BoneCreation.BoneMoveMode(worldRay.GetPoint(0));
                    }
                    if (Event.current.shift == true)
                    {
                        Puppet2D_BoneCreation.BoneMoveIndividualMode(worldRay.GetPoint(0));
                    }
                }
                if (FFDCreation || SplineCreation)
                {
                    Ray worldRay = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition);

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

        case EventType.MouseDown:
        {
            if (Event.current.button == 0)
            {
                if (BoneCreation)
                {
                    Ray worldRay  = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition);
                    int controlID = GUIUtility.GetControlID(FocusType.Passive);
                    HandleUtility.AddDefaultControl(GUIUtility.GetControlID(FocusType.Passive));
                    GameObject c = HandleUtility.PickGameObject(Event.current.mousePosition, true);
                    if (c)
                    {
                        Selection.activeGameObject = c;
                    }
                    else
                    {
                        if (Event.current.alt)
                        {
                            Puppet2D_BoneCreation.BoneAddMode(worldRay.GetPoint(0));
                        }
                        else
                        {
                            Puppet2D_BoneCreation.BoneCreationMode(worldRay.GetPoint(0));
                        }
                    }
                    HandleUtility.AddDefaultControl(controlID);
                }
                else if (SplineCreation)
                {
                    Ray worldRay = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition);

                    Puppet2D_Spline.SplineCreationMode(worldRay.GetPoint(0));
                }
                else if (FFDCreation)
                {
                    Ray worldRay = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition);

                    Puppet2D_FFD.FFDCreationMode(worldRay.GetPoint(0));
                }
                else if (SkinWeightsPaint)
                {
                    GameObject c = HandleUtility.PickGameObject(Event.current.mousePosition, true);
                    if (c && c.GetComponent <SpriteRenderer>() && c.GetComponent <SpriteRenderer>().sprite&& c.GetComponent <SpriteRenderer>().sprite.name.Contains("Bone"))
                    {
                        Selection.activeGameObject = c;
                    }
                }
            }

            else if (Event.current.button == 1)
            {
                if (BoneCreation)
                {
                    Puppet2D_BoneCreation.BoneFinishCreation();
                    Selection.activeObject = null;
                    currentActiveBone      = null;
                    BoneCreation           = true;
                }
                else if (FFDCreation)
                {
                    Puppet2D_FFD.CloseFFDPath();
                }
            }
            break;
        }

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

        case EventType.mouseDrag:
        {
            paintControlColor = new Color(.8f, 1f, .8f, .5f);



            if (SkinWeightsPaint)
            {
                Ray worldRay = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition);
                if (Event.current.control == true)
                {
                    paintControlColor = new Color(1f, .8f, .8f, .5f);
                    if (Event.current.button == 0)
                    {
                        Puppet2D_Skinning.PaintWeights(worldRay.GetPoint(0), -1);
                    }
                }
                else if (Event.current.shift == true)
                {
                    paintControlColor = new Color(.8f, .8f, 1f, .5f);
                    if (Event.current.button == 0)
                    {
                        Puppet2D_Skinning.PaintSmoothWeights(worldRay.GetPoint(0));
                    }
                }
                else
                {
                    paintControlColor = new Color(.8f, 1f, .8f, .5f);
                    if (Event.current.button == 0)
                    {
                        Puppet2D_Skinning.PaintWeights(worldRay.GetPoint(0), 1);
                    }
                }
            }


            break;
        }
        }
        if (SkinWeightsPaint)
        {
            Ray worldRay = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition);
            if (ChangingRadius)
            {
                Puppet2D_Skinning.DrawHandle(ChangeRadiusStartPosition);
            }
            else
            {
                Puppet2D_Skinning.DrawHandle(worldRay.GetPoint(0));
            }
            Repaint();
            SceneView.RepaintAll();

            int controlID = GUIUtility.GetControlID(FocusType.Passive);
            HandleUtility.AddDefaultControl(GUIUtility.GetControlID(FocusType.Passive));



            HandleUtility.AddDefaultControl(controlID);
        }
        // Do your drawing here using Handles.

        GameObject[] selection = Selection.gameObjects;

        Handles.BeginGUI();
        if (BoneCreation)
        {
            if (selection.Length > 0)
            {
                Handles.color = Color.blue;
                Handles.Label(selection[0].transform.position + new Vector3(2, 2, 0),
                              "Left Click To Draw Bones\nPress Enter To Finish.\nBackspace To Delete A Bone\nHold Shift To Move Individual Bone\nHold Ctrl To Move Bone & Hierachy\nAlt Left Click To Add A Bone In Chain\nRight Click To Deselect");
            }
            else
            {
                Handles.color = Color.blue;
                Handles.Label(SceneView.lastActiveSceneView.camera.transform.position + Vector3.forward * 2,
                              "Bone Create Mode.\nLeft Click to Draw Bones.\nOr click on a bone to be a parent");
            }
        }
        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");
        }
        // Do your drawing here using GUI.
        Handles.EndGUI();
    }