Example #1
0
        private void HandleSelection(LatticeGridComponent lattice, Transform transform)
        {
            if (selectedInfo.HasSelection)
            {
                using (var cc = new EditorGUI.ChangeCheckScope())
                {
                    var handlePos = CalcSelectionCenter(lattice);
                    handlePos = transform.TransformPoint(handlePos);
                    var newV = Handles.PositionHandle(handlePos, transform.rotation);

                    if (cc.changed)
                    {
                        Undo.RecordObject(lattice, "Lattice Vertex Change");
                        Vector3 delta = newV - handlePos;
                        delta = transform.worldToLocalMatrix * delta;

                        var indices = selectedInfo.SelectedPointsIndices;
                        foreach (int i in indices)
                        {
                            lattice.Grid.Vertices[i] += delta;
                        }

                        if (liveEvaluation)
                        {
                            if (lattice.HasSnapshot)
                            {
                                lattice.UpdateTargetSnapshotVertices();
                            }
                        }
                    }
                }
            }
        }
Example #2
0
        private void DrawScreenGUI(LatticeGridComponent lattice)
        {
            Handles.BeginGUI();
            int menuWidth = menuOpen ? 140 : 80;

            GUILayout.BeginArea(new Rect(5, 5, menuWidth, 160));
            GUILayout.BeginVertical();

            if (GUILayout.Button(menuOpen ? "<<<" : "menu >>>", GUILayout.Height(20)))
            {
                menuOpen = !menuOpen;
            }

            if (menuOpen)
            {
                if (GUILayout.Button(drawOpaque ? "transparent": "opaque"))
                {
                    drawOpaque   = !drawOpaque;
                    needsRepaint = true;
                }
                if (GUILayout.Button(allowSelection ? "disallow selection" : "allow selection"))
                {
                    allowSelection = !allowSelection;
                    selectedInfo.ClearSelection();
                    needsRepaint = true;
                }
                if (GUILayout.Button("reset grid"))
                {
                    lattice.ResetVerticesPosition();
                    needsRepaint = true;
                }
                GUI.enabled = lattice.target != null;
                string label = GUI.enabled ? "take snapshot" : "take snapshot (no target)";
                if (GUILayout.Button(label))
                {
                    lattice.TakeTargetSnapshot();
                }

                GUILayout.Space(10);

                GUI.enabled = true;
                label       = "live evaluation:" + (liveEvaluation ? "on" : "off");
                if (GUILayout.Button(label))
                {
                    liveEvaluation = !liveEvaluation;
                }

                GUI.enabled = true;
                label       = "evaluate vertices";
                if (!lattice.HasSnapshot)
                {
                    GUI.enabled = false;
                    label       = "evaluate vertices (no snapshot)";
                }
                if (GUILayout.Button(label))
                {
                    lattice.UpdateTargetSnapshotVertices();
                }
                GUI.enabled = true;
            }

            GUILayout.EndVertical();
            GUILayout.EndArea();
            Handles.EndGUI();
        }