示例#1
0
 // Reset caching
 void ResetRuntimeCaching(RayfireRigid scr, GameObject tmRefGo)
 {
     scr.DestroyObject(tmRefGo);
     runtimeCaching.stop          = false;
     runtimeCaching.inProgress    = false;
     scr.meshDemolition.rfShatter = null;
     scr.DeleteCache();
 }
示例#2
0
        // Cor to fragment mesh over several frames
        public IEnumerator RuntimeCachingCor(RayfireRigid scr)
        {
            // Object should be demolished when cached all meshes but not during caching
            bool demolitionShouldLocal = scr.limitations.demolitionShould == true;

            scr.limitations.demolitionShould = false;

            // Input mesh, setup, record time
            float t1 = Time.realtimeSinceStartup;

            if (RFFragment.InputMesh(scr) == false)
            {
                yield break;
            }

            // Set list with amount of mesh for every frame
            List <int> batchAmount = runtimeCaching.type == CachingType.ByFrames
                ? RFRuntimeCaching.GetBatchByFrames(runtimeCaching.frames, totalAmount)
                : RFRuntimeCaching.GetBatchByFragments(runtimeCaching.fragments, totalAmount);

            // Caching in progress
            runtimeCaching.inProgress = true;

            // Wait next frame if input took too much time or long batch
            float t2 = Time.realtimeSinceStartup - t1;

            if (t2 > 0.025f || batchAmount.Count > 5)
            {
                yield return(null);
            }

            // Save tm for multi frame caching
            GameObject tmRefGo = RFRuntimeCaching.CreateTmRef(scr);

            // Start rotation
            cacheRotationStart = scr.transForm.rotation;

            // Iterate every frame. Calc local frame meshes
            List <Mesh>         meshesList = new List <Mesh>();
            List <Vector3>      pivotsList = new List <Vector3>();
            List <RFDictionary> subList    = new List <RFDictionary>();

            for (int i = 0; i < batchAmount.Count; i++)
            {
                // Check for stop
                if (runtimeCaching.stop == true)
                {
                    ResetRuntimeCaching(scr, tmRefGo);
                    yield break;
                }

                // Cache defined points
                RFFragment.CacheMeshesMult(tmRefGo.transform, ref meshesList, ref pivotsList, ref subList, scr, batchAmount, i);
                // TODO create fragments for current batch
                // TODO record time and decrease batches amount if less 30 fps
                yield return(null);
            }

            // Set to main data vars
            scr.meshes = meshesList.ToArray();
            scr.pivots = pivotsList.ToArray();
            scr.subIds = subList;

            // Clear
            scr.DestroyObject(tmRefGo);
            scr.meshDemolition.scrShatter = null;

            // Set demolition ready state
            if (runtimeCaching.skipFirstDemolition == false && demolitionShouldLocal == true)
            {
                scr.limitations.demolitionShould = true;
            }

            // Reset damage
            if (runtimeCaching.skipFirstDemolition == true && demolitionShouldLocal == true)
            {
                scr.damage.Reset();
            }

            // Caching finished
            runtimeCaching.inProgress = false;
            runtimeCaching.wasUsed    = true;
        }