Ejemplo n.º 1
0
        //////////////////////////
        ////// HANDLES DRAWERS
        ////// HANDLES DRAWERS
        ////// HANDLES DRAWERS
        //////////////////////////

        //////////////////////////
        //////SCENE UI DRAWING METHODS
        //////SCENE UI DRAWING METHODS
        //////////////////////////

        private void DrawKnotMovementHandle(ShapeKnot knot)
        {
            Vector3 SnapVal = Vector3.one * 0.25f;

            float size = (HandleUtility.GetHandleSize(Target.transform.TransformPoint(knot.kPos))) / handleSize;



            Handles.color = Color.red;
            EditorGUI.BeginChangeCheck();
            Vector3 newTargetPosition = Handles.FreeMoveHandle(Target.transform.TransformPoint(knot.kPos), Quaternion.identity, size, SnapVal, Handles.CircleHandleCap);

            //float remainder = newTargetPosition.x % SnapVal.x;
            //newTargetPosition = new Vector3(newTargetPosition.x+remainder, newTargetPosition.y, newTargetPosition.z);


            if (EditorGUI.EndChangeCheck())
            {
                Vector3 newPointPosition = new Vector3(newTargetPosition.x - Target.transform.position.x, 0, newTargetPosition.z - Target.transform.position.z);

                Undo.RecordObject(Target, "Change Look At Target Position");

                knot.kPos = newPointPosition;

                Target.UpdateSpline();
            }
        }
Ejemplo n.º 2
0
        public void AddKnot(int theIndex, Vector3 pos)
        {
            Debug.Log("Adding knot");

            ShapeKnot[] newKnots = new ShapeKnot[knots.Length + 1];


            ShapeKnot theKnot = new ShapeKnot();

            theKnot.myIndex        = theIndex;
            theKnot.myElementIndex = myIndex;
            //Handle in of the first Knot
            theKnot.kHandleIn = new Vector3(0, 0, -1);
            //Handle out of the first Knot
            theKnot.kHandleOut = new Vector3(0, 0, 1);

            for (int i = 0; i < newKnots.Length; i++)
            {
                if (i < theIndex)
                {
                    newKnots[i] = knots[i];
                }
                if (i == theIndex)
                {
                    newKnots[i] = theKnot;
                }
                if (i > theIndex)
                {
                    newKnots[i] = knots[i - 1];;
                }
            }
            knots = newKnots;
        }
Ejemplo n.º 3
0
        private void DrawKnotBezierHandles(ShapeKnot knot, bool handleIn, bool handleOut)
        {
            Vector3 SnapVal = Vector3.one * 0.25f;
            float   size    = (HandleUtility.GetHandleSize(Target.transform.TransformPoint(knot.kPos))) / handleSize;

            Handles.color = Color.yellow;

            Vector3 knotWorldPos = knot.KWorldPos(Target.transform);


            if (handleIn)
            {
                EditorGUI.BeginChangeCheck();
                Vector3 handlePos = knotWorldPos + knot.kHandleIn;
                Handles.color = Color.green;

                Vector3 newTargetPosition = Handles.FreeMoveHandle(handlePos, Quaternion.identity, (size / 2), SnapVal, Handles.RectangleHandleCap);

                if (EditorGUI.EndChangeCheck())
                {
                    //Vector3 newPointPosition = new Vector3(newTargetPosition.x - handlePos.x, 0, newTargetPosition.z - handlePos.z);
                    Vector3 newPointPosition = newTargetPosition - knotWorldPos;
                    newPointPosition.y = 0;

                    Undo.RecordObject(Target, "Change Look At Target Position");

                    knot.kHandleIn = newPointPosition;
                }


                Handles.color = Color.yellow;
                Handles.DrawLine(knotWorldPos, (knotWorldPos + knot.kHandleIn));
            }
            if (handleOut)
            {
                EditorGUI.BeginChangeCheck();
                Vector3 handlePos = knotWorldPos + knot.kHandleOut;

                Handles.color = Color.green;

                Vector3 newTargetPosition = Handles.FreeMoveHandle(handlePos, Quaternion.identity, (size / 2), SnapVal, Handles.RectangleHandleCap);

                if (EditorGUI.EndChangeCheck())
                {
                    //Vector3 newPointPosition = new Vector3(newTargetPosition.x - handlePos.x, 0, newTargetPosition.z - handlePos.z);
                    Vector3 newPointPosition = newTargetPosition - knotWorldPos;
                    newPointPosition.y = 0;

                    Undo.RecordObject(Target, "Change Look At Target Position");

                    knot.kHandleOut = newPointPosition;
                }



                Handles.color = Color.yellow;
                Handles.DrawLine(knotWorldPos, (knotWorldPos + knot.kHandleOut));
            }
        }
Ejemplo n.º 4
0
        //////////////////////////
        ////// SEGMENT DRAWERS
        ////// SEGMENT DRAWERS
        ////// SEGMENT DRAWERS
        //////////////////////////

        void DrawSegmentHandles(ShapeKnot firstKnot, ShapeKnot secondKnot)
        {
            //Debug.Log("Drawing Segment");
            if (firstKnot.kType == KnotType.Linear && secondKnot.kType == KnotType.Linear)
            {
                Vector3 firstKnotWorldPos  = Target.transform.TransformPoint(firstKnot.kPos);
                Vector3 secondKnotWorldPos = Target.transform.TransformPoint(secondKnot.kPos);

                //Debug.Log("First Pos: " + firstKnotWorldPos);
                //Debug.Log("Second Pos: " + secondKnotWorldPos);

                //Gizmos.DrawLine(firstKnotWorldPos, secondKnotWorldPos);
            }
        }
Ejemplo n.º 5
0
        public void AddKnot(ShapeKnot theKnot)
        {
            Debug.Log("Adding knot");

            ShapeKnot[] newKnots = new ShapeKnot[knots.Length + 1];

            for (int i = 0; i < knots.Length; i++)
            {
                newKnots[i] = knots[i];
            }
            newKnots[newKnots.Length - 1] = theKnot;

            knots = newKnots;
            UpdateKnots();
        }
Ejemplo n.º 6
0
        private void DrawKnotSelector(ShapeKnot knot)
        {
            Handles.color = Color.green;
            Vector3 SnapVal = Vector3.one * 0.25f;

            float size = (HandleUtility.GetHandleSize(Target.transform.TransformPoint(knot.kPos))) / handleSize;

            if (Handles.Button(Target.transform.TransformPoint(knot.kPos), Quaternion.Euler(90, 0, 0), size, size, Handles.RectangleHandleCap))
            {
                //Debug.Log("Selected Knot " + Target.selectedElementIndex.ToString() + " " + Target.selectedKnotIndex.ToString());

                if (ctrlFlag && altFlag)
                {
                    Debug.Log("knot selected with ctrl pressed");
                    CheckForVertexTypeCycle();
                }
                if (!altFlag)
                {
                    //Deselect previous knots
                    if (Target.selectedKnots.Count != 0)
                    {
                        for (int i = Target.selectedKnots.Count - 1; i >= 0; i--)
                        {
                            Target.selectedKnots[i].isSelected = false;
                            Target.selectedKnots.RemoveAt(i);
                        }
                    }
                    knot.isSelected = true;
                    Target.selectedKnots.Add(knot);
                }
                else
                {
                    Target.elements[0].RemoveKnot(knot.myIndex);
                    Debug.Log("Deleting Knot");
                }
            }
        }