public override void OnInitialize() { if (!generatedDataContainer) { generatedDataContainer = CSGGeneratedComponentManager.FindContainerGameObject(this); if (generatedDataContainer != null) { generatedDataTransform = generatedDataContainer.transform; } } colliderSettings = new CSGGeneratedColliderSettings(); colliderSettings.Reset(); renderSettings = new CSGGeneratedRenderSettings(); renderSettings.Reset(); #if UNITY_EDITOR UnityEditor.UnwrapParam defaults; UnityEditor.UnwrapParam.SetDefaults(out defaults); uvGenerationSettings.angleError = defaults.angleError; uvGenerationSettings.areaError = defaults.areaError; uvGenerationSettings.hardAngle = defaults.hardAngle; uvGenerationSettings.packMarginPixels = defaults.packMargin * 256; #endif initialized = true; }
public static void UpdateModels() { // Update the tree meshes if (!CSGManager.Flush()) { CSGGeneratedComponentManager.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(); } } }
protected override void OnCleanup() { CSGGeneratedComponentManager.RemoveContainerFlags(this); }