Example #1
0
        private void GuiLayoutBeginImporterSection(Texture2D icon, string title, string author)
        {
            GUIStyle style = new GUIStyle();

            style.normal.background = SabreCSGResources.ImporterBackgroundTexture;

            EditorGUILayout.BeginVertical(style);
            EditorGUILayout.BeginHorizontal();

            GUILayout.Label(icon);

            EditorGUILayout.BeginVertical();

            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            GUILayout.Label(title, SabreGUILayout.GetTitleStyle());
            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            GUILayout.Label("Author: " + author);
            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();

            EditorGUILayout.EndVertical();

            EditorGUILayout.EndHorizontal();
        }
Example #2
0
        void OnGUI()
        {
            if (surfaceEditor == null || csgModel == null)
            {
                // Link to face tool has been lost, so attempt to reacquire
                CSGModel[] csgModels = FindObjectsOfType <CSGModel>();

                // Build the first csg model that is currently being edited
                for (int i = 0; i < csgModels.Length; i++)
                {
                    if (csgModels[i].EditMode)
                    {
                        csgModel      = csgModels[i];
                        surfaceEditor = csgModels[i].GetTool(MainMode.Face) as SurfaceEditor;
                        break;
                    }
                }

                // If it's still null
                if (surfaceEditor == null || csgModel == null)
                {
                    GUILayout.Label("No active CSG Model");
                    return;
                }
            }

            GUILayout.Label("Set Vertex Colors", SabreGUILayout.GetTitleStyle());

            Color sourceColor = surfaceEditor.GetColor();

            Color newColor = EditorGUILayout.ColorField(sourceColor);

            if (newColor != sourceColor)
            {
                surfaceEditor.SetSelectionColor(newColor);
            }

            // Preset color buttons
            GUILayout.BeginHorizontal();
            for (int i = 0; i < PRESET_COLORS.Length; i++)
            {
                if (SabreGUILayout.ColorButton(PRESET_COLORS[i]))
                {
                    surfaceEditor.SetSelectionColor(PRESET_COLORS[i]);
                }
            }
            GUILayout.EndHorizontal();
        }
        public override void OnInspectorGUI()
        {
            GUILayout.Label("SabreCSG Key Mappings", SabreGUILayout.GetTitleStyle());

            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("Uses Unity shortcut format");
            GUIStyle style = new GUIStyle(GUI.skin.label);

            style.normal.textColor = Color.blue;
            style.fontStyle        = FontStyle.Bold;
            if (GUILayout.Button("See format docs", style))
            {
                Application.OpenURL("http://unity3d.com/support/documentation/ScriptReference/MenuItem.html");
            }
            EditorGUILayout.EndHorizontal();

            DrawDefaultInspector();
        }
Example #4
0
 void OnGUI()
 {
     GUILayout.Label("SabreCSG Preferences", SabreGUILayout.GetTitleStyle(20));
     PreferencesGUI();
 }
Example #5
0
        void OnToolbarGUI(int windowID)
        {
            GUILayout.Label("Vertex", SabreGUILayout.GetTitleStyle());

            // Button should only be enabled if there are any vertices selected
            GUI.enabled = selectedVertices.Count > 0;

            if (GUILayout.Button("Connect", EditorStyles.miniButton))
            {
                if (selectedVertices != null)
                {
                    // Cache selection
                    Dictionary <Brush, List <Vertex> > refinedSelections = new Dictionary <Brush, List <Vertex> >();

                    foreach (PrimitiveBrush brush in targetBrushes)
                    {
                        refinedSelections.Add(brush, SelectedVerticesOfBrush(brush));
                    }

                    ClearSelection();

                    foreach (PrimitiveBrush brush in targetBrushes)
                    {
                        Undo.RecordObject(brush.transform, "Connect Vertices");
                        Undo.RecordObject(brush, "Connect Vertices");

                        List <Edge> newEdges;

//						Polygon[] newPolygons = VertexUtility.ConnectVertices(brush.GetPolygons(), refinedSelections[brush], out newEdge);
                        Polygon[] newPolygons = VertexUtility.ConnectVertices(brush.GetPolygons(), refinedSelections[brush], out newEdges);

                        if (newPolygons != null)
                        {
                            brush.SetPolygons(newPolygons);

                            for (int i = 0; i < newEdges.Count; i++)
                            {
                                SelectEdges(brush, newPolygons, newEdges[i]);
                            }
                        }
                    }
                }
            }

            if (GUILayout.Button("Weld Selection To Mid-Point", EditorStyles.miniButton))
            {
                if (selectedVertices != null)
                {
                    Dictionary <Brush, List <Vertex> > refinedSelections = new Dictionary <Brush, List <Vertex> >();

                    foreach (PrimitiveBrush brush in targetBrushes)
                    {
                        refinedSelections.Add(brush, SelectedVerticesOfBrush(brush));
                    }

                    ClearSelection();

                    foreach (PrimitiveBrush brush in targetBrushes)
                    {
                        Undo.RecordObject(brush.transform, "Weld Vertices");
                        Undo.RecordObject(brush, "Weld Vertices");

                        Polygon[] newPolygons = VertexUtility.WeldVerticesToCenter(brush.GetPolygons(), refinedSelections[brush]);

                        if (newPolygons != null)
                        {
                            brush.SetPolygons(newPolygons);
                        }

                        SelectVertices(brush, newPolygons, refinedSelections[brush]);
                    }
                }
            }

            EditorGUILayout.BeginHorizontal();
            weldTolerance = EditorGUILayout.FloatField(weldTolerance);

            if (GUILayout.Button("Weld with Tolerance", EditorStyles.miniButton))
            {
                if (selectedVertices != null)
                {
                    Dictionary <Brush, List <Vertex> > refinedSelections = new Dictionary <Brush, List <Vertex> >();

                    foreach (PrimitiveBrush brush in targetBrushes)
                    {
                        refinedSelections.Add(brush, SelectedVerticesOfBrush(brush));
                    }

                    ClearSelection();

                    foreach (PrimitiveBrush brush in targetBrushes)
                    {
                        Undo.RecordObject(brush.transform, "Weld Vertices");
                        Undo.RecordObject(brush, "Weld Vertices");

                        Polygon[] newPolygons = VertexUtility.WeldNearbyVertices(weldTolerance, brush.GetPolygons(), refinedSelections[brush]);

                        if (newPolygons != null)
                        {
                            brush.SetPolygons(newPolygons);
                        }

                        SelectVertices(brush, newPolygons, refinedSelections[brush]);
                    }
                }
            }
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();

            if (GUILayout.Button("Global Snap", EditorStyles.miniButton))
            {
                foreach (PrimitiveBrush brush in targetBrushes)
                {
                    Undo.RecordObject(brush.transform, "Snap Vertices");
                    Undo.RecordObject(brush, "Snap Vertices");
                }

                SnapSelectedVertices(true);
            }

            if (GUILayout.Button("Local Snap", EditorStyles.miniButton))
            {
                foreach (PrimitiveBrush brush in targetBrushes)
                {
                    Undo.RecordObject(brush.transform, "Snap Vertices");
                    Undo.RecordObject(brush, "Snap Vertices");
                }

                SnapSelectedVertices(false);
            }
            EditorGUILayout.EndHorizontal();

            GUILayout.Label("Edge", SabreGUILayout.GetTitleStyle());

            GUI.enabled = selectedEdges.Count > 0;

            if (GUILayout.Button("Connect Mid-Points", EditorStyles.miniButton))
            {
                if (selectedEdges != null)
                {
                    List <Edge> selectedEdgesCopy = new List <Edge>(selectedEdges);
                    ClearSelection();
                    foreach (PrimitiveBrush brush in targetBrushes)
                    {
                        Undo.RecordObject(brush.transform, "Connect Mid-Points");
                        Undo.RecordObject(brush, "Connect Mid-Points");

                        Polygon[]   newPolygons;
                        List <Edge> newEdges;
                        if (EdgeUtility.SplitPolygonsByEdges(brush.GetPolygons(), selectedEdgesCopy, out newPolygons, out newEdges))
                        {
                            brush.SetPolygons(newPolygons);

                            for (int i = 0; i < newEdges.Count; i++)
                            {
                                SelectEdges(brush, newPolygons, newEdges[i]);
                            }
                        }
                    }
                }
            }

            if (GUILayout.Button("Split", EditorStyles.miniButton))
            {
                if (selectedEdges != null)
                {
                    List <KeyValuePair <Vertex, Brush> > newSelectedVertices = new List <KeyValuePair <Vertex, Brush> >();
                    foreach (PrimitiveBrush brush in targetBrushes)
                    {
                        Undo.RecordObject(brush.transform, "Split Edge");
                        Undo.RecordObject(brush, "Split Edge");
                        Polygon[] polygons = brush.GetPolygons();

                        for (int j = 0; j < selectedEdges.Count; j++)
                        {
                            // First check if this edge actually belongs to the brush
                            Brush parentBrush = selectedVertices[selectedEdges[j].Vertex1];

                            if (parentBrush == brush)
                            {
                                for (int i = 0; i < polygons.Length; i++)
                                {
                                    Vertex newVertex;
                                    if (EdgeUtility.SplitPolygonAtEdge(polygons[i], selectedEdges[j], out newVertex))
                                    {
                                        newSelectedVertices.Add(new KeyValuePair <Vertex, Brush>(newVertex, brush));
                                    }
                                }
                            }
                        }

                        brush.Invalidate(true);
                    }

                    ClearSelection();

                    for (int i = 0; i < newSelectedVertices.Count; i++)
                    {
                        Brush  brush  = newSelectedVertices[i].Value;
                        Vertex vertex = newSelectedVertices[i].Key;

                        SelectVertices(brush, brush.GetPolygons(), new List <Vertex>()
                        {
                            vertex
                        });
                    }
                }
            }
        }