static void UndoRedoPerformed()
        {
            // material preview when dragging in scene-view is done by applying then undoing changes. we don't want to
            // rebuild the mesh every single frame when dragging.
            if (SceneDragAndDropListener.isDragging)
            {
                return;
            }

            // Synchronize just checks that the mesh is not null, and UV2 is still valid. This should be very cheap except
            // for the FindObjectsOfType call.
            foreach (var mesh in Object.FindObjectsOfType <ProBuilderMesh>())
            {
                EditorUtility.SynchronizeWithMeshFilter(mesh);
                mesh.InvalidateCaches();
            }

            foreach (var mesh in InternalUtility.GetComponents <ProBuilderMesh>(Selection.transforms))
            {
                mesh.InvalidateCaches();
                mesh.Rebuild();
                mesh.Optimize();
            }

            ProBuilderEditor.Refresh();
            SceneView.RepaintAll();
        }
示例#2
0
        bool HasFrameBounds()
        {
            if (m_Mesh == null)
            {
                m_Mesh = (ProBuilderMesh)target;
            }

            return(ProBuilderEditor.instance != null &&
                   InternalUtility.GetComponents <ProBuilderMesh>(Selection.transforms).Sum(x => x.selectedIndexesInternal.Length) > 0);
        }
示例#3
0
 static void SetIsTrigger(bool val, GameObject target)
 {
     Collider[] colliders = InternalUtility.GetComponents <Collider>(target);
     foreach (Collider col in colliders)
     {
         if (val && col is MeshCollider)
         {
             ((MeshCollider)col).convex = true;
         }
         col.isTrigger = val;
     }
 }
        Bounds OnGetFrameBounds()
        {
            if (!ProBuilderEditor.selectMode.IsMeshElementMode())
            {
                return(m_MeshRenderer != null ? m_MeshRenderer.bounds : default(Bounds));
            }

            if (onGetFrameBoundsEvent != null)
            {
                onGetFrameBoundsEvent();
            }

            Vector3 min = Vector3.zero, max = Vector3.zero;
            bool    init = false;

            foreach (ProBuilderMesh mesh in InternalUtility.GetComponents <ProBuilderMesh>(Selection.transforms))
            {
                int[] tris = mesh.selectedIndexesInternal;

                if (tris == null || tris.Length < 1)
                {
                    continue;
                }

                Vector3[] verts = mesh.positionsInternal;
                var       trs   = mesh.transform;

                if (!init)
                {
                    init = true;
                    min  = trs.TransformPoint(verts[tris[0]]);
                    max  = trs.TransformPoint(verts[tris[0]]);
                }

                for (int i = 0, c = tris.Length; i < c; i++)
                {
                    Vector3 p = trs.TransformPoint(verts[tris[i]]);

                    min.x = Mathf.Min(p.x, min.x);
                    max.x = Mathf.Max(p.x, max.x);

                    min.y = Mathf.Min(p.y, min.y);
                    max.y = Mathf.Max(p.y, max.y);

                    min.z = Mathf.Min(p.z, min.z);
                    max.z = Mathf.Max(p.z, max.z);
                }
            }

            return(new Bounds((min + max) / 2f, max != min ? max - min : Vector3.one * .1f));
        }
        public static void MenuRemoveDegenerateTriangles()
        {
            int count = 0;

            foreach (ProBuilderMesh pb in InternalUtility.GetComponents <ProBuilderMesh>(Selection.transforms))
            {
                int removedVertexCount;

                if (!MeshValidation.EnsureMeshIsValid(pb, out removedVertexCount))
                {
                    pb.Rebuild();
                    pb.Optimize();
                    count += removedVertexCount;
                }
            }

            EditorUtility.ShowNotification("Removed " + count + " vertices \nbelonging to degenerate triangles.");
        }
示例#6
0
        public static void MenuRemoveDegenerateTriangles()
        {
            int count = 0;

            foreach (ProBuilderMesh pb in InternalUtility.GetComponents <ProBuilderMesh>(Selection.transforms))
            {
                pb.ToMesh();

                int[] rm = pb.RemoveDegenerateTriangles();
                count += rm != null ? rm.Length : 0;

                pb.ToMesh();
                pb.Refresh();
                pb.Optimize();
            }

            EditorUtility.ShowNotification("Removed " + (count / 3) + " degenerate triangles.");
        }
 public static bool VerifyStripSelection()
 {
     return(InternalUtility.GetComponents <ProBuilderMesh>(Selection.transforms).Length > 0);
 }
示例#8
0
        public static void SetFaceColors(Color col)
        {
            col = PlayerSettings.colorSpace == ColorSpace.Linear ? col.linear : col;

            ProBuilderMesh[] selection = InternalUtility.GetComponents <ProBuilderMesh>(Selection.transforms);

            UndoUtility.RecordSelection(selection, "Apply Vertex Colors");

            ProBuilderEditor editor = ProBuilderEditor.instance;

            if (editor && ProBuilderEditor.selectMode.ContainsFlag(SelectMode.Vertex | SelectMode.Edge | SelectMode.Face))
            {
                switch (ProBuilderEditor.selectMode)
                {
                case SelectMode.Face:
                case SelectMode.TextureFace:
                    foreach (ProBuilderMesh mesh in selection)
                    {
                        Color[] colors = mesh.GetColors();

                        foreach (int i in mesh.selectedIndexesInternal)
                        {
                            colors[i] = col;
                        }

                        mesh.colors = colors;
                    }
                    break;

                case SelectMode.Edge:
                case SelectMode.Vertex:
                    foreach (var mesh in selection)
                    {
                        Color[] colors = mesh.GetColors();

                        foreach (int i in mesh.GetCoincidentVertices(mesh.selectedIndexesInternal))
                        {
                            colors[i] = col;
                        }

                        mesh.colors = colors;
                    }
                    break;
                }
            }
            else
            {
                foreach (ProBuilderMesh pb in selection)
                {
                    foreach (Face face in pb.facesInternal)
                    {
                        pb.SetFaceColor(face, col);
                    }
                }
            }

            foreach (ProBuilderMesh pb in selection)
            {
                pb.ToMesh();
                pb.Refresh();
                pb.Optimize();
            }

            EditorUtility.ShowNotification("Set Vertex Colors\n" + ColorUtility.GetColorName(col));
        }
 public static void DoRebuildMeshes()
 {
     RebuildSharedIndexes(InternalUtility.GetComponents <ProBuilderMesh>(Selection.transforms));
 }
 static bool VertifyRebuildMeshes()
 {
     return(InternalUtility.GetComponents <ProBuilderMesh>(Selection.transforms).Length > 0);
 }
        public override ActionResult DoAction()
        {
            if (MeshSelection.selectedObjectCount < 1)
            {
                return(ActionResult.NoSelection);
            }

            UndoUtility.RecordSelection("Grow Selection");

            int   grown              = 0;
            bool  angleGrow          = m_GrowSelectionWithAngle;
            bool  iterative          = m_GrowSelectionAngleIterative;
            float growSelectionAngle = m_GrowSelectionAngleValue;

            if (!angleGrow && !iterative)
            {
                iterative = true;
            }

            foreach (ProBuilderMesh pb in InternalUtility.GetComponents <ProBuilderMesh>(Selection.transforms))
            {
                int previousTriCount = pb.selectedVertexCount;

                switch (ProBuilderEditor.selectMode)
                {
                case SelectMode.Vertex:
                    pb.SetSelectedEdges(ElementSelection.GetConnectedEdges(pb, pb.selectedIndexesInternal));
                    break;

                case SelectMode.Edge:
                    pb.SetSelectedEdges(ElementSelection.GetConnectedEdges(pb, pb.selectedIndexesInternal));
                    break;

                case SelectMode.TextureFace:
                case SelectMode.Face:

                    Face[] selectedFaces = pb.GetSelectedFaces();

                    HashSet <Face> sel;

                    if (iterative)
                    {
                        sel = ElementSelection.GrowSelection(pb, selectedFaces, angleGrow ? growSelectionAngle : -1f);
                        sel.UnionWith(selectedFaces);
                    }
                    else
                    {
                        sel = ElementSelection.FloodSelection(pb, selectedFaces, angleGrow ? growSelectionAngle : -1f);
                    }

                    pb.SetSelectedFaces(sel.ToArray());

                    break;
                }

                grown += pb.selectedVertexCount - previousTriCount;
            }

            ProBuilderEditor.Refresh();
            SceneView.RepaintAll();

            if (grown > 0)
            {
                return(new ActionResult(ActionResult.Status.Success, "Grow Selection"));
            }

            return(new ActionResult(ActionResult.Status.Failure, "Nothing to Grow"));
        }