示例#1
0
        // Copy from
        public void CopyFrom(RFDemolitionMesh demolition)
        {
            amount      = demolition.amount;
            variation   = demolition.variation;
            depthFade   = demolition.depthFade;
            seed        = demolition.seed;
            contactBias = demolition.contactBias;
            useShatter  = false;

            // TODO input mesh for fragments ?? turn off for now
            meshInput = demolition.meshInput;
            meshInput = MeshInputType.AtDemolition;

            properties.CopyFrom(demolition.properties);
            runtimeCaching = new RFRuntimeCaching();

            Reset();

            shatterMode        = 1;
            innerSubId         = 0;
            compressPrefab     = true;
            cacheRotationStart = Quaternion.identity;

            mesh      = null;
            rfShatter = null;
        }
示例#2
0
        // Cache for rigid
        public static void CacheMeshesMult(Transform tmSaved, ref List <Mesh> meshesList, ref List <Vector3> pivotsList, ref List <RFDictionary> subList, RayfireRigid scrRigid, List <int> batchAmount, int batchInd)
        {
            // Get list of meshes to calc
            List <int> markedElements = RFRuntimeCaching.GetMarkedElements(batchInd, batchAmount);

            // Local iteration data lists
            Mesh[]    meshesLocal = new Mesh[batchAmount.Count];
            Vector3[] pivotsLocal = new Vector3[batchAmount.Count];
            List <Dictionary <int, int> > origSubMeshIds = new List <Dictionary <int, int> >();

            // Compute
            bool state = scrRigid.meshDemolition.rfShatter.SimpleCompute(
                tmSaved,
                ref meshesLocal,
                ref pivotsLocal,
                scrRigid.meshDemolition.mesh,
                scrRigid.meshDemolition.innerSubId,
                ref origSubMeshIds,
                markedElements,
                batchInd == 0);

            // Set names
            if (state == false || meshesLocal == null || meshesLocal.Length == 0)
            {
                return;
            }

            // Set names
            for (int i = 0; i < meshesLocal.Length; i++)
            {
                meshesLocal[i].RecalculateTangents();
                meshesLocal[i].name = scrRigid.name + "_" + markedElements[i].ToString();
            }

            // Add data to main lists
            for (int i = 0; i < origSubMeshIds.Count; i++)
            {
                subList.Add(new RFDictionary(origSubMeshIds[i]));
            }
            meshesList.AddRange(meshesLocal);
            pivotsList.AddRange(pivotsLocal);
        }
示例#3
0
        /// /////////////////////////////////////////////////////////
        /// Constructor
        /// /////////////////////////////////////////////////////////

        // Constructor
        public RFDemolitionMesh()
        {
            amount      = 15;
            variation   = 0;
            depthFade   = 0.5f;
            contactBias = 0f;
            seed        = 1;
            useShatter  = false;

            meshInput      = MeshInputType.AtDemolition;
            properties     = new RFFragmentProperties();
            runtimeCaching = new RFRuntimeCaching();

            Reset();

            shatterMode        = 1;
            innerSubId         = 0;
            compressPrefab     = true;
            cacheRotationStart = Quaternion.identity;

            mesh      = null;
            rfShatter = null;
        }
示例#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;
        }