public void drawGUIControls()
        {
            //FreeCurve gener = (FreeCurve) generator;

            //AXModel model = ArchimatixEngine.currentModel;


            // 2D GUI
            Handles.BeginGUI();

            GUIStyle buttonStyle = GUI.skin.GetStyle("Button");

            buttonStyle.alignment = TextAnchor.MiddleCenter;

            float prevFixedWidth  = buttonStyle.fixedWidth;
            float prevFixedHeight = buttonStyle.fixedHeight;


            buttonStyle.fixedHeight = 30;

            //GUIStyle areaStyle = new GUIStyle();
            //areaStyle. = MakeTex(600, 1, new Color(1.0f, 1.0f, 1.0f, 0.1f));

            float windowWidth = (SceneView.lastActiveSceneView != null) ? SceneView.lastActiveSceneView.position.width : Screen.width;
            float buttonWid   = 100;

            if (ArchimatixEngine.sceneViewState == ArchimatixEngine.SceneViewState.Default)
            {
                if (GUI.Button(new Rect(((windowWidth - buttonWid) / 2), 20, buttonWid, 30), "Add Point"))
                {
                    ArchimatixEngine.setSceneViewState(ArchimatixEngine.SceneViewState.AddPoint);
                }
            }
            else
            {
                buttonWid = 200;
                if (GUI.Button(new Rect(((windowWidth - buttonWid) / 2), 20, buttonWid, 30), "Done Adding Points"))
                {
                    ArchimatixEngine.setSceneViewState(ArchimatixEngine.SceneViewState.Default);
                }
            }



            EditorGUIUtility.labelWidth = 40;



            Handles.EndGUI();



            buttonStyle.fixedWidth  = prevFixedWidth;
            buttonStyle.fixedHeight = prevFixedHeight;
        }
Пример #2
0
        public override void drawControlHandles(ref List <string> visited, Matrix4x4 consumerM, bool beingDrawnFromConsumer)
        {
            Matrix4x4 prevHandlesMatrix = Handles.matrix;

            FreeCurve gener = (FreeCurve)parametricObject.generator;



            base.drawControlHandles(ref visited, consumerM, true);

            if (alreadyVisited(ref visited, "FreeCurveHandler"))
            {
                return;
            }



            AXParameter p = parametricObject.getParameter("Output Shape");

            if (p == null || p.getPaths() == null)
            {
                return;
            }


            parametricObject.model.addActiveFreeCurve(parametricObject);

            Event e = Event.current;

            if (ArchimatixEngine.sceneViewState == ArchimatixEngine.SceneViewState.AddPoint && e.type == EventType.keyDown && (e.keyCode == KeyCode.Escape || e.keyCode == KeyCode.Return))
            {
                ArchimatixEngine.setSceneViewState(ArchimatixEngine.SceneViewState.Default);


                e.Use();
            }


            handlePoints = new List <Vector2>();


            bool handleHasChanged = false;

            /*
             * Matrix4x4 context        = parametricObject.model.transform.localToWorldMatrix * generator.parametricObject.worldDisplayMatrix;
             * if (generator.hasOutputsConnected() || parametricObject.is2D())
             *      context *= generator.localMatrix.inverse;
             * else
             *      context *= parametricObject.getAxisRotationMatrix().inverse  * generator.localMatrix.inverse * parametricObject.getAxisRotationMatrix();
             *
             * Handles.matrix = context;
             */
            Handles.matrix = parametricObject.model.transform.localToWorldMatrix * generator.parametricObject.worldDisplayMatrix;            // * generator.localMatrix.inverse;


            float gridDim = parametricObject.model.snapSizeGrid * 100;

            // axis
            Handles.color = Color.red;
            Handles.DrawLine(new Vector3(-gridDim / 2, 0, 0), new Vector3(gridDim / 2, 0, 0));
            Handles.color = Color.green;
            Handles.DrawLine(new Vector3(0, -gridDim / 2, 0), new Vector3(0, gridDim / 2, 0));

            // grid

            if (ArchimatixEngine.snappingOn())
            {
                Handles.color = new Color(1, .5f, .65f, .15f);
            }
            else
            {
                Handles.color = new Color(1, .5f, .65f, .05f);
            }


            AXEditorUtilities.DrawGrid3D(gridDim, parametricObject.model.snapSizeGrid);



            //Handles.matrix = Matrix4x4.identity;

            CurvePoint newCurvePoint      = null;;
            int        newCurvePointIndex = -1;

            if (parametricObject.curve != null)
            {
                //if (Event.current.type == EventType.mouseDown)
                //	selectedIndex = -1;

                //Vector3 pos;



                for (int i = 0; i < parametricObject.curve.Count; i++)
                {
                    //Debug.Log (i + ": "+ parametricObject.curve[i].position);

                    // Control points in Curve

                    bool pointIsSelected = (generator.selectedIndices != null && generator.selectedIndices.Contains(i));



                    Vector3 pos = new Vector3(parametricObject.curve[i].position.x, parametricObject.curve[i].position.y, 0);



                    Handles.color = (pointIsSelected) ? Color.white :  Color.magenta;

                    float capSize = .13f * HandleUtility.GetHandleSize(pos);

                    if (pointIsSelected)
                    {
                        capSize = .17f * HandleUtility.GetHandleSize(pos);
                    }



                    // POSITION
                    //pos = new Vector3(parametricObject.curve[i].position.x, parametricObject.curve[i].position.y, 0);

//					pos = Handles.FreeMoveHandle(
//						pos,
//						Quaternion.identity,
//						capSize,
//						Vector3.zero,
//						(controlID, positione, rotation, size) =>
//					{
//						if (GUIUtility.hotControl > 0 && controlID == GUIUtility.hotControl)
//						Debug.Log("YOP");
//						Handles.SphereCap(controlID, positione, rotation, size);
//					});


                    pos = Handles.FreeMoveHandle(
                        pos,
                        Quaternion.identity,
                        capSize,
                        Vector3.zero,
                        (controlID, position, rotation, size) =>
                    {
                        if (GUIUtility.hotControl > 0 && controlID == GUIUtility.hotControl)
                        {
                            //Debug.Log("*** " + e.type + " -" + e.keyCode + "-");

                            // MOUSE DOWN ON HANDLE!

                            Undo.RegisterCompleteObjectUndo(parametricObject.model, "FreeCurve");
                            //Debug.Log(controlID + ": " + e.type);

                            ArchimatixEngine.selectedFreeCurve = gener;

                            //Debug.Log("SELECT NODE " +i + " ci="+controlID);

                            if (i == 0 && ArchimatixEngine.sceneViewState == ArchimatixEngine.SceneViewState.AddPoint)
                            {
                                generator.P_Output.shapeState = ShapeState.Closed;
                                ArchimatixEngine.setSceneViewState(ArchimatixEngine.SceneViewState.Default);
                            }
                            else if (e.shift && !ArchimatixEngine.mouseIsDownOnHandle)
                            {
                                generator.toggleItem(i);
                            }

                            else if (gener.selectedIndices == null || gener.selectedIndices.Count < 2)
                            {
                                if (!generator.isSelected(i))
                                {
                                    generator.selectOnlyItem(i);
                                }
                            }
                            ArchimatixEngine.isPseudoDraggingSelectedPoint = i;

                            // CONVERT TO BEZIER
                            if (e.alt)
                            {
                                gener.convertToBezier(i);
                            }



                            for (int j = 0; j < generator.P_Output.Dependents.Count; j++)
                            {
                                generator.P_Output.Dependents [j].parametricObject.generator.adjustWorldMatrices();
                            }


                            ArchimatixEngine.mouseDownOnSceneViewHandle();
                        }


                        Handles.SphereCap(controlID, position, rotation, size);
                    });



                    // MID_SEGEMNET HANDLE

                    if (i < parametricObject.curve.Count)
                    {
                        //Handles.matrix = parametricObject.model.transform.localToWorldMatrix * generator.parametricObject.worldDisplayMatrix * generator.localMatrix.inverse;

                        Handles.color = Color.cyan;

                        //Debug.Log("mid handle "+i);

                        CurvePoint a = parametricObject.curve[i];

                        int next_i = (i == parametricObject.curve.Count - 1) ? 0 : i + 1;

                        CurvePoint b = parametricObject.curve[next_i];

                        if (a.isPoint() && b.isPoint())
                        {
                            pos = Vector2.Lerp(a.position, b.position, .5f);
                        }
                        else
                        {
                            Vector2 pt = FreeCurve.bezierValue(a, b, .5f);
                            pos = (Vector3)pt;
                        }

                        EditorGUI.BeginChangeCheck();

                                                #if UNITY_5_6_OR_NEWER
                        pos = Handles.FreeMoveHandle(
                            pos,
                            Quaternion.identity,
                            .06f * HandleUtility.GetHandleSize(pos),
                            Vector3.zero,
                            (controlID, positione, rotation, size, eventType) =>
                        {
                            if (GUIUtility.hotControl > 0 && controlID == GUIUtility.hotControl)
                            {
                                ArchimatixEngine.selectedFreeCurve = gener;
                            }
                            Handles.CubeHandleCap(controlID, positione, rotation, size, eventType);
                        });
                                                #else
                        pos = Handles.FreeMoveHandle(
                            pos,
                            Quaternion.identity,
                            .06f * HandleUtility.GetHandleSize(pos),
                            Vector3.zero,
                            (controlID, positione, rotation, size) =>
                        {
                            if (GUIUtility.hotControl > 0 && controlID == GUIUtility.hotControl)
                            {
                                ArchimatixEngine.selectedFreeCurve = gener;
                            }
                            Handles.CubeCap(controlID, positione, rotation, size);
                        });
                                                #endif

                        if (EditorGUI.EndChangeCheck())
                        {
                            // add point to spline at i using pos.x, pos.y
                            Undo.RegisterCompleteObjectUndo(parametricObject.model, "New Midpoint");

                            //Debug.Log(pos);
                            //Debug.Log(ArchimatixEngine.isPseudoDraggingSelectedPoint + " ::: " + (i));

                            //if (ArchimatixEngine.isPseudoDraggingSelectedPoint != (i+1))
                            if (ArchimatixEngine.isPseudoDraggingSelectedPoint == -1)
                            {
                                //Debug.Log("CREATE!!!!");
                                newCurvePoint = new CurvePoint(pos.x, pos.y);

                                newCurvePointIndex = i + 1;

                                parametricObject.curve.Insert(newCurvePointIndex, newCurvePoint);
                                ArchimatixEngine.isPseudoDraggingSelectedPoint = newCurvePointIndex;
                                generator.selectedIndex = newCurvePointIndex;

                                generator.selectOnlyItem(newCurvePointIndex);
                            }

                            parametricObject.model.isAltered();
                        }
                    }
                }                 // \loop


                // BEZIER HANDLES LOOP
                for (int i = 0; i < parametricObject.curve.Count; i++)
                {
                    //Debug.Log (i + ": "+ parametricObject.curve[i].position);

                    // Control points in Curve

                    bool pointIsSelected = (generator.selectedIndices != null && generator.selectedIndices.Contains(i));



                    Vector3 pos  = new Vector3(parametricObject.curve[i].position.x, parametricObject.curve[i].position.y, 0);
                    Vector3 posA = new Vector3(parametricObject.curve[i].position.x + parametricObject.curve[i].localHandleA.x, parametricObject.curve[i].position.y + parametricObject.curve[i].localHandleA.y, 0);
                    Vector3 posB = new Vector3(parametricObject.curve[i].position.x + parametricObject.curve[i].localHandleB.x, parametricObject.curve[i].position.y + parametricObject.curve[i].localHandleB.y, 0);


                    Handles.color = (pointIsSelected) ? Color.white :  Color.magenta;



                    if (pointIsSelected)
                    {
                        Handles.color = Color.magenta;

                        if (parametricObject.curve[i].isBezierPoint())
                        {
                            Handles.color = Color.white;
                            Handles.DrawLine(pos, posA);
                            Handles.DrawLine(pos, posB);



                            EditorGUI.BeginChangeCheck();
                            posA = Handles.FreeMoveHandle(
                                posA,
                                Quaternion.identity,
                                .1f * HandleUtility.GetHandleSize(pos),
                                Vector3.zero,
                                Handles.SphereCap
                                );

                            if (EditorGUI.EndChangeCheck())
                            {
                                Undo.RegisterCompleteObjectUndo(parametricObject.model, "FreeformShapee");
                                handleHasChanged = true;

                                parametricObject.curve[i].setHandleA(new Vector2(posA.x, posA.y));



                                //parametricObject.curve[i].localHandleA = new Vector2(pos.x, pos.y) - parametricObject.curve[i].position;
                                //parametricObject.model.generate("Move FreeForm Shape Handle");
                                parametricObject.model.isAltered();
                            }



                            // HANDLE_B


                            EditorGUI.BeginChangeCheck();
                            posB = Handles.FreeMoveHandle(
                                posB,
                                Quaternion.identity,
                                .1f * HandleUtility.GetHandleSize(pos),
                                Vector3.zero,
                                Handles.SphereCap
                                );

                            if (EditorGUI.EndChangeCheck())
                            {
                                Undo.RegisterCompleteObjectUndo(parametricObject.model, "FreeformShapee");
                                handleHasChanged = true;
                                //parametricObject.curve[i].localHandleB = new Vector2(pos.x, pos.y) - parametricObject.curve[i].position;
                                parametricObject.curve[i].setHandleB(new Vector2(posB.x, posB.y));



                                //parametricObject.model.generate("Move FreeForm Shape Handle");
                                parametricObject.model.isAltered();
                            }
                        }
                    }             // selected
                }                 // \bezier handles loop



                if (handleHasChanged)
                {
                }
            }

            Handles.matrix = prevHandlesMatrix;
        }