Ejemplo n.º 1
0
        private static void PopulateMeshGroups(Dictionary <Material, List <MeshTransform> > meshGroups, GameObject go, Mesh mesh)
        {
            Mesh[]     meshes = MeshUtils.Separate(mesh);
            Material[] rendererMaterials;
            Renderer   renderer = go.GetComponent <Renderer>();

            if (renderer == null)
            {
                rendererMaterials = new Material[meshes.Length];
            }
            else
            {
                rendererMaterials = renderer.sharedMaterials;
                System.Array.Resize(ref rendererMaterials, meshes.Length);
            }

            for (int m = 0; m < rendererMaterials.Length; ++m)
            {
                Material material = rendererMaterials[m];
                if (!meshGroups.ContainsKey(material))
                {
                    meshGroups.Add(material, new List <MeshTransform>());
                }

                List <MeshTransform> group = meshGroups[material];
                group.Add(new MeshTransform(meshes[m], go.transform.localToWorldMatrix));
            }
        }
Ejemplo n.º 2
0
        private static Mesh RemoveRotation(Mesh mesh, Matrix4x4 targetRotationMatrix, bool merge)
        {
            Mesh[]            meshes           = MeshUtils.Separate(mesh);
            CombineInstance[] combineInstances = new CombineInstance[meshes.Length];
            for (int i = 0; i < meshes.Length; ++i)
            {
                CombineInstance removeRotation = new CombineInstance();
                removeRotation.mesh         = meshes[i];
                removeRotation.subMeshIndex = 0;
                removeRotation.transform    = targetRotationMatrix;
                combineInstances[i]         = removeRotation;
            }

            //got final mesh without rotation
            mesh = new Mesh();
            mesh.CombineMeshes(combineInstances, merge);
            mesh.RecalculateBounds();
            return(mesh);
        }
Ejemplo n.º 3
0
        private static List <Mesh> GetColliderMeshes(GameObject obj)
        {
            List <Mesh> meshes = new List <Mesh>();

            Collider[] allColliders = obj.GetComponents <Collider>();

            if (allColliders.Length == 0)
            {
                MeshFilter f = obj.GetComponent <MeshFilter>();
                if (f != null)
                {
                    //UNCOMMENT TO INCLUDE OBJECT MESH TO COLLIDER
                    //meshes.AddRange(Separate(f.sharedMesh));
                }
            }
            else
            {
                for (int i = 0; i < allColliders.Length; ++i)
                {
                    MeshCollider meshCollider = allColliders[i] as MeshCollider;
                    if (meshCollider != null)
                    {
                        meshes.AddRange(MeshUtils.Separate(meshCollider.sharedMesh));
                    }
                    else
                    {
                        //Use object's mesh if there is no meshcollider
                        MeshFilter f = obj.GetComponent <MeshFilter>();
                        if (f != null)
                        {
                            meshes.AddRange(MeshUtils.Separate(f.sharedMesh));
                        }
                    }
                }
            }

            return(meshes);
        }