public static void DrawSelector(Waypoint keyframe, bool showTime = false) { Vector3 position = GlobalTransform.Transfomed(keyframe.Position); float size = 0.025f; float hitboxSize = 1.5f * size; // -- DOT -- // Handles.color = Color.white; Handles.SphereHandleCap(0, position, Quaternion.identity, size, EventType.Repaint); // -- SELECTION -- // if (CustomHandles.SelectableButton(position, hitboxSize, Color.white)) { Selection.activeObject = keyframe; targetPoint = 0; } // -- MOVEMENT -- // FreeMove(keyframe, position, hitboxSize, CustomHandles.NullCap, keyframe.SetPosition); // -- LABEL -- // if (showTime) { string timestamp = $"{keyframe.time.ToString("0.0")} s"; Handles.Label(position + LabelOffset, timestamp, CustomGUI.LabelStyle); } }
protected override void OnDrawScene(SceneView scene) { Waypoint keyframe = Target; Crazyflie drone = keyframe.Drone; CrazyflieEditor.Draw(drone); Vector3 position = GlobalTransform.Transfomed(keyframe.Position); if (keyframe.JointType != JointType.Linear) { DrawTangent(keyframe, false); DrawTangent(keyframe, true); } if (targetPoint == 0) { CustomHandles.DrawCircle(position, 0.0375f, Color.yellow); MoveHandle(keyframe, position, 0.06f, 0.045f, keyframe.SetPosition); } else { CustomHandles.DrawCircle(position, 0.0375f, Color.white); } if (Event.current.type == EventType.KeyDown && Event.current.keyCode == KeyCode.Delete) { drone.RemoveWaypoint(Target); } // -- GUI -- // DrawGUI(keyframe); }
protected void DrawTangent(Waypoint keyframe, bool invert) { Vector3 position = GlobalTransform.Transfomed(keyframe.Position); Vector3 tangentPosition = GlobalTransform.Transfomed(invert ? keyframe.InverseWorldTangent : keyframe.WorldTangent); Action <Vector3> applyFunction = invert ? (Action <Vector3>)keyframe.SetInverseTangent : keyframe.SetTangent; Handles.color = Color.white; Handles.SphereHandleCap(0, tangentPosition, Quaternion.identity, 0.01f, EventType.Repaint); Handles.color = Palette.Translucent; Handles.DrawLine(position, tangentPosition); if (CustomHandles.SelectableButton(tangentPosition, 0.015f, Color.white)) { targetPoint = (invert ? 2 : 1); } // Circle FreeMove(keyframe, tangentPosition, 0.015f, CustomHandles.CircleCap, applyFunction); // Selected if ((!invert && targetPoint == 1) || (invert && targetPoint == 2)) { CustomHandles.DrawCircle(tangentPosition, 0.015f, Color.yellow); MoveHandle(keyframe, tangentPosition, 0.04f, 0.025f, applyFunction); } }
public void ApplyGlobalTransform() { List <Waypoint> waypoints = this.Waypoints; if (waypoints == null) { return; } Undo.RecordObjects(waypoints.ToArray(), "Apply Global Transform"); foreach (Waypoint waypoint in waypoints) { Vector3 newPosition = GlobalTransform.Transfomed(waypoint.Position); Vector3 newTangent = GlobalTransform.Transfomed(waypoint.WorldTangent); waypoint.SetPosition(newPosition); waypoint.SetTangent(newTangent); } }
public static void DrawWaypoints(List <Waypoint> waypoints) { foreach (Waypoint waypoint in waypoints) { WaypointEditor.DrawSelector(waypoint, showTimestamps); } if (showEndpoints) { Waypoint firstWaypoint = waypoints[0]; Waypoint lastWaypoint = waypoints[waypoints.Count - 1]; Vector3 endOffset = (waypoints.Count < 2) ? AlternateLabelOffset : LabelOffset; Handles.Label(GlobalTransform.Transfomed(firstWaypoint.Position) + LabelOffset, "START", CustomGUI.TitleStyle); Handles.Label(GlobalTransform.Transfomed(lastWaypoint.Position) + endOffset, "END", CustomGUI.TitleStyle); } }
public static void DrawBezierPath(List <Waypoint> waypoints, Color pathColor, float thiccness = 3.0f) { int numKeyframes = waypoints.Count - 1; for (int i = 0; i < numKeyframes; i++) { Waypoint currentKeyframe = waypoints[i]; Waypoint nextKeyframe = waypoints[i + 1]; bool linearStart = (currentKeyframe.JointType == JointType.Linear); bool linearEnd = (nextKeyframe.JointType == JointType.Linear); Vector3 startPos = GlobalTransform.Transfomed(currentKeyframe.Position); Vector3 endPos = GlobalTransform.Transfomed(nextKeyframe.Position); Vector3 startTangent = linearStart ? startPos : GlobalTransform.Transfomed(currentKeyframe.WorldTangent); Vector3 endTangent = linearEnd ? endPos : GlobalTransform.Transfomed(nextKeyframe.InverseWorldTangent); Handles.DrawBezier(startPos, endPos, startTangent, endTangent, pathColor, null, thiccness); } }
private static Vector3 CalculateTangent(Waypoint currentKeyframe, Waypoint nextKeyframe, float interpolation, bool normalize = false) { bool linearStart = (currentKeyframe.JointType == JointType.Linear); bool linearEnd = (nextKeyframe.JointType == JointType.Linear); Vector3 startPos = GlobalTransform.Transfomed(currentKeyframe.Position); Vector3 endPos = GlobalTransform.Transfomed(nextKeyframe.Position); Vector3 startTangent = linearStart ? startPos : GlobalTransform.Transfomed(currentKeyframe.WorldTangent); Vector3 endTangent = linearEnd ? endPos : GlobalTransform.Transfomed(nextKeyframe.InverseWorldTangent); // dP(t) / dt = (-3(1-t)^2 * P0) + (3(1-t)^2 * P1) + (-6t(1-t) * P1) + (-3t^2 * P2) + (6t(1-t) * P2) + (3t^2 * P3) float inverse = 1.0f - interpolation; float C0 = -3.0f * Mathf.Pow(inverse, 2.0f); float C1 = 3.0f * Mathf.Pow(inverse, 2.0f); float C2 = -6.0f * inverse * interpolation; float C3 = -3.0f * Mathf.Pow(interpolation, 2.0f); float C4 = 6.0f * interpolation * inverse; float C5 = 3.0f * Mathf.Pow(interpolation, 2.0f); Vector3 result = (C0 * startPos) + ((C1 + C2) * startTangent) + ((C3 + C4) * endTangent) + (C5 * endPos); return(normalize ? result.normalized : result); }
public static Vector3 GetPosition(List <Waypoint> keyframes, double time, Vector3 defaultPosition) { Vector3 position = FindPosition(keyframes, time, defaultPosition); return(GlobalTransform.Transfomed(position)); }