Beispiel #1
0
        // SLice mesh
        public static void SliceMesh(RayfireRigid scr)
        {
            // Empty lists
            scr.DeleteCache();
            scr.DeleteFragments();

            // SLice
            RFFragment.SliceMeshes(ref scr.meshes, ref scr.pivots, ref scr.subIds, scr, scr.limitations.slicePlanes);

            // Remove plane info
            scr.limitations.slicePlanes.Clear();

            // Stop
            if (scr.HasMeshes == false)
            {
                return;
            }

            // Get fragments
            scr.fragments = RFDemolitionMesh.CreateSlices(scr);

            // TODO check for fragments

            // Set demolition
            scr.limitations.demolished = true;

            // Fragments initialisation
            scr.InitMeshFragments();

            // Event
            scr.demolitionEvent.InvokeLocalEvent(scr);
            RFDemolitionEvent.InvokeGlobalEvent(scr);

            // Destroy original
            RayfireMan.DestroyFragment(scr, scr.rootParent);
        }
Beispiel #2
0
        // Slice object
        public void SliceObjectByPlanes()
        {
            // Empty lists
            DeleteCache();
            DeleteFragments();

            // SLice
            RFFragment.SliceMeshes(ref meshes, ref pivots, ref subIds, this, limitations.slicePlanes);

            // Remove plane info
            limitations.slicePlanes.Clear();

            // Stop
            if (HasMeshes == false)
            {
                return;
            }

            // Get fragments
            fragments = CreateSlices();

            // TODO check for fragments

            // Set demolition
            limitations.demolished = true;

            // Fragments initialisation
            InitFragments();

            // Event
            demolitionEvent.InvokeLocalEvent(this);
            RFDemolitionEvent.InvokeGlobalEvent(this);

            // Destroy original
            RayfireMan.DestroyFragment(this, rootParent);
        }
Beispiel #3
0
        // Demolish object
        public void Demolish()
        {
            // Profiler.BeginSample ("Demolition");
            // Debug.Log (limitations.demolitionShould);

            // Initialize if not
            if (initialized == false)
            {
                Initialize();
            }

            // Timestamp
            float t1 = Time.realtimeSinceStartup;

            // Restore position and rotation to prevent high collision offset
            transForm.position = physics.position;
            transForm.rotation = physics.rotation;

            // Demolish mesh or cluster to reference
            if (RFReferenceDemolition.DemolishReference(this) == false)
            {
                return;
            }

            // Demolish mesh and create fragments. Stop if runtime caching or no meshes/fragments were created
            if (RFDemolitionMesh.DemolishMesh(this) == false)
            {
                return;
            }

            /* EXPERIMENTAL
             * // TODO Clusterize
             * bool clusterize = true;
             * if (clusterize == true && objectType == ObjectType.Mesh && demolitionType == DemolitionType.Runtime)
             * {
             *
             *  foreach (var frag in fragments)
             *  {
             *      Destroy (frag.physics.rigidBody);
             *      Destroy (frag);
             *  }
             *
             *  RayfireRigid scr = this.rootChild.gameObject.AddComponent<RayfireRigid>();
             *  this.CopyPropertiesTo (scr);
             *  scr.demolitionType = DemolitionType.Runtime;
             *  scr.objectType     = ObjectType.ConnectedCluster;
             *
             *  scr.limitations.contactPoint   = this.limitations.contactPoint;
             *  scr.limitations.contactNormal  = this.limitations.contactNormal;
             *  scr.limitations.contactVector3 = this.limitations.contactVector3;
             *
             *  scr.physics.velocity = this.physics.velocity;
             *
             *  scr.clusterDemolition.cluster  = new RFCluster();
             *  scr.Initialize();
             *
             *  scr.physics.rigidBody.velocity   = this.physics.velocity;
             *  scr.limitations.demolitionShould = true;
             *  //scr.Demolish();
             *  RayfireMan.DestroyFragment (this, rootParent);
             *  return;
             * }
             */


            // Demolish cluster to children nodes
            if (RFDemolitionCluster.DemolishCluster(this) == true)
            {
                return;
            }

            // Check fragments and proceed TODO separate flow for connected cls demolition
            if (limitations.demolished == false)
            {
                limitations.demolitionShould = false;
                demolitionType = DemolitionType.None;
                return;
            }

            // Connectivity check
            activation.CheckConnectivity();

            // Fragments initialisation
            InitMeshFragments();

            // Sum total demolition time
            RayfireMan.inst.maxTimeThisFrame += Time.realtimeSinceStartup - t1;

            // Init particles
            RFParticles.InitDemolitionParticles(this);

            // Init sound
            RFSound.DemolitionSound(sound, limitations.bboxSize);

            // Event
            demolitionEvent.InvokeLocalEvent(this);
            RFDemolitionEvent.InvokeGlobalEvent(this);

            // Destroy demolished object
            RayfireMan.DestroyFragment(this, rootParent);

            // Timestamp
            // float t2 = Time.realtimeSinceStartup;
            // Debug.Log (t2 - t1);
            // Profiler.EndSample();
        }
Beispiel #4
0
        // Demolish object
        public void Demolish()
        {
            // Profiler.BeginSample ("Demolition");
            // Debug.Log (limitations.demolitionShould);

            // Initialize if not
            if (initialized == false)
            {
                Initialize();
            }

            // Timestamp
            float t1 = Time.realtimeSinceStartup;

            // Restore position and rotation to prevent high collision offset
            transForm.position = physics.position;
            transForm.rotation = physics.rotation;

            // Demolish mesh or cluster to reference
            if (RFReferenceDemolition.DemolishReference(this) == false)
            {
                return;
            }

            // Demolish mesh and create fragments. Stop if runtime caching or no meshes/fragments were created
            if (RFDemolitionMesh.DemolishMesh(this) == false)
            {
                return;
            }

            // Demolish cluster to children nodes
            if (RFDemolitionCluster.DemolishCluster(this) == true)
            {
                return;
            }

            // Check fragments and proceed TODO separate flow for connected cls demolition
            if (limitations.demolished == false)
            {
                limitations.demolitionShould = false;
                demolitionType = DemolitionType.None;
                return;
            }

            // Connectivity check
            activation.CheckConnectivity();

            // Fragments initialisation
            InitMeshFragments();

            // Sum total demolition time
            RayfireMan.inst.maxTimeThisFrame += Time.realtimeSinceStartup - t1;

            // Init particles
            RFParticles.InitDemolitionParticles(this);

            // Event
            demolitionEvent.InvokeLocalEvent(this);
            RFDemolitionEvent.InvokeGlobalEvent(this);

            // Destroy demolished object
            RayfireMan.DestroyFragment(this, rootParent);

            // Timestamp
            // float t2 = Time.realtimeSinceStartup;
            // Debug.Log (t2 - t1);
            // Profiler.EndSample();
        }