protected override void DerivedDraw(MotionEditor editor) { UltiDraw.Begin(); Color[] colors = UltiDraw.GetRainbowColors(Sensors.Length); if (ShowSensors) { for (int i = 0; i < Sensors.Length; i++) { for (int j = 0; j < Sensors[i].Bones.Length; j++) { Quaternion rot = editor.GetActor().FindTransform(Sensors[i].GetBoneName(j)).rotation; Vector3 pos = editor.GetActor().FindTransform(Sensors[i].GetBoneName(j)).position + rot * Sensors[i].Offset; UltiDraw.DrawCube(pos, rot, 0.025f, UltiDraw.Black); UltiDraw.DrawWireSphere(pos, rot, 2f * Sensors[i].Threshold, colors[i].Opacity(0.25f)); if (Sensors[i].GetContact(editor.GetCurrentFrame(), editor.Mirror) == 1f) { UltiDraw.DrawSphere(pos, rot, 2f * Sensors[i].Threshold, colors[i]); } else { UltiDraw.DrawSphere(pos, rot, 2f * Sensors[i].Threshold, colors[i].Opacity(0.125f)); } } } } UltiDraw.End(); }
public void Sketch(Matrix4x4[] transformations, Color color) { if (Bones.Length == 0) { return; } UltiDraw.Begin(); if (transformations.Length != Bones.Length) { for (int i = 0; i < transformations.Length; i++) { UltiDraw.DrawCube(transformations[i], 0.02f, color); } } else { Action <Bone> recursion = null; recursion = new Action <Bone>((bone) => { if (bone.GetParent() != null) { UltiDraw.DrawLine(transformations[bone.GetParent().Index].GetPosition(), transformations[bone.Index].GetPosition(), color); } UltiDraw.DrawCube(transformations[bone.Index], 0.02f, color); for (int i = 0; i < bone.Childs.Length; i++) { recursion(bone.GetChild(i)); } }); recursion(Bones[0]); } UltiDraw.End(); }
void Draw() { UltiDraw.Begin(); UltiDraw.SetCurvature(0f); UltiDraw.DrawQuad(new Vector3(0f, 1f, 3f), Quaternion.identity, 10f, 10f, UltiDraw.DarkGrey); UltiDraw.SetCurvature(0.25f); UltiDraw.SetFilling(1f); UltiDraw.DrawCube(new Vector3(-2f, 1f, 2f), Quaternion.identity, 1f, UltiDraw.Cyan); UltiDraw.SetFilling(0f); UltiDraw.DrawCube(new Vector3(0f, 1f, 2f), Quaternion.identity, 1f, UltiDraw.Cyan); UltiDraw.SetFilling(1f); UltiDraw.DrawSphere(new Vector3(-2f, 1f, 0f), Quaternion.identity, 1f, UltiDraw.Cyan); UltiDraw.SetFilling(0f); UltiDraw.DrawSphere(new Vector3(0f, 1f, 0f), Quaternion.identity, 1f, UltiDraw.Cyan); UltiDraw.End(); Gizmos.color = UltiDraw.Cyan; Gizmos.DrawCube(new Vector3(2f, 1f, 2f), Vector3.one); Gizmos.DrawSphere(new Vector3(2f, 1f, 0f), 0.5f); }
public void Sketch(Matrix4x4[] transformations, Color color) { UltiDraw.Begin(); if (transformations.Length != Bones.Length) { Debug.Log("Number of given transformations does not match number of bones."); } else { Action <Bone> recursion = null; recursion = new Action <Bone>((bone) => { Matrix4x4 current = transformations[bone.Index]; if (bone.GetParent() != null) { Matrix4x4 parent = transformations[bone.GetParent().Index]; UltiDraw.DrawLine(parent.GetPosition(), current.GetPosition(), color); } UltiDraw.DrawCube(current.GetPosition(), current.GetRotation(), 0.02f, color); for (int i = 0; i < bone.Childs.Length; i++) { recursion(bone.GetChild(i)); } }); foreach (Bone bone in GetRootBones()) { recursion(bone); } } UltiDraw.End(); }
public void Draw(int step = 1) { UltiDraw.Begin(); Color[] colors = UltiDraw.GetRainbowColors(Styles.Length); //Connections,黑线连接评估点,这些点以step=10为间隔就画一个,总共12个,历史6个,当前1个,预测5个 for (int i = 0; i < Points.Length - step; i += step) { UltiDraw.DrawLine(Points[i].GetPosition(), Points[i + step].GetPosition(), 0.01f, UltiDraw.Black); } //Velocities for (int i = 0; i < Points.Length; i += step) { //Vector3 start = Points[i].GetPosition(); //Vector3 end = Points[i].GetPosition() + Points[i].GetVelocity(); //end = Utility.ProjectGround(end, LayerMask.GetMask("Ground")); //UltiDraw.DrawLine(start, end, 0.025f, 0f, UltiDraw.DarkGreen.Transparent(0.5f)); /* * float r = 0f; * float g = 0f; * float b = 0f; * for(int j=0; j<Points[i].Styles.Length; j++) { * r += Points[i].Styles[j] * colors[j].r; * g += Points[i].Styles[j] * colors[j].g; * b += Points[i].Styles[j] * colors[j].b; * } * UltiDraw.DrawLine(Points[i].GetPosition(), Points[i].GetPosition() + Points[i].GetVelocity(), 0.025f, 0f, new Color(r, g, b, 0.5f)); */ //UltiDraw.DrawLine(Points[i].GetPosition(), Points[i].GetPosition() + Points[i].GetVelocity(), 0.025f, 0f, UltiDraw.DarkGreen.Transparent(0.5f)); } //Directions,黄色线画个间隔点的方向 for (int i = 0; i < Points.Length; i += step) { //Vector3 start = Points[i].GetPosition(); //Vector3 end = Points[i].GetPosition() + 0.25f * Points[i].GetDirection(); //end = Utility.ProjectGround(end, LayerMask.GetMask("Ground")); //UltiDraw.DrawLine(start, end, 0.025f, 0f, UltiDraw.Orange.Transparent(0.75f)); UltiDraw.DrawLine(Points[i].GetPosition(), Points[i].GetPosition() + 0.25f * Points[i].GetDirection(), 0.025f, 0f, UltiDraw.Orange.Transparent(0.75f)); } //Styles,方块的颜色是什么信息呢? if (Styles.Length > 0) { for (int i = 0; i < Points.Length; i += step) { float r = 0f; float g = 0f; float b = 0f; for (int j = 0; j < Points[i].Styles.Length; j++) { r += Points[i].Styles[j] * colors[j].r; g += Points[i].Styles[j] * colors[j].g; b += Points[i].Styles[j] * colors[j].b; } Color color = new Color(r, g, b, 1f); UltiDraw.DrawCube(Points[i].GetPosition(), Points[i].GetRotation(), 0.05f, color); } } //Signals /* * if(Styles.Length > 0) { * for(int i=0; i<Points.Length; i+=step) { * Color color = UltiDraw.Black; * for(int j=0; j<Points[i].Signals.Length; j++) { * if(Points[i].Signals[j]) { * color = colors[j]; * break; * } * } * UltiDraw.DrawCone(Points[i].GetPosition(), Quaternion.identity, 0.1f, 0.1f, color); * } * } */ /* * //Speed * for(int i=0; i<Points.Length; i+=step) { * float r = 0f; * float g = 0f; * float b = 0f; * for(int j=0; j<Points[i].Styles.Length; j++) { * r += Points[i].Styles[j] * colors[j].r; * g += Points[i].Styles[j] * colors[j].g; * b += Points[i].Styles[j] * colors[j].b; * } * UltiDraw.DrawArrow(Points[i].GetPosition(), Points[i].GetPosition() + Points[i].GetSpeed() * Points[i].GetTransformation().GetForward(), 0.8f, 0.02f, 0.04f, new Color(r, g, b, 0.5f)); * } */ //Projections //for(int i=0; i<Points.Length; i+=step) { // Vector3 right = Points[i].GetRightSample(); // Vector3 left = Points[i].GetLeftSample(); // UltiDraw.DrawCircle(right, 0.01f, UltiDraw.Yellow); // UltiDraw.DrawCircle(left, 0.01f, UltiDraw.Yellow); //} //Slopes //for(int i=0; i<Points.Length; i+=step) { // UltiDraw.DrawLine(Points[i].GetPosition(), Points[i].GetPosition() + 1f * Points[i].GetSlope() * Vector3.up, 0.025f, 0f, UltiDraw.Blue.Transparent(0.75f)); //} //Positions,间隔点再画上黑圈 for (int i = 0; i < Points.Length; i += step) { UltiDraw.DrawCircle(Points[i].GetPosition(), 0.025f, UltiDraw.Black); } //Phase,周期信息是怎么画的呢,为什么demo上看不到? for (int i = 0; i < Points.Length; i += step) { //UltiDraw.DrawLine(Points[i].GetPosition(), Points[i].GetPosition() + Points[i].Phase*Vector3.up, UltiDraw.IndianRed); UltiDraw.DrawArrow(Points[i].GetPosition(), Points[i].GetPosition() + Points[i].Phase * Vector3.up, 0.8f, 0.025f, 0.05f, UltiDraw.IndianRed.Transparent(0.5f)); //UltiDraw.DrawSphere(Points[i].GetPosition(), Quaternion.identity, Points[i].PhaseUpdate / 10f, UltiDraw.Purple.Transparent(0.25f)); } /* * List<float[]> signal = new List<float[]>(); * for(int i=0; i<Styles.Length; i++) { * float[] s = new float[Points.Length]; * for(int j=0; j<Points.Length; j++) { * s[j] = Points[j].Signals[i]; * } * signal.Add(s); * } * List<float[]> signalInput = new List<float[]>(); * for(int i=0; i<Styles.Length; i++) { * float[] s = new float[Points.Length]; * for(int j=0; j<Points.Length; j++) { * s[j] = Points[j].Signals[i] - Points[j].Styles[i]; * } * signalInput.Add(s); * } * List<float[]> stateInput = new List<float[]>(); * for(int i=0; i<Styles.Length; i++) { * float[] s = new float[Points.Length]; * for(int j=0; j<Points.Length; j++) { * s[j] = Points[j].Styles[i]; * } * stateInput.Add(s); * } * UltiDraw.DrawGUIFunctions(new Vector2(0.5f, 0.4f), new Vector2(0.75f, 0.1f), signal, 0f, 1f, UltiDraw.DarkGrey, colors); * UltiDraw.DrawGUIFunctions(new Vector2(0.5f, 0.25f), new Vector2(0.75f, 0.1f), stateInput, 0f, 1f, UltiDraw.DarkGrey, colors); * UltiDraw.DrawGUIFunctions(new Vector2(0.5f, 0.1f), new Vector2(0.75f, 0.1f), signalInput, -1f, 1f, UltiDraw.DarkGrey, colors); */ UltiDraw.End(); }
void Draw() { float speed = 100f; float spacing = 1.5f; float height = 1f; int index = 0; Color[] colors = UltiDraw.GetRainbowColors(9); UltiDraw.Begin(); UltiDraw.SetDepthRendering(DepthRendering); UltiDraw.SetCurvature(0f); UltiDraw.DrawQuad(Vector3.zero, Quaternion.Euler(90f, 0f, 0f), 100f, 100f, UltiDraw.DarkGrey); UltiDraw.SetCurvature(0.25f); UltiDraw.DrawGrid(Vector3.zero, Quaternion.identity, 100, 100, 1f, 1f, UltiDraw.DarkGreen.Transparent(0.5f)); UltiDraw.DrawWireCube(new Vector3(index * spacing, height, 0f * spacing), Quaternion.Euler(0f, speed * Time.time, 0f), 1f, colors[index]); UltiDraw.DrawCube(new Vector3(index * spacing, height, 1f * spacing), Quaternion.Euler(0f, speed * Time.time, 0f), 1f, colors[index]); UltiDraw.DrawWiredCube(new Vector3(index * spacing, height, 2f * spacing), Quaternion.Euler(0f, speed * Time.time, 0f), 1f, colors[index], UltiDraw.White); index += 1; UltiDraw.DrawWireSphere(new Vector3(index * spacing, height, 0f * spacing), Quaternion.Euler(0f, speed * Time.time, 0f), 1f, colors[index]); UltiDraw.DrawSphere(new Vector3(index * spacing, height, 1f * spacing), Quaternion.Euler(0f, speed * Time.time, 0f), 1f, colors[index]); UltiDraw.DrawWiredSphere(new Vector3(index * spacing, height, 2f * spacing), Quaternion.Euler(0f, speed * Time.time, 0f), 1f, colors[index], UltiDraw.White); index += 1; UltiDraw.DrawWireCapsule(new Vector3(index * spacing, height, 0f * spacing), Quaternion.Euler(0f, speed * Time.time, 0f), 0.5f, 1f, colors[index]); UltiDraw.DrawCapsule(new Vector3(index * spacing, height, 1f * spacing), Quaternion.Euler(0f, speed * Time.time, 0f), 0.5f, 1f, colors[index]); UltiDraw.DrawWiredCapsule(new Vector3(index * spacing, height, 2f * spacing), Quaternion.Euler(0f, speed * Time.time, 0f), 0.5f, 1f, colors[index], UltiDraw.White); index += 1; UltiDraw.DrawWireBone(new Vector3(index * spacing, height - 0.5f, 0f * spacing), Quaternion.Euler(-90f, speed * Time.time, 0f), 1f, 1f, colors[index]); UltiDraw.DrawBone(new Vector3(index * spacing, height - 0.5f, 1f * spacing), Quaternion.Euler(-90f, speed * Time.time, 0f), 1f, 1f, colors[index]); UltiDraw.DrawWiredBone(new Vector3(index * spacing, height - 0.5f, 2f * spacing), Quaternion.Euler(-90f, speed * Time.time, 0f), 1f, 1f, colors[index], UltiDraw.White); index += 1; UltiDraw.DrawWireCylinder(new Vector3(index * spacing, height, 0f * spacing), Quaternion.Euler(0f, speed * Time.time, 0f), 0.5f, 1f, colors[index]); UltiDraw.DrawCylinder(new Vector3(index * spacing, height, 1f * spacing), Quaternion.Euler(0f, speed * Time.time, 0f), 0.5f, 1f, colors[index]); UltiDraw.DrawWiredCylinder(new Vector3(index * spacing, height, 2f * spacing), Quaternion.Euler(0f, speed * Time.time, 0f), 0.5f, 1f, colors[index], UltiDraw.White); index += 1; UltiDraw.DrawWirePyramid(new Vector3(index * spacing, height - 0.5f, 0f * spacing), Quaternion.Euler(0f, speed * Time.time, 0f), 1f, 1f, colors[index]); UltiDraw.DrawPyramid(new Vector3(index * spacing, height - 0.5f, 1f * spacing), Quaternion.Euler(0f, speed * Time.time, 0f), 1f, 1f, colors[index]); UltiDraw.DrawWiredPyramid(new Vector3(index * spacing, height - 0.5f, 2f * spacing), Quaternion.Euler(0f, speed * Time.time, 0f), 1f, 1f, colors[index], UltiDraw.White); index += 1; UltiDraw.DrawWireCone(new Vector3(index * spacing, height - 0.5f, 0f * spacing), Quaternion.Euler(0f, speed * Time.time, 0f), 0.75f, 1f, colors[index]); UltiDraw.DrawCone(new Vector3(index * spacing, height - 0.5f, 1f * spacing), Quaternion.Euler(0f, speed * Time.time, 0f), 0.75f, 1f, colors[index]); UltiDraw.DrawWiredCone(new Vector3(index * spacing, height - 0.5f, 2f * spacing), Quaternion.Euler(0f, speed * Time.time, 0f), 0.75f, 1f, colors[index], UltiDraw.White); index += 1; UltiDraw.DrawWireCuboid(new Vector3(index * spacing, height, 0f * spacing), Quaternion.Euler(0f, speed * Time.time, 0f), new Vector3(0.5f, 1f, 0.5f), colors[index]); UltiDraw.DrawCuboid(new Vector3(index * spacing, height, 1f * spacing), Quaternion.Euler(0f, speed * Time.time, 0f), new Vector3(0.5f, 1f, 0.5f), colors[index]); UltiDraw.DrawWiredCuboid(new Vector3(index * spacing, height, 2f * spacing), Quaternion.Euler(0f, speed * Time.time, 0f), new Vector3(0.5f, 1f, 0.5f), colors[index], UltiDraw.White); index += 1; UltiDraw.DrawWireEllipsoid(new Vector3(index * spacing, height, 0f * spacing), Quaternion.Euler(0f, speed * Time.time, 0f), 0.5f, 1f, colors[index]); UltiDraw.DrawEllipsoid(new Vector3(index * spacing, height, 1f * spacing), Quaternion.Euler(0f, speed * Time.time, 0f), 0.5f, 1f, colors[index]); UltiDraw.DrawWiredEllipsoid(new Vector3(index * spacing, height, 2f * spacing), Quaternion.Euler(0f, speed * Time.time, 0f), 0.5f, 1f, colors[index], UltiDraw.White); index += 1; UltiDraw.End(); }
public void Draw(int step = 1) { UltiDraw.Begin(); Color[] colors = UltiDraw.GetRainbowColors(Styles); //Connections for (int i = 0; i < Points.Length - step; i += step) { UltiDraw.DrawLine(Points[i].GetPosition(), Points[i + step].GetPosition(), 0.01f, UltiDraw.Black); } //Velocities for (int i = 0; i < Points.Length; i += step) { //Vector3 start = Points[i].GetPosition(); //Vector3 end = Points[i].GetPosition() + Points[i].GetVelocity(); //end = Utility.ProjectGround(end, LayerMask.GetMask("Ground")); //UltiDraw.DrawLine(start, end, 0.025f, 0f, UltiDraw.DarkGreen.Transparent(0.5f)); /* * float r = 0f; * float g = 0f; * float b = 0f; * for(int j=0; j<Points[i].Styles.Length; j++) { * r += Points[i].Styles[j] * colors[j].r; * g += Points[i].Styles[j] * colors[j].g; * b += Points[i].Styles[j] * colors[j].b; * } * UltiDraw.DrawLine(Points[i].GetPosition(), Points[i].GetPosition() + Points[i].GetVelocity(), 0.025f, 0f, new Color(r, g, b, 0.5f)); */ //UltiDraw.DrawLine(Points[i].GetPosition(), Points[i].GetPosition() + Points[i].GetVelocity(), 0.025f, 0f, UltiDraw.DarkGreen.Transparent(0.5f)); } //Directions for (int i = 0; i < Points.Length; i += step) { //Vector3 start = Points[i].GetPosition(); //Vector3 end = Points[i].GetPosition() + 0.25f * Points[i].GetDirection(); //end = Utility.ProjectGround(end, LayerMask.GetMask("Ground")); //UltiDraw.DrawLine(start, end, 0.025f, 0f, UltiDraw.Orange.Transparent(0.75f)); UltiDraw.DrawLine(Points[i].GetPosition(), Points[i].GetPosition() + 0.25f * Points[i].GetDirection(), 0.025f, 0f, UltiDraw.Orange.Transparent(0.75f)); } //Styles if (Styles > 0) { for (int i = 0; i < Points.Length; i += step) { float r = 0f; float g = 0f; float b = 0f; for (int j = 0; j < Points[i].Styles.Length; j++) { r += Points[i].Styles[j] * colors[j].r; g += Points[i].Styles[j] * colors[j].g; b += Points[i].Styles[j] * colors[j].b; } UltiDraw.DrawCube(Points[i].GetPosition(), Points[i].GetRotation(), 0.05f, new Color(r, g, b, 1f)); } } /* * //Speed * for(int i=0; i<Points.Length; i+=step) { * float r = 0f; * float g = 0f; * float b = 0f; * for(int j=0; j<Points[i].Styles.Length; j++) { * r += Points[i].Styles[j] * colors[j].r; * g += Points[i].Styles[j] * colors[j].g; * b += Points[i].Styles[j] * colors[j].b; * } * UltiDraw.DrawArrow(Points[i].GetPosition(), Points[i].GetPosition() + Points[i].GetSpeed() * Points[i].GetTransformation().GetForward(), 0.8f, 0.02f, 0.04f, new Color(r, g, b, 0.5f)); * } */ //Projections //for(int i=0; i<Points.Length; i+=step) { // Vector3 right = Points[i].GetRightSample(); // Vector3 left = Points[i].GetLeftSample(); // UltiDraw.DrawCircle(right, 0.01f, UltiDraw.Yellow); // UltiDraw.DrawCircle(left, 0.01f, UltiDraw.Yellow); //} //Slopes //for(int i=0; i<Points.Length; i+=step) { // UltiDraw.DrawLine(Points[i].GetPosition(), Points[i].GetPosition() + 1f * Points[i].GetSlope() * Vector3.up, 0.025f, 0f, UltiDraw.Blue.Transparent(0.75f)); //} //Positions for (int i = 0; i < Points.Length; i += step) { UltiDraw.DrawCircle(Points[i].GetPosition(), 0.025f, UltiDraw.Black); } //Phase for (int i = 0; i < Points.Length; i += step) { UltiDraw.DrawLine(Points[i].GetPosition(), Points[i].GetPosition() + Points[i].Phase * Vector3.up, UltiDraw.IndianRed); } UltiDraw.End(); }
void OnRenderObject() { if (Application.isPlaying) { if (NN.Parameters == null) { return; } if (AnimationAuthoring == null) { return; } if (AnimationAuthoring.ControlPoints.Count <= 0) { return; } if (ShowAuthoring) { UltiDraw.SetDepthRendering(true); AnimationAuthoring.StyleColors = new Color[] { AnimationAuthoring.Idle, AnimationAuthoring.Move, AnimationAuthoring.Jump, AnimationAuthoring.Sit, AnimationAuthoring.Stand, AnimationAuthoring.Lie, AnimationAuthoring.Sneak, AnimationAuthoring.Eat, AnimationAuthoring.Hydrate }; if (MotionTime <= 0.0f) { MotionTime = AnimationAuthoring.GetControlPoint(AnimationAuthoring.RefTimestamp, 0).GetMotionTime(); } if (MotionTime > 0.0f) { GUIStyle style = new GUIStyle(); style.normal.textColor = UltiDraw.Red; style.fontSize = 20; Vector3 pos = AnimationAuthoring.GetLookUpPoint(AnimationAuthoring.RefTimestamp).GetPosition(); #if UNITY_EDITOR Handles.Label(new Vector3(pos.x, pos.y + 1f, pos.z), string.Format("{0:0.0}s", MotionTime), style); #endif } int countCpInspector = 0; foreach (ControlPoint cp in AnimationAuthoring.ControlPoints) { if (cp.Inspector) { countCpInspector++; } else { continue; } //AnimationAuthoring.LabelCP(cp, (countCpInspector - 1).ToString()); UltiDraw.Begin(); UltiDraw.DrawSphere(AnimationAuthoring.GetGroundPosition(cp.GetPosition(), cp.Ground), Quaternion.identity, 0.1f, UltiDraw.Red); UltiDraw.End(); } Color[] colors = AnimationAuthoring.StyleColors; for (int i = 0; i < AnimationAuthoring.LookUpPoints.Length; i++) { //draw every 4th point if ((i % (4 * AnimationAuthoring.TimeInterval) != 0) || !AnimationAuthoring.GetControlPoint(i * AnimationAuthoring.TimeDelta, +1).Inspector) { continue; } float r = 0f; float g = 0f; float b = 0f; for (int j = 0; j < AnimationAuthoring.LookUpPoints[i].GetStyle().Length; j++) { r += AnimationAuthoring.LookUpPoints[i].GetStyle()[j] * colors[j].r; g += AnimationAuthoring.LookUpPoints[i].GetStyle()[j] * colors[j].g; b += AnimationAuthoring.LookUpPoints[i].GetStyle()[j] * colors[j].b; } Color color = new Color(r, g, b, 1f); UltiDraw.Begin(); UltiDraw.DrawCube(AnimationAuthoring.GetPointPositon(i * AnimationAuthoring.TimeDelta), Quaternion.identity, 0.05f, color); UltiDraw.End(); } } if (ShowTrajectory) { UltiDraw.SetDepthRendering(false); UltiDraw.Begin(); UltiDraw.DrawLine(Trajectory.Points[RootPointIndex].GetPosition(), Trajectory.Points[RootPointIndex].GetPosition() + TargetDirection, 0.05f, 0f, UltiDraw.Red.Transparent(0.75f)); UltiDraw.DrawLine(Trajectory.Points[RootPointIndex].GetPosition(), Trajectory.Points[RootPointIndex].GetPosition() + TargetVelocity, 0.05f, 0f, UltiDraw.Green.Transparent(0.75f)); UltiDraw.End(); Trajectory.Draw(10); } if (ShowVelocities) { UltiDraw.SetDepthRendering(false); UltiDraw.Begin(); for (int i = 0; i < Actor.Bones.Length; i++) { UltiDraw.DrawArrow( Actor.Bones[i].Transform.position, Actor.Bones[i].Transform.position + Velocities[i], 0.75f, 0.0075f, 0.05f, UltiDraw.Purple.Transparent(0.5f) ); } UltiDraw.End(); } float[] a = new float[100]; for (int i = 0; i < a.Length; i++) { float x = (float)i / (float)(a.Length - 1); a[i] = SmoothStep(x, 2f, .8f); } UltiDraw.Begin(); //UltiDraw.DrawGUIFunction(new Vector2(0.5f, 0.5f), new Vector2(1f, 1f), a, 0f, 1f, Color.white, Color.black); UltiDraw.End(); if (DrawLatentSpaces) { UltiDraw.SetDepthRendering(false); UltiDraw.Begin(); float YMin = 0f; float YMax = 0f; Tensor t0 = NN.GetTensor("W0"); Tensor t1 = NN.GetTensor("W1"); Tensor t2 = NN.GetTensor("W2"); float[] arr0 = new float[t0.GetCols()]; float[] arr1 = new float[t1.GetCols()]; float[] arr2 = new float[t2.GetCols()]; for (int i = 0; i < t0.GetCols(); i++) { float x = (float)i / (float)(arr0.Length - 1); //arr[i] = SmoothStep(x, 2f, .8f); float colMean = 0f; for (int j = 0; j < t0.GetRows(); j++) { colMean += t0.GetValue(j, i); } arr0[i] = colMean; } for (int i = 0; i < t1.GetCols(); i++) { float x = (float)i / (float)(arr1.Length - 1); //arr[i] = SmoothStep(x, 2f, .8f); float colMean = 0f; for (int j = 0; j < t1.GetRows(); j++) { colMean += t1.GetValue(j, i); } arr1[i] = colMean; } for (int i = 0; i < t2.GetCols(); i++) { float x = (float)i / (float)(arr2.Length - 1); //arr[i] = SmoothStep(x, 2f, .8f); float colMean = 0f; for (int j = 0; j < t2.GetRows(); j++) { colMean += t2.GetValue(j, i); } arr2[i] = colMean; } YMin = -10f; YMax = 10f; UltiDraw.DrawGUIFunction(new Vector2(0.5f, 0.9f), new Vector2(0.4f, 0.1f), arr0, YMin, YMax, UltiDraw.LightGrey, UltiDraw.Black, 0.002f, UltiDraw.BlackGrey); YMin = -16f; YMax = 13f; UltiDraw.DrawGUIFunction(new Vector2(0.5f, 0.79f), new Vector2(0.4f, 0.1f), arr1, YMin, YMax, UltiDraw.LightGrey, UltiDraw.Black, 0.002f, UltiDraw.BlackGrey); YMin = -2f; YMax = 2f; UltiDraw.DrawGUIFunction(new Vector2(0.5f, 0.68f), new Vector2(0.4f, 0.1f), arr2, YMin, YMax, UltiDraw.LightGrey, UltiDraw.Black, 0.002f, UltiDraw.BlackGrey); UltiDraw.End(); } } }
protected override void DerivedDraw(MotionEditor editor) { UltiDraw.Begin(); Frame frame = editor.GetCurrentFrame(); Color[] colors = UltiDraw.GetRainbowColors(Sensors.Length); if (ShowDebug) { for (int i = 0; i < Sensors.Length; i++) { if (Sensors[i].GetContact(frame, editor.Mirror) == 1f) { Vector3 contact = Sensors[i].GetContactPoint(frame, editor.Mirror); Vector3 corrected = Sensors[i].GetCorrectedContactPoint(frame, editor.Mirror); UltiDraw.DrawArrow(contact, corrected, 0.8f, 0.01f, DrawScale * 0.025f, colors[i].Transparent(0.5f)); UltiDraw.DrawSphere(contact, Quaternion.identity, DrawScale * 0.025f, UltiDraw.Yellow); UltiDraw.DrawSphere(corrected, Quaternion.identity, DrawScale * 0.05f, UltiDraw.Gold.Transparent(0.5f)); } } for (int i = 0; i < Sensors.Length; i++) { Matrix4x4 bone = frame.GetBoneTransformation(Sensors[i].Bone, editor.Mirror); Matrix4x4 corrected = Sensors[i].GetCorrectedTransformation(frame, editor.Mirror); UltiDraw.DrawCube(bone, DrawScale * 0.025f, UltiDraw.DarkRed.Transparent(0.5f)); UltiDraw.DrawLine(bone.GetPosition(), corrected.GetPosition(), colors[i].Transparent(0.5f)); UltiDraw.DrawCube(corrected, DrawScale * 0.025f, UltiDraw.DarkGreen.Transparent(0.5f)); } } if (ShowSensors) { for (int i = 0; i < Sensors.Length; i++) { Quaternion rot = editor.GetActor().GetBoneTransformation(Sensors[i].GetName()).GetRotation(); Vector3 pos = editor.GetActor().GetBoneTransformation(Sensors[i].GetName()).GetPosition() + rot * Sensors[i].Offset; UltiDraw.DrawCube(pos, rot, DrawScale * 0.025f, UltiDraw.Black); UltiDraw.DrawWireSphere(pos, rot, 2f * Sensors[i].Threshold, colors[i].Transparent(0.25f)); if (Sensors[i].GetContact(frame, editor.Mirror) == 1f) { UltiDraw.DrawSphere(pos, rot, 2f * Sensors[i].Threshold, colors[i]); } else { UltiDraw.DrawSphere(pos, rot, 2f * Sensors[i].Threshold, colors[i].Transparent(0.125f)); } } } if (ShowTolerances) { for (int i = 0; i < Sensors.Length; i++) { Quaternion rot = editor.GetActor().GetBoneTransformation(Sensors[i].GetName()).GetRotation(); Vector3 pos = editor.GetActor().GetBoneTransformation(Sensors[i].GetName()).GetPosition() + rot * Sensors[i].Offset; UltiDraw.DrawWireSphere(pos, rot, 2f * (Sensors[i].Tolerance + Sensors[i].Threshold), UltiDraw.DarkGrey.Transparent(0.25f)); } } if (ShowContacts) { for (int i = 0; i < Sensors.Length; i++) { if (Sensors[i].Edit != Sensor.ID.None) { for (float j = 0f; j <= Data.GetTotalTime(); j += Mathf.Max(Step, 1) / Data.Framerate) { Frame reference = Data.GetFrame(j); if (Sensors[i].GetContact(reference, editor.Mirror) == 1f) { UltiDraw.DrawSphere(Sensors[i].GetContactPoint(reference, editor.Mirror), Quaternion.identity, DrawScale * 0.025f, colors[i]); } } } } } /* * if(ShowSkeletons) { * UltiDraw.End(); * float start = Mathf.Clamp(frame.Timestamp-Window, 0f, Data.GetTotalTime()); * float end = Mathf.Clamp(frame.Timestamp+Window, 0f, Data.GetTotalTime()); * float inc = Mathf.Max(SkeletonStep, 1)/Data.Framerate; * for(float j=start; j<=end; j+=inc) { * Frame reference = Data.GetFrame(j); * float weight = (j-start+inc) / (end-start+inc); * editor.GetActor().Sketch(reference.GetBoneTransformations(editor.GetActor().GetBoneNames(), editor.Mirror), Color.Lerp(UltiDraw.Cyan, UltiDraw.Magenta, weight).Transparent(weight)); * } * UltiDraw.Begin(); * } */ if (TrueMotionTrajectory || CorrectedMotionTrajectory) { for (int i = 0; i < Sensors.Length; i++) { if (Sensors[i].Edit != Sensor.ID.None) { Vector3 previousPos = Vector3.zero; Vector3 previousCorrected = Vector3.zero; float start = Mathf.Clamp(frame.Timestamp - PastTrajectoryWindow, 0f, Data.GetTotalTime()); float end = Mathf.Clamp(frame.Timestamp + FutureTrajectoryWindow, 0f, Data.GetTotalTime()); for (float j = start; j <= end; j += Mathf.Max(Step, 1) / Data.Framerate) { Frame reference = Data.GetFrame(j); Matrix4x4 bone = reference.GetBoneTransformation(Sensors[i].Bone, editor.Mirror); Matrix4x4 corrected = Sensors[i].GetCorrectedTransformation(reference, editor.Mirror); if (j > start) { if (TrueMotionTrajectory) { UltiDraw.DrawArrow(previousPos, bone.GetPosition(), 0.8f, DrawScale * 0.005f, DrawScale * 0.025f, UltiDraw.DarkRed.Lighten(0.5f).Transparent(0.5f)); } if (CorrectedMotionTrajectory) { UltiDraw.DrawArrow(previousCorrected, corrected.GetPosition(), 0.8f, DrawScale * 0.005f, DrawScale * 0.025f, UltiDraw.DarkGreen.Lighten(0.5f).Transparent(0.5f)); } //UltiDraw.DrawLine(previousPos, bone.GetPosition(), UltiDraw.DarkRed.Transparent(0.5f)); //UltiDraw.DrawLine(previousCorrected, corrected.GetPosition(), UltiDraw.DarkGreen.Transparent(0.5f)); } previousPos = bone.GetPosition(); previousCorrected = corrected.GetPosition(); if (TrueMotionTrajectory) { UltiDraw.DrawCube(bone, DrawScale * 0.025f, UltiDraw.DarkRed.Transparent(0.5f)); } //UltiDraw.DrawLine(bone.GetPosition(), corrected.GetPosition(), colors[i].Transparent(0.5f)); if (CorrectedMotionTrajectory) { UltiDraw.DrawCube(corrected, DrawScale * 0.025f, UltiDraw.DarkGreen.Transparent(0.5f)); } } } } } if (ContactTrajectories) { for (int i = 0; i < Sensors.Length; i++) { if (Sensors[i].Edit != Sensor.ID.None) { float start = Mathf.Clamp(frame.Timestamp - Window, 0f, Data.GetTotalTime()); float end = Mathf.Clamp(frame.Timestamp + Window, 0f, Data.GetTotalTime()); for (float j = 0f; j <= Data.GetTotalTime(); j += Mathf.Max(Step, 1) / Data.Framerate) { Frame reference = Data.GetFrame(j); if (Sensors[i].GetContact(reference, editor.Mirror) == 1f) { Vector3 contact = Sensors[i].GetContactPoint(reference, editor.Mirror); Vector3 corrected = Sensors[i].GetCorrectedContactPoint(reference, editor.Mirror); UltiDraw.DrawArrow(contact, corrected, 0.8f, Vector3.Distance(contact, corrected) * DrawScale * 0.025f, Vector3.Distance(contact, corrected) * DrawScale * 0.1f, colors[i].Lighten(0.5f).Transparent(0.5f)); UltiDraw.DrawSphere(contact, Quaternion.identity, DrawScale * 0.0125f, colors[i].Transparent(0.5f)); UltiDraw.DrawSphere(corrected, Quaternion.identity, DrawScale * 0.05f, colors[i]); } } } } } if (ShowDistances) { for (int i = 0; i < Sensors.Length; i++) { if (Sensors[i].Edit != Sensor.ID.None) { for (float j = frame.Timestamp - PastTrajectoryWindow; j <= frame.Timestamp + FutureTrajectoryWindow; j += Mathf.Max(Step, 1) / Data.Framerate) { Frame reference = Data.GetFrame(j); if (Sensors[i].GetContact(reference, editor.Mirror) == 1f) { UltiDraw.DrawArrow(Sensors[i].GetContactPoint(reference, editor.Mirror), Sensors[i].GetContactPoint(reference, editor.Mirror) - Sensors[i].GetContactDistance(reference, editor.Mirror), 0.8f, DrawScale * 0.0025f, DrawScale * 0.01f, colors[i].Transparent(0.5f)); } } } } } UltiDraw.End(); }
public void Draw() { UltiDraw.Begin(); if (DrawRoot) { UltiDraw.DrawCube(GetRoot().position, GetRoot().rotation, 0.1f, UltiDraw.Black); UltiDraw.DrawTranslateGizmo(GetRoot().position, GetRoot().rotation, 0.1f); } if (DrawSkeleton) { Action <Bone> recursion = null; recursion = new Action <Bone>((bone) => { if (bone.GetParent() != null) { UltiDraw.DrawBone( bone.GetParent().Transform.position, Quaternion.FromToRotation(bone.GetParent().Transform.forward, bone.Transform.position - bone.GetParent().Transform.position) * bone.GetParent().Transform.rotation, 12.5f * BoneSize * bone.GetLength(), bone.GetLength(), bone.Color == UltiDraw.None ? BoneColor : bone.Color ); } UltiDraw.DrawSphere( bone.Transform.position, Quaternion.identity, 5f / 8f * BoneSize, JointColor ); for (int i = 0; i < bone.Childs.Length; i++) { recursion(bone.GetChild(i)); } }); foreach (Bone bone in GetRootBones()) { recursion(bone); } } if (DrawVelocities) { for (int i = 0; i < Bones.Length; i++) { UltiDraw.DrawArrow( Bones[i].Transform.position, Bones[i].Transform.position + Bones[i].Velocity, 0.75f, 0.0075f, 0.05f, UltiDraw.DarkGreen.Opacity(0.5f) ); } } if (DrawTransforms) { Action <Bone> recursion = null; recursion = new Action <Bone>((bone) => { UltiDraw.DrawTranslateGizmo(bone.Transform.position, bone.Transform.rotation, 0.05f); for (int i = 0; i < bone.Childs.Length; i++) { recursion(bone.GetChild(i)); } }); foreach (Bone bone in GetRootBones()) { recursion(bone); } } UltiDraw.End(); if (DrawSketch) { Sketch(GetBoneTransformations(), BoneColor); } if (DrawHistory) { if (DrawSkeleton) { int step = Mathf.Max(Sampling, 1); for (int i = 0; i < History.Count; i += step) { Sketch(History[i].Transformations, BoneColor.Darken(1f - (float)i / (float)History.Count)); } } if (DrawVelocities) { float max = 0f; float[][] functions = new float[History.Count][]; for (int i = 0; i < History.Count; i++) { functions[i] = new float[Bones.Length]; for (int j = 0; j < Bones.Length; j++) { functions[i][j] = History[i].Velocities[j].magnitude; max = Mathf.Max(max, functions[i][j]); } } UltiDraw.Begin(); UltiDraw.PlotFunctions(new Vector2(0.5f, 0.05f), new Vector2(0.9f, 0.1f), functions, UltiDraw.Dimension.Y, yMin: 0f, yMax: max, thickness: 0.0025f); UltiDraw.End(); } } }