Exemplo n.º 1
0
        public static Mesh FixMesh(Mesh originalMesh, Vector3 extents)
        {
            Bounds bounds      = originalMesh.bounds;
            Bounds fixBounds   = new Bounds(bounds.center, extents * 2.0f);
            Mesh   fixVertices = HBUtils.BoundsToMesh(fixBounds);

            CombineInstance fixInstance = new CombineInstance();

            fixInstance.mesh         = fixVertices;
            fixInstance.subMeshIndex = 0;
            fixInstance.transform    = Matrix4x4.identity;

            CombineInstance[] combineInstances = new CombineInstance[originalMesh.subMeshCount];
            for (int i = 0; i < originalMesh.subMeshCount; ++i)
            {
                CombineInstance submeshInstance = new CombineInstance();
                submeshInstance.mesh      = Subdivider.ExtractSubmesh(originalMesh, i);
                submeshInstance.transform = Matrix4x4.identity;
                CombineInstance[] submeshInstances = new[] { fixInstance, submeshInstance };
                Mesh fixedSubmesh = new Mesh();
                fixedSubmesh.CombineMeshes(submeshInstances, true);

                CombineInstance meshInstance = new CombineInstance();
                meshInstance.mesh         = fixedSubmesh;
                meshInstance.transform    = Matrix4x4.identity;
                meshInstance.subMeshIndex = 0;
                combineInstances[i]       = meshInstance;
            }

            Mesh fixedMesh = new Mesh();

            fixedMesh.CombineMeshes(combineInstances, false);

            return(fixedMesh);
        }