예제 #1
0
        /// <summary>
        /// Is this edge collinear with the other edge? Two edges are considered collinear if they
        /// lie on a single straight line through space (gaps between them make no difference).
        /// </summary>
        /// <param name="other">Other edge that may be collinear.</param>
        /// <returns><c>true</c> if both edges are collinear; otherwise, <c>false</c>.</returns>
        /// <exception cref="System.ArgumentNullException">
        /// Thrown when <paramref name="other"/> is null.
        /// </exception>
        public bool Collinear(Edge other)
        {
#if SABRE_CSG_DEBUG
            if (other == null)
            {
                throw new ArgumentNullException("other");
            }
#endif
            return(EdgeUtility.EdgeMatches(this, other));
        }
예제 #2
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
                        });
                    }
                }
            }
        }