Esempio n. 1
0
        /*
         * Draws the scene view helpers for IKSolverFullBodyBiped
         * */
        public static void AddScene(IKSolverFullBodyBiped solver, Color color, bool modifiable, ref int selectedEffector, Transform root)
        {
            if (!solver.IsValid(false))
            {
                return;
            }

            float heightF = Vector3.Distance(solver.chain.children[0].nodes[0].transform.position, solver.chain.children[0].nodes[1].transform.position) +
                            Vector3.Distance(solver.chain.children[2].nodes[0].transform.position, solver.chain.children[2].nodes[1].transform.position);

            float size = Mathf.Clamp(heightF * 0.1f, 0.005f, 0.05f);

            // Chain
            if (!Application.isPlaying)
            {
                IKSolverFullBodyInspector.AddChain(solver.chain, color, size);
                Handles.DrawLine(solver.chain.children[0].nodes[0].transform.position, solver.chain.children[1].nodes[0].transform.position);
                Handles.DrawLine(solver.chain.children[2].nodes[0].transform.position, solver.chain.children[3].nodes[0].transform.position);

                AddLimbHelper(solver.chain.children[0], size);
                AddLimbHelper(solver.chain.children[1], size);
                AddLimbHelper(solver.chain.children[2], size, root);
                AddLimbHelper(solver.chain.children[3], size, root);
            }

            // Effectors
            IKSolverFullBodyInspector.AddScene(solver, color, modifiable, ref selectedEffector, size);
        }
        // Draws the custom inspector for IKSolverFullBodybiped
        public static void AddInspector(SerializedProperty prop, bool editHierarchy, bool editWeights)
        {
            IKSolverFullBodyInspector.AddInspector(prop, editHierarchy, editWeights);

            EditorGUILayout.Space();
            EditorGUI.indentLevel = 0;

            AddSolver(prop);
        }
        // Draws the scene view helpers for IKSolverFullBodyBiped
        public static void AddScene(UnityEngine.Object target, IKSolverFullBodyBiped solver, Color color, ref int selectedEffector, Transform root)
        {
            if (Application.isPlaying && !solver.initiated)
            {
                return;
            }
            if (!Application.isPlaying && !solver.IsValid())
            {
                return;
            }

            bool modifiable = solver.initiated;

            float heightF = Vector3.Distance(solver.chain[1].nodes[0].transform.position, solver.chain[1].nodes[1].transform.position) +
                            Vector3.Distance(solver.chain[3].nodes[0].transform.position, solver.chain[3].nodes[1].transform.position);

            float size = Mathf.Clamp(heightF * 0.075f, 0.001f, Mathf.Infinity);

            // Bend goals
            for (int i = 0; i < solver.chain.Length; i++)
            {
                if (solver.chain[i].nodes.Length == 3 && solver.chain[i].bendConstraint.bendGoal != null && solver.chain[i].bendConstraint.weight > 0f)
                {
                    Color c = color;
                    c.a           = solver.chain[i].bendConstraint.weight;
                    Handles.color = c;

                    Handles.DrawLine(solver.chain[i].nodes[1].transform.position, solver.chain[i].bendConstraint.bendGoal.position);
                    Handles.SphereHandleCap(0, solver.chain[i].nodes[1].transform.position, Quaternion.identity, size * 0.5f, EventType.Repaint);
                    Handles.SphereHandleCap(0, solver.chain[i].bendConstraint.bendGoal.position, Quaternion.identity, size * 0.5f, EventType.Repaint);

                    Handles.color = Color.white;
                }
            }

            // Chain
            if (!modifiable)
            {
                for (int i = 0; i < solver.chain.Length; i++)
                {
                    IKSolverFullBodyInspector.AddChain(solver.chain, i, color, size);
                }

                Handles.DrawLine(solver.chain[1].nodes[0].transform.position, solver.chain[2].nodes[0].transform.position);
                Handles.DrawLine(solver.chain[3].nodes[0].transform.position, solver.chain[4].nodes[0].transform.position);

                AddLimbHelper(solver.chain[1], size);
                AddLimbHelper(solver.chain[2], size);
                AddLimbHelper(solver.chain[3], size, root);
                AddLimbHelper(solver.chain[4], size, root);
            }

            // Effectors
            IKSolverFullBodyInspector.AddScene(target, solver, color, modifiable, ref selectedEffector, size);
        }
        /*
         * Returns all solver SeiralizedProperties
         * */
        public static SerializedContent[] FindContent(SerializedProperty prop)
        {
            SerializedContent[] c = IKSolverFullBodyInspector.FindContent(prop);
            Array.Resize(ref c, c.Length + 7);

            c[c.Length - 1] = new SerializedContent(prop.FindPropertyRelative("pullBodyVertical"), new GUIContent("Pull Body Vertical", "Weight of hand effectors pulling the body vertically."));
            c[c.Length - 2] = new SerializedContent(prop.FindPropertyRelative("limbMappings"), GUIContent.none);
            c[c.Length - 3] = new SerializedContent(prop.FindPropertyRelative("spineMapping"), GUIContent.none);
            c[c.Length - 4] = new SerializedContent(prop.FindPropertyRelative("boneMappings"), GUIContent.none);
            c[c.Length - 5] = new SerializedContent(prop.FindPropertyRelative("rootNode"), new GUIContent("Root Node", "Select one of the bones in the (lower) spine."));
            c[c.Length - 6] = new SerializedContent(prop.FindPropertyRelative("spineStiffness"), new GUIContent("Spine Stiffness", "The bend resistance of the spine."));
            c[c.Length - 7] = new SerializedContent(prop.FindPropertyRelative("pullBodyHorizontal"), new GUIContent("Pull Body Horizontal", "Weight of hand effectors pulling the body horizontally."));
            return(c);
        }
        /*
         * Draws the custom inspector for IKSolverFullBodybiped
         * */
        public static void AddInspector(SerializedProperty prop, bool editHierarchy, bool editWeights, SerializedContent[] content)
        {
            IKSolverFullBodyInspector.AddInspector(prop, editHierarchy, editWeights, content);

            // Spine Iteration
            AddClampedInt(content[content.Length - 3].prop.FindPropertyRelative("iterations"), new GUIContent("Spine Mapping Iterations", "Iterations of FABRIK solver mapping the spine to the FBIK nodes."), 1, 10);

            // Spine Stiffness
            AddClampedFloat(content[content.Length - 6]);

            // Pull Body
            AddClampedFloat(content[content.Length - 1], -1f, 1f);
            AddClampedFloat(content[content.Length - 7], -1f, 1f);

            // Chain
            EditorGUILayout.Space();
            EditorGUI.indentLevel = 0;

            EditorGUILayout.PropertyField(content[4].prop, new GUIContent("Chain", "The node chain."));
            if (content[4].prop.isExpanded)
            {
                AddPulls(content[4].prop);
                EditorGUILayout.Space();
            }

            // Effectors
            EditorGUI.indentLevel = 0;

            EditorGUILayout.PropertyField(content[2].prop, new GUIContent("Effectors", "Effectors for manipulating the node chain."));
            if (content[2].prop.isExpanded)
            {
                // Body
                AddEffector(content[2].prop.GetArrayElementAtIndex(0), new GUIContent("Body"), false);

                // Left Shoulder
                AddEffector(content[2].prop.GetArrayElementAtIndex(1), new GUIContent("L Shoulder"), false);

                // Right Shoulder
                AddEffector(content[2].prop.GetArrayElementAtIndex(2), new GUIContent("R Shoulder"), false);

                // Left Thigh
                AddEffector(content[2].prop.GetArrayElementAtIndex(3), new GUIContent("L Thigh"), false);

                // Right Thigh
                AddEffector(content[2].prop.GetArrayElementAtIndex(4), new GUIContent("R Thigh"), false);

                // Left Hand
                AddEffector(content[2].prop.GetArrayElementAtIndex(5), new GUIContent("L Hand"));

                // Right Hand
                AddEffector(content[2].prop.GetArrayElementAtIndex(6), new GUIContent("R Hand"));

                // Left Foot
                AddEffector(content[2].prop.GetArrayElementAtIndex(7), new GUIContent("L Foot"));

                // Right Foot
                AddEffector(content[2].prop.GetArrayElementAtIndex(8), new GUIContent("R Foot"));

                EditorGUILayout.Space();
            }

            EditorGUI.indentLevel = 0;

            // Mappings
            EditorGUILayout.PropertyField(content[content.Length - 3].prop, new GUIContent("Mapping", "Options for mapping bones to their solver positions."));
            if (content[content.Length - 3].prop.isExpanded)
            {
                AddSpineMapping(content[content.Length - 3].prop, new GUIContent("Spine"));

                AddMapping(content[content.Length - 2].prop.GetArrayElementAtIndex(0), new GUIContent("Left Hand"));
                AddMapping(content[content.Length - 2].prop.GetArrayElementAtIndex(1), new GUIContent("Right Hand"));
                AddMapping(content[content.Length - 2].prop.GetArrayElementAtIndex(2), new GUIContent("Left Foot"));
                AddMapping(content[content.Length - 2].prop.GetArrayElementAtIndex(3), new GUIContent("Right Foot"));

                AddMapping(content[content.Length - 4].prop.GetArrayElementAtIndex(0), new GUIContent("Head"));
            }
        }