示例#1
0
        // Set cluster
        void SetCluster()
        {
            cluster = new RFCluster();

            // Set shards for main cluster
            cluster.shards = RFShard.GetShards(rigidList, connectivityType);

            // Set shard neibs
            RFShard.SetShardNeibs(cluster.shards, connectivityType);
        }
        // Set cluster
        void SetCluster(List <Transform> tmList)
        {
            // In case of runtime add
            if (cluster == null)
            {
                cluster = new RFCluster();
            }

            // Main cluster cached, reinit non serialized vars
            if (cluster.shards.Count > 0)
            {
                InitShards(rigidList, cluster);
            }

            // Create main cluster
            if (cluster.shards.Count == 0)
            {
                cluster              = new RFCluster();
                cluster.id           = RFCluster.GetUniqClusterId(cluster);
                cluster.tm           = transform;
                cluster.depth        = 0;
                cluster.pos          = transform.position;
                cluster.initialized  = true;
                cluster.demolishable = demolishable;

                // Set shards for main cluster
                if (Application.isPlaying == true)
                {
                    SetShardsByRigids(cluster, rigidList, type);
                }
                else
                {
                    RFShard.SetShardsByTransforms(cluster, tmList, type);
                }

                // Set shard neibs
                RFShard.SetShardNeibs(cluster.shards, type, minimumArea, minimumSize, percentage, seed);

                // Set range for area and size
                RFCollapse.SetRangeData(cluster, percentage, seed);

                // Debug.Log ("SetCluster" + rigidList.Count);
            }
        }
示例#3
0
        // Create one cluster which includes only children meshes, not children of children meshes.
        static bool ClusterizeConnected(RayfireRigid scr)
        {
            // Setup cluster and shard if first time. Do not if copied from parent
            if (scr.clusterDemolition.cluster == null || scr.clusterDemolition.cluster.id == 0)
            {
                // Set cluster
                scr.clusterDemolition.cluster    = RFCluster.SetCluster(scr.transForm, scr.clusterDemolition.connectivity);
                scr.clusterDemolition.cluster.id = 1;

                // Set shard neibs
                RFShard.SetShardNeibs(scr.clusterDemolition.cluster.shards, scr.clusterDemolition.connectivity);
            }

            // Get all children meshes
            List <MeshFilter> childMeshes = new List <MeshFilter>();

            for (int i = 0; i < scr.transForm.childCount; i++)
            {
                MeshFilter mf = scr.transForm.GetChild(i).GetComponent <MeshFilter>();
                if (mf != null)
                {
                    childMeshes.Add(mf);
                }
            }

            // No meshes in children
            if (childMeshes.Count == 0)
            {
                return(false);
            }

            // float t1 = Time.realtimeSinceStartup;

            // Create mesh colliders for every input mesh and collect
            RFPhysic.SetClusterColliders(scr, childMeshes.ToArray());

            // TODO connectivity check to find solo shards and make sure they are not connected

            return(true);
        }
示例#4
0
        /// /////////////////////////////////////////////////////////
        /// By range
        /// /////////////////////////////////////////////////////////

        // Second clustering type
        void ClusterizeRange()
        {
            if (type == ClusterType.BySharedArea)
            {
                Random.InitState(seed);

                // Create Base cluster and collect
                RFCluster mainCluster = SetupMainCluster(ConnectivityType.ByMesh);
                allClusters.Add(mainCluster);

                // Set shard neibs
                RFShard.SetShardNeibs(mainCluster.shards, ConnectivityType.ByMesh);

                // Clusterize base shards to clusters
                List <RFCluster> childClusters = ClusterizeRangeShards(mainCluster);

                // Create root and set shards and children
                foreach (RFCluster childCluster in childClusters)
                {
                    CreateRoot(childCluster, transform);
                }

                // Add to all clusters
                allClusters.AddRange(childClusters);

                // Clusterize clusters in depth
                if (depth > 1)
                {
                    for (int i = 1; i < depth; i++)
                    {
                        // Set clusters neib info
                        RFCluster.SetClusterNeib(mainCluster.childClusters, true);

                        // Get new depth clusters
                        List <RFCluster> newClusters = ClusterizeRangeClusters(mainCluster);

                        if (newClusters.Count > 1)
                        {
                            // Create root for all new clusters and set as parent for them
                            foreach (RFCluster cls in newClusters)
                            {
                                CreateRoot(cls, mainCluster.tm);
                                foreach (RFCluster childCLuster in cls.childClusters)
                                {
                                    childCLuster.tm.parent = cls.tm;
                                }
                            }

                            // Set as child cluster for main cluster to be clusterized at next pass
                            mainCluster.childClusters = newClusters;

                            // Add to all clusters
                            allClusters.AddRange(newClusters);

                            // Get all nested clusters and increment depth
                            foreach (RFCluster cls in allClusters)
                            {
                                if (cls.id != 0)
                                {
                                    cls.depth += 1;
                                }
                            }
                        }
                    }
                }

                // Set name to roots
                SetClusterNames();
            }
        }
示例#5
0
        /// /////////////////////////////////////////////////////////
        /// Voronoi
        /// /////////////////////////////////////////////////////////

        // Clusterize by Voronoi pc
        void ClusterizeVoronoi()
        {
            if (type == ClusterType.ByPointCloud)
            {
                // Create Base cluster
                RFCluster mainCluster = SetupMainCluster(connectivity);

                // Base amount of clusters is more than shards amount
                if (baseAmount >= mainCluster.shards.Count)
                {
                    return;
                }

                // Set shard neibs
                RFShard.SetShardNeibs(mainCluster.shards, connectivity);

                // List with all clusters
                List <RFCluster> clusters = new List <RFCluster> {
                    mainCluster
                };

                // Collect base cluster
                allClusters.Add(mainCluster);

                // Clusterize
                while (clusters.Count > 0)
                {
                    // Get local cluster
                    RFCluster cls = clusters[0];

                    // Remove current cluster from clustering list
                    clusters.RemoveAt(0);

                    // Low amount of shards
                    if (cls.shards.Count < 4)
                    {
                        continue;
                    }

                    // Get amount
                    int amount = baseAmount;
                    if (cls.depth > 0)
                    {
                        amount = depthAmount;
                    }

                    // Get local depth roots
                    cls.childClusters = ClusterizeClusterByAmount(cls, amount);

                    // Collect new clusters
                    allClusters.AddRange(cls.childClusters);

                    // Check if local cluster should be clusterized further and add to list
                    if (cls.childClusters.Count > 0 && depth > cls.depth + 1)
                    {
                        clusters.AddRange(cls.childClusters);
                    }
                }

                // Set name to roots
                SetClusterNames();
            }
        }