Exemplo n.º 1
0
        // Create one cluster which includes all children meshes
        static bool ClusterizeNested(RayfireRigid scr)
        {
            // Get all nested children with meshes
            MeshFilter[] childMeshes = scr.gameObject.GetComponentsInChildren <MeshFilter>();

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

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

            return(true);
        }
Exemplo n.º 2
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);
        }