// Fragments initialisation public void InitMeshFragments() { // No fragments if (HasFragments == false) { return; } // Set velocity RFPhysic.SetFragmentsVelocity(this); // Sum total new fragments amount RayfireMan.inst.advancedDemolitionProperties.currentAmount += fragments.Count; // Set ancestor and descendants if (reset.mesh == RFReset.MeshResetType.ReuseInputMesh) { RFLimitations.SetAncestor(this); RFLimitations.SetDescendants(this); } // Fading. move to fragment if (fading.onDemolition == true) { fading.DemolitionFade(fragments); } }
// Awake ops void AwakeMethods() { // Create RayFire manager if not created RayfireMan.RayFireManInit(); // Set components for mesh / skinned mesh / clusters SetComponentsBasic(); // Set particles RFParticles.SetParticleComponents(this); // Init mesh root. if (SetRootMesh() == true) { return; } // Check for user mistakes RFLimitations.Checks(this); // Set components for mesh / skinned mesh / clusters SetComponentsPhysics(); // Initialization Mesh input if (meshDemolition.meshInput == RFDemolitionMesh.MeshInputType.AtInitialization) { MeshInput(); } // Precache meshes at awake AwakePrecache(); // Prefragment object at awake AwakePrefragment(); }
// Fragments initialisation void InitFragments() { // No fragments if (HasFragments == false) { return; } // Set velocity RFPhysic.SetFragmentsVelocity(this); // TODO set current frame for cluster demol types // Sum total new fragments amount RayfireMan.inst.advancedDemolitionProperties.currentAmount += fragments.Count; // Set ancestor RFLimitations.SetAncestor(this); RFLimitations.SetDescendants(this); // Fading. move to fragment if (fading.onDemolition == true) { fading.DemolitionFade(fragments); } }
// Copy from public void CopyFrom(RFLimitations limitations) { solidity = limitations.solidity; depth = limitations.depth; time = limitations.time; size = limitations.size; sliceByBlade = limitations.sliceByBlade; // Do not copy currentDepth. Set in other place Reset(); }
// Reset rigid data public void Default() { // Reset limitations.Reset(); meshDemolition.Reset(); clusterDemolition.Reset(); limitations.birthTime = Time.time + Random.Range(0f, 0.3f); // Birth position for activation check physics.initScale = transForm.localScale; physics.initPosition = transForm.position; physics.initRotation = transForm.rotation; // Set bound and size RFLimitations.SetBound(this); }
// 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); }
// Create fragments by mesh and pivots array public static List <RayfireRigid> CreateFragments(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; // Save original rotation // Quaternion originalRotation = rootChild.transform.rotation; // Set rotation to precache rotation if (scr.demolitionType == DemolitionType.AwakePrecache) { scr.rootChild.transform.rotation = scr.cacheRotation; } // 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 < 3) { rfScr.meshDemolition.amount = 3; } // Add in array scrArray.Add(rfScr); // Debug.Log (rfScr.rootParent); } // Fix transform for precached fragments if (scr.demolitionType == DemolitionType.AwakePrecache) { scr.rootChild.rotation = scr.transForm.rotation; } // Fix runtime caching rotation difference. Get rotation difference and add to root if (scr.demolitionType == DemolitionType.Runtime && scr.meshDemolition.runtimeCaching.type != CachingType.Disable) { Quaternion cacheRotationDif = scr.transForm.rotation * Quaternion.Inverse(scr.meshDemolition.cacheRotationStart); scr.rootChild.rotation = cacheRotationDif * scr.rootChild.rotation; } return(scrArray); }
// Create slices by mesh and pivots array List <RayfireRigid> CreateSlices() { // Create root object RFLimitations.CreateRoot(this); // Clear array for new fragments List <RayfireRigid> scrArray = new List <RayfireRigid>(); // Vars int baseLayer = meshDemolition.GetLayer(this); string baseTag = gameObject.tag; string baseName = gameObject.name + "_sl_"; // Create fragment objects for (int i = 0; i < meshes.Length; ++i) { // Get object from pool or create RayfireRigid rfScr = RayfireMan.inst.GetPoolObject(); // Setup rfScr.transform.position = transForm.position + pivots[i]; rfScr.transform.parent = rootChild; rfScr.name = baseName + i; rfScr.gameObject.tag = baseTag; rfScr.gameObject.layer = baseLayer; rfScr.meshFilter.sharedMesh = meshes[i]; rfScr.meshFilter.sharedMesh.name = baseName + i; rfScr.rootParent = rootChild; // Copy properties from parent to fragment node CopyPropertiesTo(rfScr); // Copy particles RFParticles.CopyParticles(this, rfScr); // Shadow casting if (RayfireMan.inst.advancedDemolitionProperties.sizeThreshold > 0 && RayfireMan.inst.advancedDemolitionProperties.sizeThreshold > meshes[i].bounds.size.magnitude) { rfScr.meshRenderer.shadowCastingMode = ShadowCastingMode.Off; } // Turn on rfScr.gameObject.SetActive(true); // Set multymaterial RFSurface.SetMaterial(subIds, meshRenderer.sharedMaterials, materials, rfScr.meshRenderer, i, meshes.Length); // Inherit same current depth level rfScr.limitations.currentDepth = limitations.currentDepth + 1; // Set collider mesh MeshCollider mc = rfScr.physics.meshCollider as MeshCollider; if (mc != null) { mc.sharedMesh = meshes[i]; mc.name = meshes[i].name; } // Add in array scrArray.Add(rfScr); } // Empty lists DeleteCache(); return(scrArray); }