Exemple #1
0
        /// /////////////////////////////////////////////////////////
        /// Rigid
        /// /////////////////////////////////////////////////////////

        // Prepare rigid component to cache fragment meshes
        public static bool InputMesh(RayfireRigid scr)
        {
            // Set up shatter
            if (SetRigidShatter(scr) == false)
            {
                return(false);
            }

            // Get innerSubId
            scr.meshDemolition.innerSubId = RFSurface.SetInnerSubId(scr);

            // Set fragmentation properties
            SetFragmentProperties(scr.meshDemolition.rfShatter, scr.meshDemolition.scrShatter, scr);

            return(true);
        }
Exemple #2
0
        /// /////////////////////////////////////////////////////////
        /// Slice
        /// /////////////////////////////////////////////////////////

        // Cache for slice
        public static void SliceMeshes(ref Mesh[] meshes, ref Vector3[] pivots, ref List <RFDictionary> origSubMeshIdsRf, RayfireRigid scr, List <Vector3> sliceData)
        {
            // Get mesh
            scr.meshDemolition.mesh = GetDemolitionMesh(scr);

            // Set up shatter
            RFShatter shatter = SetShatter(
                2,
                scr.meshDemolition.mesh,
                scr.transform,
                scr.materials,
                true,
                scr.meshDemolition.properties.removeCollinear,
                scr.meshDemolition.seed,
                FragmentMode.Runtime,
                false,
                false,
                false,
                false,
                3);

            // Failed input
            if (shatter == null)
            {
                scr.meshDemolition.badMesh++;
                return;
            }

            // Get innerSubId
            int innerSubId = RFSurface.SetInnerSubId(scr);

            // Get slice data
            List <Vector3> points = new List <Vector3>();
            List <Vector3> norms  = new List <Vector3>();

            for (int i = 0; i < sliceData.Count; i++)
            {
                points.Add(sliceData[i]);
                norms.Add(sliceData[i + 1]);
                i++;
            }

            // Set params
            shatter.SetBricksParams(points.ToArray(), norms.ToArray(), scr.transform);

            // Calculate fragments
            List <Dictionary <int, int> > origSubMeshIds = new List <Dictionary <int, int> >();
            bool successState = Compute(
                2,
                shatter,
                scr.transform,
                ref meshes,
                ref pivots,
                scr.meshDemolition.mesh,
                innerSubId,
                ref origSubMeshIds,
                scr.gameObject);

            // Create RF dictionary
            origSubMeshIdsRf = new List <RFDictionary>();
            for (int i = 0; i < origSubMeshIds.Count; i++)
            {
                origSubMeshIdsRf.Add(new RFDictionary(origSubMeshIds[i]));
            }

            // Failed fragmentation. Increase bad mesh
            if (successState == false)
            {
                scr.meshDemolition.badMesh++;
                Debug.Log("Bad mesh: " + scr.name, scr.gameObject);
            }
            else
            {
                for (int i = 0; i < meshes.Length; i++)
                {
                    meshes[i].name = scr.name + "_" + i;
                }
            }
        }
Exemple #3
0
        /// /////////////////////////////////////////////////////////
        /// Shatter
        /// /////////////////////////////////////////////////////////

        // Cache for shatter
        public static void CacheMeshes(ref Mesh[] meshes, ref Vector3[] pivots, ref List <RFDictionary> origSubMeshIdsRf, RayfireShatter scrShatter)
        {
            // TODO check vars by type: slice list, etc

            // Turn off fast mode for tets and slices
            int shatterMode = GetShatterMode(scrShatter);

            // Get mesh
            Mesh mesh = GetDemolitionMesh(scrShatter);;

            // Decompose in Editor only, slice runtime only
            FragmentMode mode = scrShatter.mode;

            if (scrShatter.type == FragType.Decompose) // TODO FIX
            {
                mode = FragmentMode.Editor;
            }
            if (scrShatter.type == FragType.Slices)
            {
                mode = FragmentMode.Runtime;
            }

            // Set up shatter
            RFShatter shatter = SetShatter(
                shatterMode,
                mesh,
                scrShatter.transform,
                scrShatter.material,
                scrShatter.advanced.decompose,
                scrShatter.advanced.removeCollinear,
                scrShatter.advanced.seed,
                mode,
                scrShatter.advanced.inputPrecap,
                scrShatter.advanced.outputPrecap,
                scrShatter.advanced.removeDoubleFaces,
                scrShatter.advanced.excludeInnerFragments,
                scrShatter.advanced.elementSizeThreshold);

            // Failed input
            if (shatter == null)
            {
                meshes = null;
                pivots = null;
                return;
            }

            // Get innerSubId
            int innerSubId = RFSurface.SetInnerSubId(scrShatter);

            // Set fragmentation properties
            SetFragmentProperties(shatter, scrShatter, null);

            // Custom points check
            if (scrShatter.type == FragType.Custom && scrShatter.custom.noPoints == true)
            {
                meshes = null;
                pivots = null;
                Debug.Log("No custom ponts");
                return;
            }

            // Calculate fragments
            List <Dictionary <int, int> > origSubMeshIds = new List <Dictionary <int, int> >();
            bool successState = Compute(
                shatterMode,
                shatter,
                scrShatter.transform,
                ref meshes,
                ref pivots,
                mesh,
                innerSubId,
                ref origSubMeshIds,
                scrShatter);

            // Create RF dictionary
            origSubMeshIdsRf = new List <RFDictionary>();
            for (int i = 0; i < origSubMeshIds.Count; i++)
            {
                origSubMeshIdsRf.Add(new RFDictionary(origSubMeshIds[i]));
            }

            // Failed fragmentation. Increase bad mesh
            if (successState == false)
            {
                Debug.Log("Bad shatter output mesh: " + scrShatter.name);
            }
            else
            {
                for (int i = 0; i < meshes.Length; i++)
                {
                    meshes[i].name = scrShatter.name + "_" + i;
                }
            }
        }