예제 #1
0
        // Instant caching into meshes
        public static void CacheInstant(RayfireRigid scr)
        {
            // Timestamp
            float t1 = Time.realtimeSinceStartup;

            // Input mesh, setup
            if (RFFragment.InputMesh(scr) == false)
            {
                return;
            }

            // Timestamp
            float t2 = Time.realtimeSinceStartup;

            //Debug.Log (scr.gameObject.name +  " Input time: " + (t2 - t1));

            // Create fragments
            RFFragment.CacheMeshesInst(ref scr.meshes, ref scr.pivots, ref scr.subIds, scr);

            // Timestamp
            float t3 = Time.realtimeSinceStartup;

            //Debug.Log (t2 - t1);
            //Debug.Log (scr.gameObject.name +  " Cache time: " + (t3 - t1));
        }
예제 #2
0
        // Instant caching into meshes
        public static void CacheInstant(RayfireRigid scr)
        {
            // Input mesh, setup
            if (RFFragment.InputMesh(scr) == false)
            {
                return;
            }

            // Create fragments
            RFFragment.CacheMeshesInst(ref scr.meshes, ref scr.pivots, ref scr.subIds, scr);
        }
예제 #3
0
        /// /////////////////////////////////////////////////////////
        /// Demolition types
        /// /////////////////////////////////////////////////////////

        // Awake Mesh input // TODO add checks in case has input mesh but mesh input is off
        public void MeshInput()
        {
            if (objectType == ObjectType.Mesh)
            {
                // Set components for mesh / skinned mesh / clusters
                SetComponentsBasic();

                // Timestamp
                //float t1 = Time.realtimeSinceStartup;

                // Input
                RFFragment.InputMesh(this);

                // Timestamp
                //float t2 = Time.realtimeSinceStartup;

                //Debug.Log (gameObject.name +  " Input time: " + (t2 - t1));
            }
        }
예제 #4
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;
        }