예제 #1
0
        // 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();
        }
예제 #2
0
        // 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);
        }
예제 #3
0
        // 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);
        }