Beispiel #1
0
        static GeneratedMeshContents GeneratedMeshAndValidate(CSGTree tree, MeshQuery[] meshTypes, bool expectEmpty = false)
        {
            GeneratedMeshContents generatedMesh = null;

            GeneratedMeshDescription[] meshDescriptions = null;
            bool treeWasDirtyBefore = false;
            bool treeIsDirtyAfter   = true;

            tree.SetDirty();
            bool haveChanges = CSGManager.Flush(); // Note: optional

            if (haveChanges)
            {
                treeWasDirtyBefore = tree.Dirty; // Note: optional
                if (treeWasDirtyBefore)
                {
                    meshDescriptions = tree.GetMeshDescriptions(meshTypes);
                    if (meshDescriptions != null)
                    {
                        var meshDescription = meshDescriptions[0];
                        generatedMesh = tree.GetGeneratedMesh(meshDescription);
                    }
                    treeIsDirtyAfter = tree.Dirty;
                }
            }

            Assert.IsTrue(haveChanges);
            Assert.IsTrue(treeWasDirtyBefore);
            Assert.IsFalse(treeIsDirtyAfter);
            if (expectEmpty)
            {
                Assert.Null(meshDescriptions);
                Assert.Null(generatedMesh);
            }
            else
            {
                Assert.NotNull(meshDescriptions);
                Assert.NotNull(generatedMesh);
                Assert.AreEqual(meshDescriptions[0].meshQuery, meshTypes[0]);
                Assert.AreEqual(simpleMeshTypes.Length, meshDescriptions.Length);
                Assert.IsTrue(generatedMesh.description.vertexCount > 0 &&
                              generatedMesh.description.indexCount > 0);
            }
            return(generatedMesh);
        }
        public static void UpdateModels()
        {
            // Update the tree meshes
            Profiler.BeginSample("Flush");
            try
            {
                if (!CSGManager.Flush(s_FinishMeshUpdates))
                {
                    ChiselGeneratedComponentManager.DelayedUVGeneration();
                    return; // Nothing to update ..
                }
            }
            finally
            {
                Profiler.EndSample();
            }

            {
                Profiler.BeginSample("PostUpdateModels");
                PostUpdateModels?.Invoke();
                Profiler.EndSample();
            }
        }
Beispiel #3
0
        public static void UpdateModels()
        {
            // Update the tree meshes
            if (!CSGManager.Flush())
            {
                ChiselGeneratedComponentManager.DelayedUVGeneration();
                if (sharedUnityMeshes.FindAllUnusedUnityMeshes())
                {
                    sharedUnityMeshes.DestroyNonRecycledUnusedUnityMeshes();
                }
                return; // Nothing to update ..
            }

            for (int m = 0; m < registeredModels.Count; m++)
            {
                var model = registeredModels[m];
                if (!model)
                {
                    continue;
                }

                var tree = model.Node;

                // See if the tree has been modified
                if (!tree.Dirty)
                {
                    continue;
                }

                try
                {
                    if (PreUpdateModel != null)
                    {
                        PreUpdateModel(model);
                    }
                }
                catch (Exception ex) // if there's a bug in user-code we don't want to end up in a bad state
                {
                    Debug.LogException(ex);
                }

                UpdateModelMeshDescriptions(model);

                // Re-use existing UnityEngine.Mesh if they exist
                sharedUnityMeshes.ReuseExistingMeshes(model);

                updateList.Add(model);
            }

            bool modifications = false;

            try
            {
                // Find all meshes whose refCounts are 0
                sharedUnityMeshes.FindAllUnusedUnityMeshes();

                // Separate loop so we can re-use garbage collected UnityEngine.Meshes to avoid allocation costs

                for (int m = 0; m < updateList.Count; m++)
                {
                    var model = updateList[m];

                    // Generate new UnityEngine.Mesh instances and fill them with data from the CSG algorithm (if necessary)
                    //	note: reuses garbage collected meshes when possible
                    sharedUnityMeshes.CreateNewMeshes(model);

                    // Generate (or re-use) components and set them up properly
                    componentGenerator.Rebuild(model);
                }
            }
            finally
            {
                for (int m = 0; m < updateList.Count; m++)
                {
                    var model = updateList[m];
                    try
                    {
                        modifications = true;
                        if (PostUpdateModel != null)
                        {
                            PostUpdateModel(model);
                        }
                    }
                    catch (Exception ex) // if there's a bug in user-code we don't want to end up in a bad state
                    {
                        Debug.LogException(ex);
                    }
                }
                updateList.Clear();
            }

            // Destroy all meshes whose refCounts are 0
            sharedUnityMeshes.DestroyNonRecycledUnusedUnityMeshes();

            if (modifications)
            {
                if (PostUpdateModels != null)
                {
                    PostUpdateModels();
                }
            }
        }
        public static void UpdateModels()
        {
            // Update the tree meshes
            Profiler.BeginSample("Flush");
            try
            {
                if (!CSGManager.Flush())
                {
                    ChiselGeneratedComponentManager.DelayedUVGeneration();
                    return; // Nothing to update ..
                }
            }
            finally
            {
                Profiler.EndSample();
            }

#if UNITY_EDITOR
            ChiselGeneratedComponentManager.OnVisibilityChanged();
#endif


            for (int m = 0; m < registeredModels.Count; m++)
            {
                var model = registeredModels[m];
                if (!model)
                {
                    continue;
                }

                var tree = model.Node;

                // See if the tree has been modified
                if (!tree.Dirty)
                {
                    continue;
                }

                Profiler.BeginSample("UpdateModelMeshDescriptions");
                UpdateModelMeshDescriptions(model);
                Profiler.EndSample();

                updateList.Add(model);
            }

            bool modifications = false;
            try
            {
                for (int m = 0; m < updateList.Count; m++)
                {
                    var model = updateList[m];

                    // Generate (or re-use) components and set them up properly
                    Profiler.BeginSample("componentGenerator.Rebuild");
                    componentGenerator.Rebuild(model);
                    Profiler.EndSample();
                }
            }
            finally
            {
                for (int m = 0; m < updateList.Count; m++)
                {
                    var model = updateList[m];
                    try
                    {
                        modifications = true;
                        Profiler.BeginSample("PostUpdateModel");
                        PostUpdateModel?.Invoke(model);
                        Profiler.EndSample();
                    }
                    catch (Exception ex) // if there's a bug in user-code we don't want to end up in a bad state
                    {
                        Debug.LogException(ex);
                    }
                }
                updateList.Clear();
            }

            if (modifications)
            {
                Profiler.BeginSample("PostUpdateModels");
                PostUpdateModels?.Invoke();
                Profiler.EndSample();
            }
        }