Beispiel #1
0
    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);
        }
    }
Beispiel #2
0
    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);
    }
Beispiel #3
0
    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);
        }
    }
Beispiel #4
0
    protected static void DrawPointHandles(List <AttachmentPoint> points)
    {
        foreach (AttachmentPoint point in points)
        {
            Vector3 position = point.Position;
            CustomHandles.DrawDisc(position, 0.0075f, Color.white);
            if (CustomHandles.SelectableButton(position, 0.035f, Color.green))
            {
                foreach (AttachmentPoint otherPoint in points)
                {
                    otherPoint.Selected = false;
                }

                point.Selected = true;
            }

            if (point.Selected)
            {
                CustomHandles.DrawCircle(position, 0.035f, Color.white);
                Crazyflie[] drones = GameObject.FindObjectsOfType <Crazyflie>();
                foreach (Crazyflie drone in drones)
                {
                    if (CustomHandles.SelectableButton(drone.transform.position, 0.075f, Color.green))
                    {
                        drone.SetWaypoint(position, drone.Time);
                        point.Drone    = drone;
                        point.Selected = false;
                    }
                }
            }
        }
    }
Beispiel #5
0
 private static void DrawNonSelected(Crazyflie drone, GizmoType gizmo)
 {
     if (PreferencesMenu.PathEnabled)
     {
         //DrawDroneBounds(drone, Palette.UltraTranslucent);
         List <Waypoint> waypoints = drone.Waypoints;
         CustomHandles.DrawBezierPath(waypoints, Palette.UltraTranslucent, 2.0f);
     }
 }
Beispiel #6
0
 public static void DrawSphereHandle(Vector3 position, float size, Color inactiveColor, Color activeColor)
 {
     if (CustomHandles.InsideHandleOnGUI(position))
     {
         DebugDraw.DrawSphere(position, size, activeColor);
     }
     else
     {
         DebugDraw.DrawSphere(position, size, inactiveColor);
     }
 }
Beispiel #7
0
    private static void MoveHandle(Waypoint keyframe, Vector3 position, float size, float offset, Action <Vector3> applyFunction)
    {
        EditorGUI.BeginChangeCheck();
        Vector3 updatedPosition = CustomHandles.MoveHandle(position, offset, size);

        updatedPosition = GlobalTransform.InverseTransfomed(updatedPosition);
        if (EditorGUI.EndChangeCheck())
        {
            Undo.RecordObject(keyframe, "Change Waypoint");
            applyFunction.Invoke(updatedPosition);
            keyframe.Drone.UpdateView();
        }
    }
Beispiel #8
0
    public static void CircleCap(int controlId, Vector3 position, Quaternion rotation, float size, EventType eventType)
    {
        if (eventType == EventType.Layout)
        {
            float distance = HandleUtility.DistanceToCircle(position, size);
            HandleUtility.AddControl(controlId, distance);
        }

        if (eventType == EventType.Repaint)
        {
            Vector3 normal = CustomHandles.GetNormal(position);
            Handles.DrawWireDisc(position, normal, size);
        }
    }
Beispiel #9
0
    public static void DrawSquareTextureAtWorldPoint(Vector3 position, float width, Texture texture, Texture textureSelected)
    {
        Vector3 screenPoint = Camera.main.WorldToScreenPoint(position).SwapScreenToWorldPoint();
        Rect    rect        = new Rect(screenPoint.x - width / 2f, screenPoint.y - width / 2f, width, width);

        if (CustomHandles.InsideHandleOnGUI(position))
        {
            GUI.DrawTexture(rect, textureSelected);
        }
        else
        {
            GUI.DrawTexture(rect, texture);
        }
    }
Beispiel #10
0
    public static void DrawSelector(ColorKeyframe keyframe)
    {
        int     hint           = (ControlHint * keyframe.MarkerIndex) + keyframe.MarkerIndex;
        int     controlId      = GUIUtility.GetControlID(hint, FocusType.Passive);
        Vector3 offsetPosition = keyframe.Position + new Vector3(0, keyframe.Offset, 0);

        float size       = 0.0175f;
        float hitboxSize = 1.5f * size;

        // -- DOT & LINE -- //
        Handles.color = Palette.Translucent;
        Handles.DrawLine(keyframe.Position, offsetPosition);
        CustomHandles.DrawDisc(offsetPosition, size * 0.5f, keyframe.LightColor);

        // -- SELECTION -- //
        if (CustomHandles.SelectableButton(offsetPosition, hitboxSize, keyframe.LightColor))
        {
            Selection.activeObject = keyframe;
        }

        bool selected = Selection.activeObject == keyframe;

        if (selected)
        {
            CustomHandles.DrawCircle(offsetPosition, hitboxSize, keyframe.LightColor);
        }


        /// -- MOVEMENT -- //
        EditorGUI.BeginChangeCheck();
        Vector3 newPosition = Handles.FreeMoveHandle(controlId, offsetPosition, Quaternion.identity, size, DefaultSnap, CustomHandles.NullCap);

        if (EditorGUI.EndChangeCheck() && selected)
        {
            Undo.RecordObject(keyframe, "Change Color Keyframe");

            Vector3 delta = (newPosition - offsetPosition);
            ApplyDelta(keyframe, keyframe.Tangent, delta);

            keyframe.Drone.UpdateView();
            TimelineEditor.Refresh(RefreshReason.ContentsModified);
        }
    }
Beispiel #11
0
    /// -------- DRONE HANDLES -------- ///

    public static void DrawDroneHandles(Crazyflie drone, bool active)
    {
        float           time      = (float)TimelineUtilities.Director.time;
        List <Waypoint> waypoints = drone.Waypoints;

        CustomHandles.DrawBezierPath(waypoints, Color.white, 2.0f);
        DrawWaypoints(waypoints);
        ColorKeyframeEditor.DrawColorKeyframes(drone, waypoints);
        if (active)
        {
            DrawDroneBounds(drone, Palette.Translucent);
            // DrawDroneBounds(drone, Color.white);

            EditorGUI.BeginChangeCheck();
            Vector3 updatedPosition = CustomHandles.MoveHandle(drone.transform.position, 0.025f, 0.085f);
            if (EditorGUI.EndChangeCheck())
            {
                drone.SetWaypoint(updatedPosition, time);
            }
        }

        //CustomHandles.DrawTangent(waypoints, 0.25f, time);
    }
Beispiel #12
0
        private void OnSceneGUI()
        {
            BezierSpline spline = (BezierSpline)target;
            bool         change = false;
            Vector3      oldPos;

            //if (spline.Parameters == null) return;

            // Draw Root
            Handles.color = Color.yellow;
            Handles.CubeCap(0, spline.transform.position, Quaternion.identity, 0.4f);

            // Draw First Point
            if (spline._showAnchors)
            {
                Undo.RecordObject(spline.SplinePoints[0].transform, "Move Point");
                Handles.color = Color.red;
                Handles.SphereCap(0, spline.SplinePoints [0].transform.position, Quaternion.identity, 0.3f);
                oldPos = spline.SplinePoints [0].transform.position;
                spline.SplinePoints [0].transform.position = Handles.PositionHandle(spline.SplinePoints [0].transform.position, Quaternion.identity);
                if ((oldPos - spline.SplinePoints [0].transform.position).magnitude > 0.00001f)
                {
                    change = true;

                    //spline.ControlPoints[0] += (spline.SplinePoints[0].transform.position - oldPos);
                    // Remember to add the loop control point if required
                }
            }

            //int loop = spline.Loop ? 1 : 0;

            for (int s = 0; s < spline.SegmentCount; ++s)            // - loop
            {
                // Draw each segment

                if (spline._showAnchors)
                {
                    // Draw Point
                    Undo.RecordObject(spline.SplinePoints [s + 1].transform, "Move Point");
                    Handles.color = Color.red;
                    Handles.SphereCap(0, spline.SplinePoints [s + 1].transform.position, Quaternion.identity, 0.3f);
                    oldPos = spline.SplinePoints [s + 1].transform.position;
                    spline.SplinePoints [s + 1].transform.position = Handles.PositionHandle(spline.SplinePoints [s + 1].transform.position, Quaternion.identity);
                    if ((oldPos - spline.SplinePoints [s + 1].transform.position).magnitude > 0.00001f)
                    {
                        change = true;
                    }
                }

                if (spline._showHelperAnchors)
                {
                    for (int i = 0; i < 2; ++i)
                    {
                        // Draw Control point
                        Undo.RecordObject(spline, "Move Control Point");
                        Handles.color = Color.magenta;
                        Handles.SphereCap(0, spline.GetControlPointWorldPos(s + s + i), Quaternion.identity, 0.2f);
                        oldPos = spline.ControlPoints [s + s + i];

                        spline.ControlPoints [s + s + i] = spline.GetControlPointInverseWorldPos(Handles.PositionHandle(spline.GetControlPointWorldPos(s + s + i), Quaternion.identity), s + s + i);
                        if ((oldPos - spline.ControlPoints [s + s + i]).magnitude > 0.00001f)
                        {
                            // If the control point was moved, set the bordering control point to the opposite location
                            change = true;
                            int iTangent = spline.GetTangentControlPoint(s + s + i);
                            if (iTangent != -1)
                            {
                                spline.ControlPoints [iTangent] = -spline.ControlPoints [s + s + i];
                            }
                        }

                        // Draw control handles
                        Handles.color = Color.yellow;
                        Handles.DrawLine(spline.SplinePoints [s].transform.position, spline.GetControlPointWorldPos(s + s));
                        Handles.DrawLine(spline.SplinePoints [s + 1].transform.position, spline.GetControlPointWorldPos(s + s + 1));
                    }
                }

                if (spline._showBreakAnchors)
                {
                    if (spline.BreakIntervals != null)
                    {
                        foreach (BreakInterval breakInterval in spline.BreakIntervals)
                        {
                            Handles.color = Color.red;
                            CustomHandles.DragHandleResult dhResult;
                            this.adjustBreakInterval(breakInterval, CustomHandles.DragHandle(breakInterval._PointA, breakInterval._DirectionA, 1f, Handles.ConeCap, Color.yellow, out dhResult), BreakInterval.Points.PointA);
                            this.adjustBreakInterval(breakInterval, CustomHandles.DragHandle(breakInterval._PointB, breakInterval._DirectionB, 1f, Handles.ConeCap, Color.yellow, out dhResult), BreakInterval.Points.PointB);
                        }
                    }
                }
            }

            //if(spline.Loop)
            //{
            //	// Draw last 2 control handles
            //	Handles.color = Color.yellow;
            //	Handles.DrawLine(spline.SplinePoints[0].transform.position, spline.GetControlPointWorldPos(spline.ControlPoints.Count-1));
            //	//Handles.DrawLine(spline.SplinePoints[spline.SplinePoints.Count-1].transform.position, spline.GetControlPointWorldPos(spline.ControlPoints.Count-2));
            //}

            // Recalculate length and such if the positions has been changed
            if (change)
            {
                spline.Recalculate();
            }
        }
Beispiel #13
0
    void Draw()
    {
        for (int j = 0; j < VertPath[currentPathIndex].vertPoints.Count; j++)
        {
            Handles.DrawSphere(0, VertPath[currentPathIndex].vertPoints[j].Position, Quaternion.identity, .05f);

            Handles.DrawLine(VertPath[currentPathIndex].vertPoints[j].Position, VertPath[currentPathIndex].vertPoints[j].Position + VertPath[currentPathIndex].vertPoints[j].Rotation * Vector3.up * .5f);
        }

        for (int i = 0; i < Path.Count; i++)
        {
            for (int j = 0; j < Path[i].NumSegments; j++)
            {
                Vector3[] points = Path[i].GetPointsInSegment(j);

                Handles.color = Color.black;

                if (i == currentPathIndex)
                {
                    Handles.DrawLine(points[1], points[0]);
                    Handles.DrawLine(points[2], points[3]);
                }
                Color segmentColor = (j == selectedSegmentIndex && (Event.current.shift && !Event.current.control) && hoveredPathIndex == currentPathIndex) ? BezOptions.SelectedSegmentCol : BezOptions.ActiveSegmentCol;
                segmentColor = (i == currentPathIndex) ? segmentColor : BezOptions.UnactiveSegmentCol;
                Color highlightColor = (i == currentPathIndex) ? BezOptions.ActiveSegmentHighlight : BezOptions.UnactiveSegmentHighlight;
                Handles.DrawBezier(points[0], points[3], points[1], points[2], highlightColor, null, 10);
                Handles.DrawBezier(points[0], points[3], points[1], points[2], segmentColor, null, 6);
            }
        }



        for (int i = 0; i < Path[currentPathIndex].NumPoints; i++)
        {
            bool mainPoint = i % 3 == 0;
            Handles.color = mainPoint ? BezOptions.AnchorCol : BezOptions.ControlCol;
            float handleSize = mainPoint ? BezOptions.AnchorDiameter : BezOptions.ControlDiameter;

            CustomHandles.DragHandleResult dhResult = CustomHandles.DragHandleResult.none;

            Vector3 newPosition = Path[currentPathIndex][i];

            if (selectedAnchor == i)
            {
                bool lmbDrag = false;
                if (handleMode == AnchorModes.POSITION)
                {
                    Handles.color = Color.red;
                    newPosition.x = CustomHandles.DragHandle(newPosition, Quaternion.LookRotation(Vector3.right, Vector3.up), 1f, Handles.ArrowCap, Color.yellow, out dhResult).x;
                    if (dhResult == CustomHandles.DragHandleResult.LMBDrag)
                    {
                        lmbDrag = true;
                    }

                    Handles.color = Color.green;
                    newPosition.y = CustomHandles.DragHandle(newPosition, Quaternion.LookRotation(Vector3.up, Vector3.forward), 1f, Handles.ArrowCap, Color.yellow, out dhResult).y;
                    if (dhResult == CustomHandles.DragHandleResult.LMBDrag)
                    {
                        lmbDrag = true;
                    }

                    Handles.color = Color.blue;
                    newPosition.z = CustomHandles.DragHandle(newPosition, Quaternion.LookRotation(Vector3.forward, Vector3.right), 1f, Handles.ArrowCap, Color.yellow, out dhResult).z;
                    if (dhResult == CustomHandles.DragHandleResult.LMBDrag)
                    {
                        lmbDrag = true;
                    }
                }
                else if (handleMode == AnchorModes.ROTATION)
                {
                    Handles.color = Color.yellow;
                    Quaternion newRot = Handles.Disc(0, Path[currentPathIndex].rotations[i / 3], Path[currentPathIndex][i], Path[currentPathIndex].rotations[i / 3] * Vector3.forward, 1f, false, VertOptions.RotationalSnap);
                    Path[currentPathIndex].ChangeRotation(i / 3, newRot);
                    creator.SetVertPath(Path[currentPathIndex].CalculateEvenlySpacedPointsAndNormals(VertOptions.VertSpacing, VertOptions.Resolution), currentPathIndex);
                }


                if (newPosition != Path[currentPathIndex][i] && lmbDrag)
                {
                    dhResult = CustomHandles.DragHandleResult.LMBDrag;
                }
            }
            else
            {
                newPosition = CustomHandles.DragHandle(Path[currentPathIndex][i], Quaternion.identity, handleSize, Handles.SphereCap, Color.yellow, out dhResult);
            }

            switch (dhResult)
            {
            case CustomHandles.DragHandleResult.LMBClick:
                if (mainPoint == true)
                {
                    selectedAnchor = i;
                }

                break;

            case CustomHandles.DragHandleResult.LMBDrag:
                Undo.RecordObject(creator, "Move Point");
                if (guiEvent.control)
                {
                    Ray        mouseRay = Camera.current.ScreenPointToRay(screenSpaceMousePos);
                    RaycastHit hit;
                    newPosition = mouseRay.origin + mouseRay.direction * 5f;
                    if (Physics.Raycast(mouseRay.origin, mouseRay.direction, out hit, 30f))
                    {
                        newPosition = hit.point;
                    }
                }
                Path[currentPathIndex].MovePoint(i, newPosition);
                creator.SetVertPath(Path[currentPathIndex].CalculateEvenlySpacedPointsAndNormals(VertOptions.VertSpacing, VertOptions.Resolution), currentPathIndex);

                break;

            default:
                break;
            }
        }
    }