diff --git a/Assets/UniGLTF/Editor/UniGLTF/ExportDialog/GltfExportWindow.cs b/Assets/UniGLTF/Editor/UniGLTF/ExportDialog/GltfExportWindow.cs index 7a4f27459..d567ef00a 100644 --- a/Assets/UniGLTF/Editor/UniGLTF/ExportDialog/GltfExportWindow.cs +++ b/Assets/UniGLTF/Editor/UniGLTF/ExportDialog/GltfExportWindow.cs @@ -100,22 +100,21 @@ namespace UniGLTF default: throw new System.Exception(); } - var gltf = new glTF(); - ExportingGltfData writer = default; - using (var exporter = new gltfExporter(gltf, Settings)) + var data = new ExportingGltfData(); + using (var exporter = new gltfExporter(data, Settings)) { exporter.Prepare(State.ExportRoot); - writer = exporter.Export(new EditorTextureSerializer()); + exporter.Export(new EditorTextureSerializer()); } if (isGlb) { - var bytes = writer.ToGlbBytes(); + var bytes = data.ToGlbBytes(); File.WriteAllBytes(path, bytes); } else { - var (json, buffers) = writer.ToGltf(path); + var (json, buffers) = data.ToGltf(path); // without BOM var encoding = new System.Text.UTF8Encoding(false); File.WriteAllText(path, json, encoding); diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/ExportingGltfData.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/ExportingGltfData.cs index 99dd7a5a5..faed324c7 100644 --- a/Assets/UniGLTF/Runtime/UniGLTF/IO/ExportingGltfData.cs +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/ExportingGltfData.cs @@ -7,17 +7,16 @@ namespace UniGLTF { public class ExportingGltfData { - readonly glTF _gltf; + readonly glTF _gltf = new glTF(); public glTF GLTF => _gltf; - public ExportingGltfData(glTF gltf, int reserved = default) + public ExportingGltfData(int reserved = default) { if (reserved == 0) { reserved = 50 * 1024 * 1024; } - _gltf = gltf; // glb body と gltf の bin 兼用 _gltf.buffers.Add(new glTFBuffer(new ArrayByteBuffer(new byte[reserved]))); } diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/gltfExporter.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/gltfExporter.cs index c486c5c13..11552c84a 100644 --- a/Assets/UniGLTF/Runtime/UniGLTF/IO/gltfExporter.cs +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/gltfExporter.cs @@ -10,9 +10,9 @@ namespace UniGLTF { public class gltfExporter : IDisposable { - protected glTF glTF; + protected ExportingGltfData _data; - protected ExportingGltfData _writer; + protected glTF _gltf => _data.GLTF; public GameObject Copy { @@ -69,14 +69,13 @@ namespace UniGLTF GltfExportSettings m_settings; - public gltfExporter(glTF gltf, GltfExportSettings settings) + public gltfExporter(ExportingGltfData data, GltfExportSettings settings) { - glTF = gltf; - _writer = new ExportingGltfData (gltf); + _data = data; - glTF.extensionsUsed.AddRange(ExtensionUsed); + _gltf.extensionsUsed.AddRange(ExtensionUsed); - glTF.asset = new glTFAssets + _gltf.asset = new glTFAssets { generator = "UniGLTF-" + UniGLTFVersion.VERSION, version = "2.0", @@ -225,7 +224,7 @@ namespace UniGLTF // do nothing } - public virtual ExportingGltfData Export(ITextureSerializer textureSerializer) + public virtual void Export(ITextureSerializer textureSerializer) { Nodes = Copy.transform.Traverse() .Skip(1) // exclude root object for the symmetry with the importer @@ -240,7 +239,7 @@ namespace UniGLTF m_textureExporter = new TextureExporter(textureSerializer); var materialExporter = CreateMaterialExporter(); - glTF.materials = Materials.Select(x => materialExporter.ExportMaterial(x, TextureExporter, m_settings)).ToList(); + _gltf.materials = Materials.Select(x => materialExporter.ExportMaterial(x, TextureExporter, m_settings)).ToList(); #endregion #region Meshes @@ -253,10 +252,10 @@ namespace UniGLTF } var (gltfMesh, blendShapeIndexMap) = m_settings.DivideVertexBuffer - ? MeshExporter_DividedVertexBuffer.Export(_writer, unityMesh, Materials, m_settings.InverseAxis.Create(), m_settings) - : MeshExporter_SharedVertexBuffer.Export(_writer, unityMesh, Materials, m_settings.InverseAxis.Create(), m_settings) + ? MeshExporter_DividedVertexBuffer.Export(_data, unityMesh, Materials, m_settings.InverseAxis.Create(), m_settings) + : MeshExporter_SharedVertexBuffer.Export(_data, unityMesh, Materials, m_settings.InverseAxis.Create(), m_settings) ; - glTF.meshes.Add(gltfMesh); + _gltf.meshes.Add(gltfMesh); Meshes.Add(unityMesh.Mesh); if (!MeshBlendShapeIndexMap.ContainsKey(unityMesh.Mesh)) { @@ -276,9 +275,9 @@ namespace UniGLTF foreach (var node in Nodes) { var gltfNode = ExportNode(node, Nodes, uniqueUnityMeshes, skins); - glTF.nodes.Add(gltfNode); + _gltf.nodes.Add(gltfNode); } - glTF.scenes = new List + _gltf.scenes = new List { new gltfScene { @@ -293,20 +292,20 @@ namespace UniGLTF if (uniqueBones != null && renderer is SkinnedMeshRenderer smr) { var matrices = x.GetBindPoses().Select(m_settings.InverseAxis.Create().InvertMat4).ToArray(); - var accessor = _writer.ExtendBufferAndGetAccessorIndex(matrices, glBufferTarget.NONE); + var accessor = _data.ExtendBufferAndGetAccessorIndex(matrices, glBufferTarget.NONE); var skin = new glTFSkin { inverseBindMatrices = accessor, joints = uniqueBones.Select(y => Nodes.IndexOf(y)).ToArray(), skeleton = Nodes.IndexOf(smr.rootBone), }; - var skinIndex = glTF.skins.Count; - glTF.skins.Add(skin); + var skinIndex = _gltf.skins.Count; + _gltf.skins.Add(skin); foreach (var z in Nodes.Where(y => y.Has(renderer))) { var nodeIndex = Nodes.IndexOf(z); - var node = glTF.nodes[nodeIndex]; + var node = _gltf.nodes[nodeIndex]; node.skin = skinIndex; } } @@ -339,14 +338,14 @@ namespace UniGLTF { var sampler = animationWithCurve.Animation.samplers[kv.Key]; - var inputAccessorIndex = _writer.ExtendBufferAndGetAccessorIndex(kv.Value.Input); + var inputAccessorIndex = _data.ExtendBufferAndGetAccessorIndex(kv.Value.Input); sampler.input = inputAccessorIndex; - var outputAccessorIndex = _writer.ExtendBufferAndGetAccessorIndex(kv.Value.Output); + var outputAccessorIndex = _data.ExtendBufferAndGetAccessorIndex(kv.Value.Output); sampler.output = outputAccessorIndex; // modify accessors - var outputAccessor = glTF.accessors[outputAccessorIndex]; + var outputAccessor = _gltf.accessors[outputAccessorIndex]; var channel = animationWithCurve.Animation.channels.First(x => x.sampler == kv.Key); switch (glTFAnimationTarget.GetElementCount(channel.target.path)) { @@ -369,7 +368,7 @@ namespace UniGLTF } } animationWithCurve.Animation.name = clip.name; - glTF.animations.Add(animationWithCurve.Animation); + _gltf.animations.Add(animationWithCurve.Animation); } } @@ -383,12 +382,10 @@ namespace UniGLTF for (var exportedTextureIdx = 0; exportedTextureIdx < exported.Count; ++exportedTextureIdx) { var (unityTexture, colorSpace) = exported[exportedTextureIdx]; - GltfTextureExporter.PushGltfTexture(_writer, unityTexture, colorSpace, textureSerializer); + GltfTextureExporter.PushGltfTexture(_data, unityTexture, colorSpace, textureSerializer); } - FixName(glTF); - - return _writer; + FixName(_gltf); } /// diff --git a/Assets/UniGLTF/Tests/UniGLTF/EditorTextureSerializerTests.cs b/Assets/UniGLTF/Tests/UniGLTF/EditorTextureSerializerTests.cs index 71cd70566..463da1c2e 100644 --- a/Assets/UniGLTF/Tests/UniGLTF/EditorTextureSerializerTests.cs +++ b/Assets/UniGLTF/Tests/UniGLTF/EditorTextureSerializerTests.cs @@ -122,8 +122,8 @@ namespace UniGLTF root.GetComponent().sharedMaterial = mat; // Export glTF - var gltf = new glTF(); - using (var exporter = new gltfExporter(gltf, new GltfExportSettings + var data = new ExportingGltfData(); + using (var exporter = new gltfExporter(data, new GltfExportSettings { InverseAxis = Axes.X, ExportOnlyBlendShapePosition = false, @@ -134,6 +134,7 @@ namespace UniGLTF exporter.Prepare(root); exporter.Export(new EditorTextureSerializer()); } + var gltf = data.GLTF; Assert.AreEqual(1, gltf.images.Count); var exportedImage = gltf.images[0]; Assert.AreEqual("image/png", exportedImage.mimeType); @@ -142,10 +143,10 @@ namespace UniGLTF UnityEngine.Object.DestroyImmediate(mat); UnityEngine.Object.DestroyImmediate(root); - var data = GltfData.CreateFromGltfDataForTest(gltf); + var parsed = GltfData.CreateFromGltfDataForTest(gltf); // Extract Image to Texture2D - var exportedBytes = data.GetViewBytes(exportedImage.bufferView).ToArray(); + var exportedBytes = parsed.GetViewBytes(exportedImage.bufferView).ToArray(); var exportedTexture = new Texture2D(2, 2, TextureFormat.ARGB32, mipChain: false, linear: false); Assert.IsTrue(exportedTexture.LoadImage(exportedBytes)); // Always true ? Assert.AreEqual(srcTex.width, exportedTexture.width); diff --git a/Assets/UniGLTF/Tests/UniGLTF/GlbParserTests.cs b/Assets/UniGLTF/Tests/UniGLTF/GlbParserTests.cs index 29e13aac0..f8265df94 100644 --- a/Assets/UniGLTF/Tests/UniGLTF/GlbParserTests.cs +++ b/Assets/UniGLTF/Tests/UniGLTF/GlbParserTests.cs @@ -8,7 +8,8 @@ namespace UniGLTF [Test] public void TextureNameUniqueness() { - var gltf = new glTF(); + var data = new ExportingGltfData(); + var gltf = data.GLTF; gltf.asset.version = "2.0"; gltf.buffers.Add(new glTFBuffer(new ArrayByteBuffer(Array.Empty()))); gltf.textures.Add(new glTFTexture @@ -30,12 +31,12 @@ namespace UniGLTF name = "hogefuga", }); - var parser = new GlbLowLevelParser("Test", new ExportingGltfData (gltf).ToGlbBytes()); - var data = parser.Parse(); + var parser = new GlbLowLevelParser("Test", data.ToGlbBytes()); + var parsed = parser.Parse(); - Assert.AreEqual("FooBar", data.GLTF.textures[0].name); + Assert.AreEqual("FooBar", parsed.GLTF.textures[0].name); // NOTE: 大文字小文字が違うだけの名前は、同一としてみなされ、Suffix が付く。 - Assert.AreEqual("foobar__UNIGLTF__DUPLICATED__2", data.GLTF.textures[1].name); + Assert.AreEqual("foobar__UNIGLTF__DUPLICATED__2", parsed.GLTF.textures[1].name); } } } \ No newline at end of file diff --git a/Assets/UniGLTF/Tests/UniGLTF/GltfLoadTests.cs b/Assets/UniGLTF/Tests/UniGLTF/GltfLoadTests.cs index f89103bf1..68d4c0c91 100644 --- a/Assets/UniGLTF/Tests/UniGLTF/GltfLoadTests.cs +++ b/Assets/UniGLTF/Tests/UniGLTF/GltfLoadTests.cs @@ -57,13 +57,13 @@ namespace UniGLTF static Byte[] Export(GameObject root) { - var gltf = new glTF(); - using (var exporter = new gltfExporter(gltf, new GltfExportSettings())) + var data = new ExportingGltfData(); + using (var exporter = new gltfExporter(data, new GltfExportSettings())) { exporter.Prepare(root); - var w = exporter.Export(new EditorTextureSerializer()); - return w.ToGlbBytes(); + exporter.Export(new EditorTextureSerializer()); } + return data.ToGlbBytes(); } // Unsolved Animation Export issue diff --git a/Assets/UniGLTF/Tests/UniGLTF/MeshTests.cs b/Assets/UniGLTF/Tests/UniGLTF/MeshTests.cs index a014e7fbb..7d75ea89f 100644 --- a/Assets/UniGLTF/Tests/UniGLTF/MeshTests.cs +++ b/Assets/UniGLTF/Tests/UniGLTF/MeshTests.cs @@ -117,8 +117,7 @@ namespace UniGLTF [Test] public void SharedVertexBufferTest() { - var glTF = new glTF(); - var w = new ExportingGltfData (glTF, 50 * 1024 * 1024); + var data = new ExportingGltfData(50 * 1024 * 1024); var Materials = new List{ new Material(Shader.Find("Standard")), // A @@ -134,13 +133,14 @@ namespace UniGLTF var unityMesh = MeshExportList.Create(go); var (gltfMesh, blendShapeIndexMap) = meshExportSettings.DivideVertexBuffer - ? MeshExporter_DividedVertexBuffer.Export(w, unityMesh, Materials, axisInverter, meshExportSettings) - : MeshExporter_SharedVertexBuffer.Export(w, unityMesh, Materials, axisInverter, meshExportSettings) + ? MeshExporter_DividedVertexBuffer.Export(data, unityMesh, Materials, axisInverter, meshExportSettings) + : MeshExporter_SharedVertexBuffer.Export(data, unityMesh, Materials, axisInverter, meshExportSettings) ; - var data = GltfData.CreateFromGltfDataForTest(glTF); + + var parsed = GltfData.CreateFromGltfDataForTest(data.GLTF); { - var indices = data.GetIndices(gltfMesh.primitives[0].indices); + var indices = parsed.GetIndices(gltfMesh.primitives[0].indices); Assert.AreEqual(0, indices[0]); Assert.AreEqual(1, indices[1]); Assert.AreEqual(5, indices[2]); @@ -150,7 +150,7 @@ namespace UniGLTF } { - var indices = data.GetIndices(gltfMesh.primitives[1].indices); + var indices = parsed.GetIndices(gltfMesh.primitives[1].indices); Assert.AreEqual(1, indices[0]); Assert.AreEqual(2, indices[1]); Assert.AreEqual(4, indices[2]); @@ -159,15 +159,14 @@ namespace UniGLTF Assert.AreEqual(3, indices[5]); } - var positions = data.GetArrayFromAccessor(gltfMesh.primitives[0].attributes.POSITION); + var positions = parsed.GetArrayFromAccessor(gltfMesh.primitives[0].attributes.POSITION); Assert.AreEqual(6, positions.Length); } [Test] public void DividedVertexBufferTest() { - var glTF = new glTF(); - var w = new ExportingGltfData (glTF, 50 * 1024 * 1024); + var data = new ExportingGltfData(50 * 1024 * 1024); var Materials = new List{ new Material(Shader.Find("Standard")), // A @@ -183,13 +182,13 @@ namespace UniGLTF var unityMesh = MeshExportList.Create(go); var (gltfMesh, blendShapeIndexMap) = meshExportSettings.DivideVertexBuffer - ? MeshExporter_DividedVertexBuffer.Export(w, unityMesh, Materials, axisInverter, meshExportSettings) - : MeshExporter_SharedVertexBuffer.Export(w, unityMesh, Materials, axisInverter, meshExportSettings) + ? MeshExporter_DividedVertexBuffer.Export(data, unityMesh, Materials, axisInverter, meshExportSettings) + : MeshExporter_SharedVertexBuffer.Export(data, unityMesh, Materials, axisInverter, meshExportSettings) ; - var data = GltfData.CreateFromGltfDataForTest(glTF); + var parsed = GltfData.CreateFromGltfDataForTest(data.GLTF); { - var indices = data.GetIndices(gltfMesh.primitives[0].indices); + var indices = parsed.GetIndices(gltfMesh.primitives[0].indices); Assert.AreEqual(0, indices[0]); Assert.AreEqual(1, indices[1]); Assert.AreEqual(3, indices[2]); @@ -198,12 +197,12 @@ namespace UniGLTF Assert.AreEqual(2, indices[5]); } { - var positions = data.GetArrayFromAccessor(gltfMesh.primitives[0].attributes.POSITION); + var positions = parsed.GetArrayFromAccessor(gltfMesh.primitives[0].attributes.POSITION); Assert.AreEqual(4, positions.Length); } { - var indices = data.GetIndices(gltfMesh.primitives[1].indices); + var indices = parsed.GetIndices(gltfMesh.primitives[1].indices); Assert.AreEqual(0, indices[0]); Assert.AreEqual(1, indices[1]); Assert.AreEqual(3, indices[2]); @@ -212,7 +211,7 @@ namespace UniGLTF Assert.AreEqual(2, indices[5]); } { - var positions = data.GetArrayFromAccessor(gltfMesh.primitives[1].attributes.POSITION); + var positions = parsed.GetArrayFromAccessor(gltfMesh.primitives[1].attributes.POSITION); Assert.AreEqual(4, positions.Length); } } diff --git a/Assets/UniGLTF/Tests/UniGLTF/UniGLTFTests.cs b/Assets/UniGLTF/Tests/UniGLTF/UniGLTFTests.cs index 985a5e8c6..d521af24b 100644 --- a/Assets/UniGLTF/Tests/UniGLTF/UniGLTFTests.cs +++ b/Assets/UniGLTF/Tests/UniGLTF/UniGLTFTests.cs @@ -100,25 +100,25 @@ namespace UniGLTF var go = CreateSimpleScene(); // export - var gltf = new glTF(); + var data = new ExportingGltfData(); string json = null; - using (var exporter = new gltfExporter(gltf, new GltfExportSettings())) + using (var exporter = new gltfExporter(data, new GltfExportSettings())) { exporter.Prepare(go); exporter.Export(new EditorTextureSerializer()); // remove empty buffer - gltf.buffers.Clear(); + data.GLTF.buffers.Clear(); - json = gltf.ToJson(); + json = data.GLTF.ToJson(); } // parse - var data = new JsonWithStorageParser(json).Parse(); + var parsed = new JsonWithStorageParser(json).Parse(); // import - using (var context = new ImporterContext(data)) + using (var context = new ImporterContext(parsed)) using (var loaded = context.Load()) { AssertAreEqual(go.transform, loaded.transform); @@ -293,14 +293,14 @@ namespace UniGLTF [Test] public void GlTFToJsonTest() { - var gltf = new glTF(); - using (var exporter = new gltfExporter(gltf, new GltfExportSettings())) + var data = new ExportingGltfData(); + using (var exporter = new gltfExporter(data, new GltfExportSettings())) { exporter.Prepare(CreateSimpleScene()); exporter.Export(new EditorTextureSerializer()); } - var expected = gltf.ToJson().ParseAsJson(); + var expected = data.GLTF.ToJson().ParseAsJson(); expected.AddKey(Utf8String.From("meshes")); expected.AddValue(default(ArraySegment), ValueNodeType.Array); expected["meshes"].AddValue(default(ArraySegment), ValueNodeType.Object); @@ -334,7 +334,7 @@ namespace UniGLTF primitive["targets"][1].AddKey(Utf8String.From("TANGENT")); primitive["targets"][1].AddValue(Utf8String.From("0").Bytes, ValueNodeType.Integer); - gltf.meshes.Add(new glTFMesh("test") + data.GLTF.meshes.Add(new glTFMesh("test") { primitives = new List { @@ -362,7 +362,7 @@ namespace UniGLTF } } }); - var actual = gltf.ToJson().ParseAsJson(); + var actual = data.GLTF.ToJson().ParseAsJson(); Assert.AreEqual(expected, actual); } @@ -528,9 +528,10 @@ namespace UniGLTF } // export - var gltf = new glTF(); + var data = new ExportingGltfData(); + var gltf = data.GLTF; var json = default(string); - using (var exporter = new gltfExporter(gltf, new GltfExportSettings())) + using (var exporter = new gltfExporter(data, new GltfExportSettings())) { exporter.Prepare(go); exporter.Export(new EditorTextureSerializer()); @@ -553,9 +554,9 @@ namespace UniGLTF // import { var storage = new SimpleStorage(new ArraySegment(new byte[1024 * 1024])); - var data = new JsonWithStorageParser(json, storage).Parse(); + var parsed = new JsonWithStorageParser(json, storage).Parse(); - using (var context = new ImporterContext(data)) + using (var context = new ImporterContext(parsed)) using (var loaded = context.Load()) { var importedRed = loaded.transform.GetChild(0); @@ -573,10 +574,10 @@ namespace UniGLTF // import new version { var storage = new SimpleStorage(new ArraySegment(new byte[1024 * 1024])); - var data = new JsonWithStorageParser(json, storage).Parse(); + var parsed = new JsonWithStorageParser(json, storage).Parse(); //Debug.LogFormat("{0}", context.Json); - using (var context = new ImporterContext(data)) + using (var context = new ImporterContext(parsed)) using (var loaded = context.Load()) { var importedRed = loaded.transform.GetChild(0); @@ -610,9 +611,10 @@ namespace UniGLTF } // export - var gltf = new glTF(); + var data = new ExportingGltfData(); + var gltf = data.GLTF; string json; - using (var exporter = new gltfExporter(gltf, new GltfExportSettings())) + using (var exporter = new gltfExporter(data, new GltfExportSettings())) { exporter.Prepare(go); exporter.Export(new EditorTextureSerializer()); @@ -627,9 +629,9 @@ namespace UniGLTF // import { var storage = new SimpleStorage(new ArraySegment(new byte[1024 * 1024])); - var data = new JsonWithStorageParser(json, storage).Parse(); + var parsed = new JsonWithStorageParser(json, storage).Parse(); - using (var context = new ImporterContext(data)) + using (var context = new ImporterContext(parsed)) using (var loaded = context.Load()) { Assert.AreEqual(1, loaded.transform.GetChildren().Count()); @@ -674,9 +676,10 @@ namespace UniGLTF Assert.True(vs.All(x => x.CanExport)); // export - var gltf = new glTF(); + var data = new ExportingGltfData(); + var gltf = data.GLTF; string json; - using (var exporter = new gltfExporter(gltf, new GltfExportSettings())) + using (var exporter = new gltfExporter(data, new GltfExportSettings())) { exporter.Prepare(root); exporter.Export(new EditorTextureSerializer()); @@ -692,9 +695,9 @@ namespace UniGLTF // import { var storage = new SimpleStorage(new ArraySegment(new byte[1024 * 1024])); - var data = new JsonWithStorageParser(json, storage).Parse(); + var parsed = new JsonWithStorageParser(json, storage).Parse(); - using (var context = new ImporterContext(data)) + using (var context = new ImporterContext(parsed)) using (var loaded = context.Load()) { Assert.AreEqual(2, loaded.transform.GetChildren().Count()); diff --git a/Assets/VRM/Editor/Format/VRMEditorExporter.cs b/Assets/VRM/Editor/Format/VRMEditorExporter.cs index 419912b1b..4003ba880 100644 --- a/Assets/VRM/Editor/Format/VRMEditorExporter.cs +++ b/Assets/VRM/Editor/Format/VRMEditorExporter.cs @@ -222,14 +222,13 @@ namespace VRM // 出力 var sw = System.Diagnostics.Stopwatch.StartNew(); - var gltf = new UniGLTF.glTF(); - ExportingGltfData writer = default; - using (var exporter = new VRMExporter(gltf, settings.MeshExportSettings)) + var data = new UniGLTF.ExportingGltfData(); + using (var exporter = new VRMExporter(data, settings.MeshExportSettings)) { exporter.Prepare(target); - writer = exporter.Export(new EditorTextureSerializer()); + exporter.Export(new EditorTextureSerializer()); } - var bytes = writer.ToGlbBytes(); + var bytes = data.ToGlbBytes(); Debug.LogFormat("Export elapsed {0}", sw.Elapsed); return bytes; } diff --git a/Assets/VRM/Runtime/IO/VRMExporter.cs b/Assets/VRM/Runtime/IO/VRMExporter.cs index 63903b977..741d31ad9 100644 --- a/Assets/VRM/Runtime/IO/VRMExporter.cs +++ b/Assets/VRM/Runtime/IO/VRMExporter.cs @@ -12,26 +12,27 @@ namespace VRM { public const Axes Vrm0xSpecificationInverseAxis = Axes.Z; - public static ExportingGltfData Export(GltfExportSettings configuration, GameObject go, ITextureSerializer textureSerializer) + public static ExportingGltfData Export(GltfExportSettings configuration, GameObject go, ITextureSerializer textureSerializer) { - var gltf = new glTF(); - using (var exporter = new VRMExporter(gltf, configuration)) + var data = new ExportingGltfData(); + using (var exporter = new VRMExporter(data, configuration)) { exporter.Prepare(go); - return exporter.Export(textureSerializer); + exporter.Export(textureSerializer); } + return data; } public readonly VRM.glTF_VRM_extensions VRM = new glTF_VRM_extensions(); - public VRMExporter(glTF gltf, GltfExportSettings exportSettings) : base(gltf, exportSettings) + public VRMExporter(ExportingGltfData data, GltfExportSettings exportSettings) : base(data, exportSettings) { if (exportSettings == null || exportSettings.InverseAxis != Vrm0xSpecificationInverseAxis) { throw new Exception($"VRM specification requires InverseAxis settings as {Vrm0xSpecificationInverseAxis}"); } - gltf.extensionsUsed.Add(glTF_VRM_extensions.ExtensionName); + _gltf.extensionsUsed.Add(glTF_VRM_extensions.ExtensionName); } protected override IMaterialExporter CreateMaterialExporter() @@ -117,7 +118,7 @@ namespace VRM VRM.meta.title = meta.Title; if (meta.Thumbnail != null) { - VRM.meta.texture = GltfTextureExporter.PushGltfTexture(_writer, meta.Thumbnail, ColorSpace.sRGB, textureSerializer); + VRM.meta.texture = GltfTextureExporter.PushGltfTexture(_data, meta.Thumbnail, ColorSpace.sRGB, textureSerializer); } VRM.meta.licenseType = meta.LicenseType; @@ -212,7 +213,7 @@ namespace VRM var f = new JsonFormatter(); VRMSerializer.Serialize(f, VRM); var bytes = f.GetStoreBytes(); - glTFExtensionExport.GetOrCreate(ref glTF.extensions).Add("VRM", bytes); + glTFExtensionExport.GetOrCreate(ref _gltf.extensions).Add("VRM", bytes); } } } diff --git a/Assets/VRM10/Runtime/IO/Vrm10Storage.cs b/Assets/VRM10/Runtime/IO/Vrm10Storage.cs index f863d017a..3bccfbc21 100644 --- a/Assets/VRM10/Runtime/IO/Vrm10Storage.cs +++ b/Assets/VRM10/Runtime/IO/Vrm10Storage.cs @@ -10,7 +10,7 @@ using VrmLib; namespace UniVRM10 { - public class Vrm10Storage : ExportingGltfData + public class Vrm10Storage : ExportingGltfData { UniGLTF.GltfData m_data; public UniGLTF.glTF Gltf => m_data.GLTF; @@ -24,10 +24,7 @@ namespace UniVRM10 /// /// for export /// - public Vrm10Storage() : base(new glTF - { - extensionsUsed = new List(), - }) + public Vrm10Storage() { m_data = new GltfData( string.Empty, @@ -48,7 +45,7 @@ namespace UniVRM10 /// /// /// - public Vrm10Storage(UniGLTF.GltfData data) : base(data.GLTF) + public Vrm10Storage(UniGLTF.GltfData data) { m_data = data;