Esempio n. 1
0
        // Init collapse after connection loss
        static void CollapseCluster(RayfireRigid scr)
        {
            // Collect solo shards, remove from cluster, no need to reinit
            List <RFShard> detachShards = new List <RFShard>();

            RFCluster.GetSoloShards(scr.clusterDemolition.cluster, detachShards);

            // Clear fragments in case of previous demolition
            if (scr.HasFragments == true)
            {
                scr.fragments.Clear();
            }

            // Dynamic cluster connectivity check, all clusters are equal, pick biggest to keep as original
            if (scr.simulationType == SimType.Dynamic || scr.simulationType == SimType.Sleeping)
            {
                // Check left cluster shards for connectivity and collect not connected child clusters. Should be before ClusterizeDetachShards
                RFCluster.ConnectivityCheck(scr.clusterDemolition.cluster);

                // Cluster is not connected. Set biggest child cluster shards to original cluster. Cant be 1 child cluster here
                RFCluster.ReduceChildClusters(scr.clusterDemolition.cluster);
            }

            // Kinematik/ Inactive cluster, Connectivity check if cluster has uny shards. Main cluster keeps all not activated
            else if (scr.simulationType == SimType.Kinematic || scr.simulationType == SimType.Inactive)
            {
                RFCluster.ConnectivityUnyCheck(scr.clusterDemolition.cluster);
            }

            // Init final cluster ops
            RFDemolitionCluster.PostDemolitionCluster(scr, detachShards);
        }
        // Check for connectivity
        public void CheckConnectivity()
        {
            // Do once
            checkNeed = false;

            // Clear all activated/demolished shards
            CleanUpActivatedShards(cluster);

            // No shards to check
            if (cluster.shards.Count == 0)
            {
                return;
            }

            // Reinit neibs after cleaning
            RFShard.ReinitNeibs(cluster.shards);

            // List of shards to be activated
            List <RFShard> soloShards = new List <RFShard>();

            // TODO do not collect solo uny shards
            // Check for solo shards and collect
            RFCluster.GetSoloShards(cluster, soloShards);

            // Reinit neibs before connectivity check
            RFShard.ReinitNeibs(cluster.shards);

            // Connectivity check
            RFCluster.ConnectivityCheck(cluster);

            // Get not connected and not unyielding child cluster
            CheckUnyielding(cluster);

            // TODO ONE NEIB DETACH FOR CHILD CLUSTERS

            // Activate not connected shards.
            if (soloShards.Count > 0)
            {
                for (int i = 0; i < soloShards.Count; i++)
                {
                    soloShards[i].rigid.Activate();
                }
            }

            // Clusterize childClusters  or activate their shards
            if (cluster.HasChildClusters == true)
            {
                if (clusterize == true)
                {
                    Clusterize();
                }
                else
                {
                    for (int c = 0; c < cluster.childClusters.Count; c++)
                    {
                        for (int s = 0; s < cluster.childClusters[c].shards.Count; s++)
                        {
                            cluster.childClusters[c].shards[s].rigid.Activate();
                        }
                    }
                }
            }

            // Stop checking. Everything activated
            if (cluster.shards.Count == 0)
            {
                checkConnectivity = false;
            }
        }