diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/MeshExporter.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/MeshExporter.cs index 005d79d47..a4490768f 100644 --- a/Assets/UniGLTF/Runtime/UniGLTF/IO/MeshExporter.cs +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/MeshExporter.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Linq; -using UniJSON; using UnityEngine; namespace UniGLTF @@ -24,10 +23,10 @@ namespace UniGLTF public static class MeshExporter { static glTFMesh ExportPrimitives(glTF gltf, int bufferIndex, - string rendererName, - Mesh mesh, Material[] materials, - List unityMaterials) + MeshWithRenderer unityMesh, List unityMaterials) { + var mesh = unityMesh.Mesh; + var materials = unityMesh.Renderer.sharedMaterials; var positions = mesh.vertices.Select(y => y.ReverseZ()).ToArray(); var positionAccessorIndex = gltf.ExtendBufferAndGetAccessorIndex(bufferIndex, positions, glBufferTarget.ARRAY_BUFFER); gltf.accessors[positionAccessorIndex].min = positions.Aggregate(positions[0], (a, b) => new Vector3(Mathf.Min(a.x, b.x), Math.Min(a.y, b.y), Mathf.Min(a.z, b.z))).ToArray(); @@ -98,7 +97,7 @@ namespace UniGLTF if (j >= materials.Length) { - Debug.LogWarningFormat("{0}.materials is not enough", rendererName); + Debug.LogWarningFormat("{0}.materials is not enough", unityMesh.Renderer.name); break; } @@ -255,24 +254,19 @@ namespace UniGLTF List unityMeshes, List unityMaterials, MeshExportSettings settings) { - for (int i = 0; i < unityMeshes.Count; ++i) + foreach (var unityMesh in unityMeshes) { - var x = unityMeshes[i]; - var mesh = x.Mesh; - var materials = x.Renderer.sharedMaterials; - var gltfMesh = ExportPrimitives(gltf, bufferIndex, - x.Renderer.name, - mesh, materials, unityMaterials); + unityMesh, unityMaterials); var targetNames = new List(); var blendShapeIndexMap = new Dictionary(); int exportBlendShapes = 0; - for (int j = 0; j < mesh.blendShapeCount; ++j) + for (int j = 0; j < unityMesh.Mesh.blendShapeCount; ++j) { var morphTarget = ExportMorphTarget(gltf, bufferIndex, - mesh, j, + unityMesh.Mesh, j, settings.UseSparseAccessorForMorphTarget, settings.ExportOnlyBlendShapePosition); if (morphTarget.POSITION < 0 && morphTarget.NORMAL < 0 && morphTarget.TANGENT < 0) @@ -281,7 +275,7 @@ namespace UniGLTF } // maybe skip - var blendShapeName = mesh.GetBlendShapeName(j); + var blendShapeName = unityMesh.Mesh.GetBlendShapeName(j); blendShapeIndexMap.Add(j, exportBlendShapes++); targetNames.Add(blendShapeName); @@ -296,7 +290,7 @@ namespace UniGLTF gltf_mesh_extras_targetNames.Serialize(gltfMesh, targetNames); - yield return (mesh, gltfMesh, blendShapeIndexMap); + yield return (unityMesh.Mesh, gltfMesh, blendShapeIndexMap); } } }