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); } } }
public Model(IKBody body) { Body = body; AddNode(Body.transform); BuildModel(); UpdateState(); }
void OnDestroy() { IKBody body = SearchIKBody(); if (body != null) { body.Rebuild(); } }
void OnDisable() { IKBody body = SearchIKBody(); if (body != null) { body.Rebuild(); } }
void Awake() { UpdateState(); IKBody body = SearchIKBody(); if (body != null) { body.Rebuild(); } }
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); }
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); } } }
void Awake() { Target = (IKBody)target; }