public override void UpdateData() { if (Segment.Character.Evolution == null) { return; } Valid = IsValid(); if (!Valid) { return; } if (X) { Motion = Segment.Joint.X; } if (Y) { Motion = Segment.Joint.Y; } if (Z) { Motion = Segment.Joint.Z; } Ptr = Segment.Character.Evolution.GetModel().FindMotionPtr(Motion); NormalisedTargetValue = Segment.Joint.JointType == JointType.Rotational ? NormalisedTargetValue = Utility.Deg2Rad * TargetValue : TargetValue; }
void LateUpdate() { PostcaptureAnimation(Root); UpdateData(Root); for (int i = 0; i < Solution.Length; i++) { Solution[i] = Evolution.GetModel().MotionPtrs[i].Motion.GetTargetValue(true); } Solution = Evolution.Optimise(Generations, Solution); for (int i = 0; i < Solution.Length; i++) { BioJoint.Motion motion = Evolution.GetModel().MotionPtrs[i].Motion; motion.SetTargetValue(Solution[i], true); /* * if(motion.Joint.GetJointType() == JointType.Revolute) { * motion.SetTargetValue((float)Solution[i]); * } else if(motion.Joint.GetJointType() == JointType.Continuous) { * motion.SetTargetValue(motion.GetTargetValue() + Mathf.Deg2Rad*Mathf.DeltaAngle(Mathf.Rad2Deg*motion.GetTargetValue(), Mathf.Rad2Deg*(float)Solution[i])); * } else if(motion.Joint.GetJointType() == JointType.Prismatic) { * motion.SetTargetValue((float)Solution[i]); * } else if(motion.Joint.GetJointType() == JointType.Floating) { * motion.SetTargetValue((float)Solution[i]); * } */ } ProcessMotion(Root); }
private void InspectMotion(BioJoint.Motion motion, string name) { SetGUIColor(Color8); using (new EditorGUILayout.VerticalScope("Box")) { SetGUIColor(Color5); GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); EditorGUILayout.HelpBox(name, MessageType.None); GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); if (motion.IsEnabled()) { SetGUIColor(Color1); motion.Constrained = EditorGUILayout.Toggle("Constrained", motion.Constrained); if (motion.Constrained) { SetGUIColor(Color1); motion.SetLowerLimit(EditorGUILayout.DoubleField("Lower Limit", motion.GetLowerLimit())); SetGUIColor(Color1); motion.SetUpperLimit(EditorGUILayout.DoubleField("Upper Limit", motion.GetUpperLimit())); SetGUIColor(Color1); motion.SetTargetValue(EditorGUILayout.Slider("Target Value", (float)motion.GetTargetValue(), (float)motion.GetLowerLimit(), (float)motion.GetUpperLimit())); } else { SetGUIColor(Color1); motion.SetTargetValue(EditorGUILayout.DoubleField("Target Value", motion.GetTargetValue())); } GUI.skin.button.alignment = TextAnchor.MiddleCenter; SetGUIColor(Color1); GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button("Disable", GUILayout.Width(250f), GUILayout.Height(20f))) { motion.SetEnabled(false); } GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); } else { GUI.skin.button.alignment = TextAnchor.MiddleCenter; SetGUIColor(Color1); GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button("Enable", GUILayout.Width(250f), GUILayout.Height(20f))) { motion.SetEnabled(true); } GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); } } }
//Returns the pointer to the motion public MotionPtr FindMotionPtr(BioJoint.Motion motion) { for (int i = 0; i < MotionPtrs.Length; i++) { if (MotionPtrs[i].Motion == motion) { return(MotionPtrs[i]); } } return(null); }
private void DrawMotion(BioJoint.Motion motion, Color color, bool final) { if (Target.SelectedSegment == motion.Joint.Segment && final) { DrawArrow(motion.Joint.GetAnchorInWorldSpace(), motion.Joint.Segment.Transform.rotation * Quaternion.LookRotation(motion.Axis), 0.125f, motion.IsEnabled() ? color : Color.grey); if (!motion.IsEnabled() || !motion.Constrained) { return; } if (motion.Joint.JointType == JointType.Rotational) { if (motion == motion.Joint.X) { DrawSolidArc( motion.Joint.GetAnchorInWorldSpace(), motion.Joint.Segment.Transform.rotation * motion.Axis, Quaternion.AngleAxis((float)motion.GetLowerLimit(), motion.Joint.Segment.Transform.rotation * motion.Axis) * motion.Joint.Segment.Transform.rotation * motion.Joint.Y.Axis, (float)motion.GetUpperLimit() - (float)motion.GetLowerLimit(), 0.125f, new Color(1f, 0f, 0f, 0.25f) ); } if (motion == motion.Joint.Y) { DrawSolidArc( motion.Joint.GetAnchorInWorldSpace(), motion.Joint.Segment.Transform.rotation * motion.Axis, Quaternion.AngleAxis((float)motion.GetLowerLimit(), motion.Joint.Segment.Transform.rotation * motion.Axis) * motion.Joint.Segment.Transform.rotation * motion.Joint.Z.Axis, (float)motion.GetUpperLimit() - (float)motion.GetLowerLimit(), 0.125f, new Color(0f, 1f, 0f, 0.25f) ); } if (motion == motion.Joint.Z) { DrawSolidArc( motion.Joint.GetAnchorInWorldSpace(), motion.Joint.Segment.Transform.rotation * motion.Axis, Quaternion.AngleAxis((float)motion.GetLowerLimit(), motion.Joint.Segment.Transform.rotation * motion.Axis) * motion.Joint.Segment.Transform.rotation * motion.Joint.X.Axis, (float)motion.GetUpperLimit() - (float)motion.GetLowerLimit(), 0.125f, new Color(0f, 0f, 1f, 0.25f) ); } } if (motion.Joint.JointType == JointType.Translational) { Vector3 A = motion.Joint.GetAnchorInWorldSpace() + (float)motion.GetLowerLimit() * (motion.Joint.Segment.Transform.rotation * motion.Axis); Vector3 B = motion.Joint.GetAnchorInWorldSpace() + (float)motion.GetUpperLimit() * (motion.Joint.Segment.Transform.rotation * motion.Axis); Color c = Color.white; if (motion == motion.Joint.X) { c = Color.red; } if (motion == motion.Joint.Y) { c = Color.green; } if (motion == motion.Joint.Z) { c = Color.blue; } DrawLine(A, B, 3f, c); DrawCube(A, motion.Joint.Segment.Transform.rotation, 0.0125f, new Color(c.r, c.g, c.b, 0.5f)); DrawCube(B, motion.Joint.Segment.Transform.rotation, 0.0125f, new Color(c.r, c.g, c.b, 0.5f)); } } else if (Target.SelectedSegment != motion.Joint.Segment) { DrawArrow(motion.Joint.GetAnchorInWorldSpace(), motion.Joint.Segment.Transform.rotation * Quaternion.LookRotation(motion.Axis), 0.05f, motion.IsEnabled() ? color : Color.clear); } }
public MotionPtr(BioJoint.Motion motion, Node node, int index) { Motion = motion; Node = node; Index = index; }