// Reset caching void ResetRuntimeCaching(RayfireRigid scr, GameObject tmRefGo) { scr.DestroyObject(tmRefGo); runtimeCaching.stop = false; runtimeCaching.inProgress = false; scr.meshDemolition.rfShatter = null; scr.DeleteCache(); }
/// ///////////////////////////////////////////////////////// /// Caching /// ///////////////////////////////////////////////////////// // Start cache fragment meshes. Instant or runtime static void CacheRuntime(RayfireRigid scr) { // Reuse existing cache if (scr.reset.action == RFReset.PostDemolitionType.DeactivateToReset && scr.reset.mesh == RFReset.MeshResetType.ReuseFragmentMeshes) { if (scr.HasMeshes == true) { return; } } // Clear all mesh data scr.DeleteCache(); // Cache meshes if (scr.meshDemolition.runtimeCaching.type == CachingType.Disable) { CacheInstant(scr); } else { scr.CacheFrames(); } }
// SLice mesh public static void SliceMesh(RayfireRigid scr) { // Empty lists scr.DeleteCache(); scr.DeleteFragments(); // SLice RFFragment.SliceMeshes(ref scr.meshes, ref scr.pivots, ref scr.subIds, scr, scr.limitations.slicePlanes); // Remove plane info scr.limitations.slicePlanes.Clear(); // Stop if (scr.HasMeshes == false) { return; } // Get fragments scr.fragments = RFDemolitionMesh.CreateSlices(scr); // TODO check for fragments // Set demolition scr.limitations.demolished = true; // Fragments initialisation scr.InitMeshFragments(); // Event scr.demolitionEvent.InvokeLocalEvent(scr); RFDemolitionEvent.InvokeGlobalEvent(scr); // Destroy original RayfireMan.DestroyFragment(scr, scr.rootParent); }
// Create slices by mesh and pivots array public static List <RayfireRigid> CreateSlices(RayfireRigid scr) { // Fragments list List <RayfireRigid> scrArray = new List <RayfireRigid>(); // Stop if has no any meshes if (scr.meshes == null) { return(scrArray); } // Create RayFire manager if not created RayfireMan.RayFireManInit(); // Create root object and parent RFLimitations.CreateRoot(scr); // Vars int baseLayer = scr.meshDemolition.GetLayer(scr); string baseTag = scr.gameObject.tag; string baseName = scr.gameObject.name + fragmentStr; // Get original mats Material[] mats = scr.skinnedMeshRend != null ? scr.skinnedMeshRend.sharedMaterials : scr.meshRenderer.sharedMaterials; // Create fragment objects for (int i = 0; i < scr.meshes.Length; ++i) { // Get object from pool or create RayfireRigid rfScr = RayfireMan.inst == null ? RFPoolingFragment.CreateRigidInstance() : RayfireMan.inst.fragments.GetPoolObject(RayfireMan.inst.transForm); // Setup rfScr.transform.position = scr.transForm.position + scr.pivots[i]; rfScr.transform.parent = scr.rootChild; rfScr.name = baseName + i; rfScr.gameObject.tag = baseTag; rfScr.gameObject.layer = baseLayer; rfScr.meshFilter.sharedMesh = scr.meshes[i]; rfScr.rootParent = scr.rootChild; // Copy properties from parent to fragment node scr.CopyPropertiesTo(rfScr); // Copy particles RFParticles.CopyParticles(scr, rfScr); // Set collider RFPhysic.SetFragmentMeshCollider(rfScr, scr.meshes[i]); // Shadow casting if (RayfireMan.inst.advancedDemolitionProperties.sizeThreshold > 0 && RayfireMan.inst.advancedDemolitionProperties.sizeThreshold > scr.meshes[i].bounds.size.magnitude) { rfScr.meshRenderer.shadowCastingMode = ShadowCastingMode.Off; } // Turn on rfScr.gameObject.SetActive(true); // Set multymaterial RFSurface.SetMaterial(scr.subIds, mats, scr.materials, rfScr.meshRenderer, i, scr.meshes.Length); // Update depth level and amount rfScr.limitations.currentDepth = scr.limitations.currentDepth + 1; //rfScr.meshDemolition.amount = (int)(rfScr.meshDemolition.amount * rfScr.meshDemolition.depthFade); //if (rfScr.meshDemolition.amount < 2) // rfScr.meshDemolition.amount = 2; // Add in array scrArray.Add(rfScr); } // Empty lists scr.DeleteCache(); return(scrArray); }
/// ///////////////////////////////////////////////////////// /// Static /// ///////////////////////////////////////////////////////// // Check for user mistakes public static void Checks(RayfireRigid scr) { // TODO static and cluster if (scr.objectType == ObjectType.Mesh) { } // //////////////// // Sim Type // //////////////// // Static and demolishable if (scr.simulationType == SimType.Static) { if (scr.demolitionType != DemolitionType.None) { Debug.Log("RayFire Rigid: " + scr.name + " Simulation Type set to " + scr.simulationType.ToString() + " but Demolition Type is not None. Static object can not be demolished. Demolition Type set to None.", scr.gameObject); scr.demolitionType = DemolitionType.None; } } // Non static simulation but static property if (scr.simulationType != SimType.Static) { if (scr.gameObject.isStatic == true) { Debug.Log("RayFire Rigid: " + scr.name + " Simulation Type set to " + scr.simulationType.ToString() + " but object is Static. Turn off Static checkbox in Inspector.", scr.gameObject); } } // //////////////// // Object Type // //////////////// // Object can not be simulated as mesh if (scr.objectType == ObjectType.Mesh) { // Has no mesh if (scr.meshFilter == null || scr.meshFilter.sharedMesh == null) { Debug.Log("RayFire Rigid: " + scr.name + " Object Type set to " + scr.objectType.ToString() + " but object has no mesh. Object Excluded from simulation.", scr.gameObject); scr.physics.exclude = true; } // Not readable mesh if (scr.demolitionType != DemolitionType.None) { if (scr.meshFilter != null && scr.meshFilter.sharedMesh != null && scr.meshFilter.sharedMesh.isReadable == false) { Debug.Log("RayFire Rigid: " + scr.name + " Mesh is not readable. Demolition type set to None. Open Import Settings and turn On Read/Write Enabled property", scr.meshFilter.gameObject); scr.demolitionType = DemolitionType.None; scr.meshDemolition.badMesh = 10; } } } // Object can not be simulated as cluster else if (scr.objectType == ObjectType.NestedCluster || scr.objectType == ObjectType.ConnectedCluster) { if (scr.transForm.childCount == 0) { Debug.Log("RayFire Rigid: " + scr.name + " Object Type set to " + scr.objectType.ToString() + " but object has no children. Object Excluded from simulation.", scr.gameObject); scr.physics.exclude = true; } } // Object can not be simulated as mesh else if (scr.objectType == ObjectType.SkinnedMesh) { if (scr.skinnedMeshRend == null) { Debug.Log("RayFire Rigid: " + scr.name + " Object Type set to " + scr.objectType.ToString() + " but object has no SkinnedMeshRenderer. Object Excluded from simulation.", scr.gameObject); } // Excluded from sim by default scr.physics.exclude = true; } // //////////////// // Demolition Type // //////////////// // Demolition checks if (scr.demolitionType != DemolitionType.None) { // // Static // if (scr.simulationType == SimType.Static) // { // Debug.Log ("RayFire Rigid: " + scr.name + " Simulation Type set to " + scr.simulationType.ToString() + " but Demolition Type is " + scr.demolitionType.ToString() + ". Demolition Type set to None.", scr.gameObject); // scr.demolitionType = DemolitionType.None; // } // Set runtime demolition for clusters and skinned mesh if (scr.objectType == ObjectType.SkinnedMesh || scr.objectType == ObjectType.NestedCluster || scr.objectType == ObjectType.ConnectedCluster) { if (scr.demolitionType != DemolitionType.Runtime && scr.demolitionType != DemolitionType.ReferenceDemolition) { Debug.Log("RayFire Rigid: " + scr.name + " Object Type set to " + scr.objectType.ToString() + " but Demolition Type is " + scr.demolitionType.ToString() + ". Demolition Type set to Runtime.", scr.gameObject); scr.demolitionType = DemolitionType.Runtime; } } // No Shatter component for runtime demolition with Use Shatter on if (scr.meshDemolition.scrShatter == null && scr.meshDemolition.useShatter == true) { if (scr.demolitionType == DemolitionType.Runtime || scr.demolitionType == DemolitionType.AwakePrecache || scr.demolitionType == DemolitionType.AwakePrefragment) { Debug.Log("RayFire Rigid: " + scr.name + "Demolition Type is " + scr.demolitionType.ToString() + ". Has no Shatter component, but Use Shatter property is On. Use Shatter property was turned Off.", scr.gameObject); scr.meshDemolition.useShatter = false; } } } // None check if (scr.demolitionType == DemolitionType.None) { if (scr.HasMeshes == true) { Debug.Log("RayFire Rigid: " + scr.name + " Demolition Type set to None. Had manually precached meshes which were destroyed.", scr.gameObject); scr.DeleteCache(); } if (scr.HasFragments == true) { Debug.Log("RayFire Rigid: " + scr.name + " Demolition Type set to None. Had manually prefragmented objects which were destroyed.", scr.gameObject); scr.DeleteFragments(); } if (scr.HasRfMeshes == true) { Debug.Log("RayFire Rigid:" + scr.name + " Demolition Type set to None. Had manually precached serialized meshes which were destroyed.", scr.gameObject); scr.DeleteCache(); } } // Runtime check else if (scr.demolitionType == DemolitionType.Runtime) { if (scr.HasMeshes == true) { Debug.Log("RayFire Rigid: " + scr.name + " Demolition Type set to Runtime. Had manually precached meshes which were destroyed.", scr.gameObject); scr.DeleteCache(); } if (scr.HasFragments == true) { Debug.Log("RayFire Rigid: " + scr.name + " Demolition Type set to Runtime. Had manually prefragmented objects which were destroyed.", scr.gameObject); scr.DeleteFragments(); } if (scr.HasRfMeshes == true) { Debug.Log("RayFire Rigid:" + scr.name + " Demolition Type set to Runtime. Had manually precached serialized meshes which were destroyed.", scr.gameObject); scr.DeleteCache(); } // No runtime caching for rigid with shatter with tets/slices/glue if (scr.meshDemolition.useShatter == true && scr.meshDemolition.runtimeCaching.type != CachingType.Disable) { if (scr.meshDemolition.scrShatter.type == FragType.Decompose || scr.meshDemolition.scrShatter.type == FragType.Tets || scr.meshDemolition.scrShatter.type == FragType.Slices || scr.meshDemolition.scrShatter.clusters.enable == true) { Debug.Log("RayFire Rigid: " + scr.name + " Demolition Type is Runtime, Use Shatter is On. Unsupported fragments type. Runtime Caching supports only Voronoi, Splinters, Slabs and Radial fragmentation types. Runtime Caching was Disabled.", scr.gameObject); scr.meshDemolition.runtimeCaching.type = CachingType.Disable; } } } // Awake precache check else if (scr.demolitionType == DemolitionType.AwakePrecache) { if (scr.HasMeshes == true) { Debug.Log("RayFire Rigid: " + scr.name + " Demolition Type set to Awake Precache. Had manually precached Unity meshes which were overwritten.", scr.gameObject); } if (scr.HasFragments == true) { Debug.Log("RayFire Rigid: " + scr.name + " Demolition Type set to Awake Precache. Had manually prefragmented objects which were destroyed.", scr.gameObject); scr.DeleteFragments(); } if (scr.HasRfMeshes == true) { Debug.Log("RayFire Rigid:" + scr.name + " Demolition Type set to Awake Precache. Has manually precached serialized meshes.", scr.gameObject); } } // Awake prefragmented check else if (scr.demolitionType == DemolitionType.AwakePrefragment) { if (scr.HasFragments == true) { Debug.Log("RayFire Rigid: " + scr.name + " Demolition Type set to Awake Prefragment. Has manually prefragmented objects", scr.gameObject); } if (scr.HasMeshes == true) { Debug.Log("RayFire Rigid: " + scr.name + " Demolition Type set to Awake Prefragment. Has manually precached Unity meshes.", scr.gameObject); } if (scr.HasRfMeshes == true) { Debug.Log("RayFire Rigid:" + scr.name + " Demolition Type set to Awake Prefragment. Has manually precached serialized meshes.", scr.gameObject); } } // TODO Tag and Layer check }