Exemplo n.º 1
0
            public virtual void OnSceneGUI()
            {
                //Draw Kinematic Chain
                IKBody body = SearchIKBody();

                if (body != null)
                {
                    DrawKinematicChain(new Chain(body.transform, Target.transform));
                }

                //Draw Objective
                if (Target.Objective != null)
                {
                    if (Target.Objective.Type == ObjectiveType.Position)
                    {
                        Handles.SphereCap(0, Target.transform.position, Quaternion.identity, Target.Objective.MaximumPositionError);
                    }
                    if (Target.Objective.Type == ObjectiveType.Orientation)
                    {
                        //Visualized by Unity's Transform
                    }
                    if (Target.Objective.Type == ObjectiveType.Pose)
                    {
                        Handles.SphereCap(0, Target.transform.position, Quaternion.identity, Target.Objective.MaximumPositionError);
                    }
                    if (Target.Objective.Type == ObjectiveType.LookAt)
                    {
                        Handles.ArrowCap(0, Target.transform.position, Target.transform.rotation * Quaternion.LookRotation(Target.Objective.Direction), 0.05f);
                    }
                }
            }
Exemplo n.º 2
0
 public Model(IKBody body)
 {
     Body = body;
     AddNode(Body.transform);
     BuildModel();
     UpdateState();
 }
Exemplo n.º 3
0
        void OnDestroy()
        {
            IKBody body = SearchIKBody();

            if (body != null)
            {
                body.Rebuild();
            }
        }
Exemplo n.º 4
0
        void OnDisable()
        {
            IKBody body = SearchIKBody();

            if (body != null)
            {
                body.Rebuild();
            }
        }
Exemplo n.º 5
0
        void Awake()
        {
            UpdateState();

            IKBody body = SearchIKBody();

            if (body != null)
            {
                body.Rebuild();
            }
        }
Exemplo n.º 6
0
            public override void OnInspectorGUI()
            {
                Undo.RecordObject(Target, Target.name);

                using (var scope = new EditorGUILayout.VerticalScope("Button")) {
                    EditorGUILayout.HelpBox("Settings", MessageType.None);

                    Target.Target         = (Transform)EditorGUILayout.ObjectField("Target", Target.Target, typeof(Transform), true);
                    Target.Objective.Type = (ObjectiveType)EditorGUILayout.EnumPopup("Objective", Target.Objective.Type);

                    using (var error = new EditorGUILayout.VerticalScope("Box")) {
                        EditorGUILayout.LabelField("Maximum Error");
                        if (Target.Objective.Type == ObjectiveType.Position)
                        {
                            Target.Objective.MaximumPositionError = EditorGUILayout.FloatField("Position", Target.Objective.MaximumPositionError);
                        }
                        if (Target.Objective.Type == ObjectiveType.Orientation)
                        {
                            Target.Objective.MaximumOrientationError = EditorGUILayout.FloatField("Orientation", Target.Objective.MaximumOrientationError);
                        }
                        if (Target.Objective.Type == ObjectiveType.Pose)
                        {
                            Target.Objective.MaximumPositionError    = EditorGUILayout.FloatField("Position", Target.Objective.MaximumPositionError);
                            Target.Objective.MaximumOrientationError = EditorGUILayout.FloatField("Orientation", Target.Objective.MaximumOrientationError);
                        }
                        if (Target.Objective.Type == ObjectiveType.LookAt)
                        {
                            Target.Objective.Direction             = EditorGUILayout.Vector3Field("Direction", Target.Objective.Direction);
                            Target.Objective.MaximumDirectionError = EditorGUILayout.FloatField("Error", Target.Objective.MaximumDirectionError);
                        }
                    }

                    using (var degreeoffreedom = new EditorGUILayout.VerticalScope("Button")) {
                        IKBody body = SearchIKBody();
                        if (body != null)
                        {
                            Chain chain = new Chain(body.transform, Target.transform);
                            EditorGUILayout.LabelField("Length: " + chain.Length);
                            EditorGUILayout.LabelField("Degree of Freedom: " + chain.DoF);
                        }
                        else
                        {
                            EditorGUILayout.HelpBox("Could not find a connected IK Body. Make sure to add a 'IKBody' component to your model from where the IK problem shall be solved.", MessageType.Warning);
                        }
                    }
                }

                EditorUtility.SetDirty(Target);
            }
Exemplo n.º 7
0
            private IKBody SearchIKBody()
            {
                Transform t = Target.transform;

                while (true)
                {
                    IKBody body = t.GetComponent <IKBody>();
                    if (body != null)
                    {
                        return(body);
                    }
                    else if (t != t.root)
                    {
                        t = t.parent;
                    }
                    else
                    {
                        return(null);
                    }
                }
            }
Exemplo n.º 8
0
 void Awake()
 {
     Target = (IKBody)target;
 }