Esempio n. 1
0
    static void MakeHead(Transform _headPoint, Transform _chestPoint, Vector3 _headTop)
    {
        float headScale = Vector3.Distance(_chestPoint.position, _headPoint.position) * .01f;


        Selection.activeObject = GameObject.Find("Spine_05");

        Puppet2D_BoneCreation.CreateBoneTool();
        Puppet2D_BoneCreation.BoneCreationMode(_headPoint.position);
        Puppet2D_BoneCreation.BoneCreationMode(_headTop);

        Puppet2D_BoneCreation.BoneFinishCreation();
        GameObject head = GameObject.Find("bone_1");

        head.name = "Head";
        Selection.activeGameObject = head;
        GameObject headEnd = GameObject.Find("bone_2");

        headEnd.name = "HeadEnd";

        Puppet2D_CreateControls.CreateOrientControl();
        GameObject headControl = GameObject.Find("Head_CTRL");

        headControl.GetComponent <Puppet2D_ParentControl>().ConstrianedPosition = true;
        GameObject headControlParent = GameObject.Find("Head_CTRL_GRP");

        headControlParent.transform.localScale = Vector3.one * headScale * 2f;
        //GameObject.Find ("bone_22").name = ("a");
    }
Esempio n. 2
0
    static void MakeClav(GameObject parentTo, string boneName)
    {
        Selection.activeObject = parentTo;
        Puppet2D_BoneCreation.CreateBoneTool();
        Puppet2D_BoneCreation.BoneCreationMode(parentTo.transform.position + Vector3.one * .1f);
        Puppet2D_BoneCreation.BoneFinishCreation();
        GameObject clav = GameObject.Find("bone_1");

        clav.name = boneName;
    }
Esempio n. 3
0
    static void MakeLimb(Transform _thighLPoint, Transform _footLPoint, Transform _kneePoint, Vector3 FootEnd, GameObject parentTo, string controlName, string controlName3, string controlName2, string controlName1, bool flip = false)
    {
        Selection.activeObject = parentTo;

        float   limbScale     = Vector3.Distance(_footLPoint.position, _thighLPoint.position) * .01f;
        Vector3 scaledFootPos = (_footLPoint.position - _thighLPoint.position) / limbScale;

        scaledFootPos += _thighLPoint.position;

        Vector3 scaledKneePos = (_kneePoint.position - _thighLPoint.position) / limbScale;

        scaledKneePos += _thighLPoint.position;

        Puppet2D_BoneCreation.CreateBoneTool();
        Puppet2D_BoneCreation.BoneCreationMode(_thighLPoint.position);

        Puppet2D_BoneCreation.BoneCreationMode(scaledKneePos);
        GameObject endLimbGO = Puppet2D_BoneCreation.BoneCreationMode(scaledFootPos);

        Vector3 scaledFinalEndLimbGO = (FootEnd - _thighLPoint.position) / limbScale;

        scaledFinalEndLimbGO += _thighLPoint.position;

        GameObject finalEndLimbGO = Puppet2D_BoneCreation.BoneCreationMode(scaledFinalEndLimbGO);

        finalEndLimbGO.name = (controlName1 + "End");

        Puppet2D_BoneCreation.BoneFinishCreation();

        Selection.activeGameObject = endLimbGO;
        endLimbGO.name             = controlName1;
        Puppet2D_CreateControls.IKCreateTool(true);
        GameObject limbControlParent = GameObject.Find(controlName1 + "_CTRL_GRP");

        Transform elbow        = endLimbGO.transform.parent;
        Transform shoulderBone = endLimbGO.transform.parent.parent;

        elbow.name        = (controlName2);
        shoulderBone.name = (controlName3);

        Transform limbParent = limbControlParent.transform.parent;

        limbControlParent.transform.parent = shoulderBone;
        shoulderBone.localScale            = shoulderBone.localScale * limbScale;
        limbControlParent.transform.parent = limbParent;
        GameObject.Find(controlName1 + "_CTRL").GetComponent <Puppet2D_IKHandle> ().Flip = flip;
    }
Esempio n. 4
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();
    }