void TriangleSelectionToolbox() { if (plotter.CurrentAction != HairyPlotterActions.VertexUvEdit) { if (plotter.TriangleSelectionCount > 0) { EditorGUILayout.LabelField("Triangle Selection: " + plotter.TriangleSelectionCount, EditorStyles.boldLabel); EditorGUILayout.BeginHorizontal(); GUI.color = TriangleSelectionToolbarColor; if (GUILayout.Button("Create Unique Vertices", EditorStyles.miniButton)) { HashSet <HairyPlotterTriangle> selectedTriangles = new HashSet <HairyPlotterTriangle>(plotter.SelectedTriangles); HashSet <HairyPlotterVertex> uniqueVertices = new HashSet <HairyPlotterVertex>(selectedTriangles.SelectMany(x => x.VertexObjects).Distinct()); // Iterate over each vertex that the selectedTriangles use foreach (HairyPlotterVertex vertex in uniqueVertices) { // Iterate over each triangle the vertex blongs to foreach (HairyPlotterTriangle vertexTriangle in vertex.TriangleSet) { // If the triangle is NOT in the selected triangles if (!selectedTriangles.Contains(vertexTriangle)) { // Create a clone of the vertex HairyPlotterVertex vertexClone = plotter.CreateVertex(vertex.Position, vertex.Uv); // And step through each selected triangle, and switch out the shared vertex for the clone foreach (HairyPlotterTriangle selectedTriangle in selectedTriangles) { selectedTriangle.SwitchVertices(vertex, vertexClone); } // We're done break; } } } plotter.Dirty = true; plotter.UpdateVertexIndexes(); } if (GUILayout.Button("Select Vertices", EditorStyles.miniButton)) { HashSet <HairyPlotterTriangle> selectedTriangles = new HashSet <HairyPlotterTriangle>(plotter.SelectedTriangles); HashSet <HairyPlotterVertex> selectedTrianglesVertices = new HashSet <HairyPlotterVertex>(selectedTriangles.SelectMany(x => x.VertexObjects)); plotter.ClearVertexSelection(); foreach (HairyPlotterVertex vertex in selectedTrianglesVertices) { plotter.AddSelection(vertex); } // Clear triangle selection plotter.ClearTriangleSelection(); } if (GUILayout.Button("Clear Selection", EditorStyles.miniButton)) { plotter.ClearTriangleSelection(); } if (plotter.CurrentAction == HairyPlotterActions.TriangleDelete) { if (GUILayout.Button("Yes!", EditorStyles.miniButton)) { foreach (HairyPlotterTriangle triangle in plotter.SelectedTriangles) { plotter.DestroyTriangle(triangle); } plotter.CurrentAction = HairyPlotterActions.None; } if (GUILayout.Button("No!", EditorStyles.miniButton)) { plotter.CurrentAction = HairyPlotterActions.None; } } else { if (GUILayout.Button("Delete Selected", EditorStyles.miniButton)) { plotter.CurrentAction = HairyPlotterActions.TriangleDelete; } } GUI.color = Color.white; EditorGUILayout.EndHorizontal(); } } }