diff --git a/Assets/VRM.Samples/Editor/Tests/VRMImportExportTests.cs b/Assets/VRM.Samples/Editor/Tests/VRMImportExportTests.cs index 6f3ec5721..ce0da3f13 100644 --- a/Assets/VRM.Samples/Editor/Tests/VRMImportExportTests.cs +++ b/Assets/VRM.Samples/Editor/Tests/VRMImportExportTests.cs @@ -81,7 +81,7 @@ namespace VRM.Samples */ importedJson.RemoveValue(Utf8String.From("/bufferViews/*/byteStride")); - var vrm = VRMExporter.Export(context.Root); + var vrm = VRMExporter.Export(UniGLTF.MeshExportSettings.Default, context.Root); // TODO: Check contents in JSON /*var exportJson = */ diff --git a/Assets/VRM.Samples/Scripts/VRMRuntimeExporter.cs b/Assets/VRM.Samples/Scripts/VRMRuntimeExporter.cs index 63a64740d..519b9dbee 100644 --- a/Assets/VRM.Samples/Scripts/VRMRuntimeExporter.cs +++ b/Assets/VRM.Samples/Scripts/VRMRuntimeExporter.cs @@ -90,7 +90,7 @@ namespace VRM.Samples return; } - var vrm = VRMExporter.Export(m_model); + var vrm = VRMExporter.Export(UniGLTF.MeshExportSettings.Default, m_model); var bytes = vrm.ToGlbBytes(); File.WriteAllBytes(path, bytes); Debug.LogFormat("export to {0}", path); diff --git a/Assets/VRM/UniGLTF/Editor/Tests/UniGLTFTests.cs b/Assets/VRM/UniGLTF/Editor/Tests/UniGLTFTests.cs index 1db2c13fa..0c090fecf 100644 --- a/Assets/VRM/UniGLTF/Editor/Tests/UniGLTFTests.cs +++ b/Assets/VRM/UniGLTF/Editor/Tests/UniGLTFTests.cs @@ -57,7 +57,7 @@ namespace UniGLTF using (var exporter = new gltfExporter(gltf)) { exporter.Prepare(go); - exporter.Export(); + exporter.Export(MeshExportSettings.Default); // remove empty buffer gltf.buffers.Clear(); @@ -307,7 +307,7 @@ namespace UniGLTF using (var exporter = new gltfExporter(gltf)) { exporter.Prepare(CreateSimpleScene()); - exporter.Export(); + exporter.Export(MeshExportSettings.Default); } var expected = gltf.ToJson().ParseAsJson(); @@ -629,7 +629,7 @@ namespace UniGLTF using (var exporter = new gltfExporter(gltf)) { exporter.Prepare(go); - exporter.Export(); + exporter.Export(UniGLTF.MeshExportSettings.Default); json = gltf.ToJson(); } diff --git a/Assets/VRM/UniGLTF/Scripts/IO/MeshExporter.cs b/Assets/VRM/UniGLTF/Scripts/IO/MeshExporter.cs index 339e51748..90153efdd 100644 --- a/Assets/VRM/UniGLTF/Scripts/IO/MeshExporter.cs +++ b/Assets/VRM/UniGLTF/Scripts/IO/MeshExporter.cs @@ -13,6 +13,25 @@ namespace UniGLTF public Renderer Renderer; } + public struct MeshExportSettings + { + // MorphTarget に Sparse Accessor を使う + public bool UseSparseAccessorForMorphTarget; + + // MorphTarget を Position だけにする(normal とか捨てる) + public bool ExportOnlyBlendShapePosition; + + // VertexColor が存在していても捨てる + public bool RemoveVertexColor; + + public static MeshExportSettings Default => new MeshExportSettings + { + UseSparseAccessorForMorphTarget = false, + ExportOnlyBlendShapePosition = false, + RemoveVertexColor = false, + }; + } + public static class MeshExporter { static glTFMesh ExportPrimitives(glTF gltf, int bufferIndex, @@ -234,9 +253,7 @@ namespace UniGLTF public static IEnumerable<(Mesh, glTFMesh, Dictionary)> ExportMeshes(glTF gltf, int bufferIndex, List unityMeshes, List unityMaterials, - bool useSparseAccessorForMorphTarget, - bool exportOnlyBlendShapePosition, - bool removeVertexColor) + MeshExportSettings settings) { for (int i = 0; i < unityMeshes.Count; ++i) { @@ -246,7 +263,7 @@ namespace UniGLTF var gltfMesh = ExportPrimitives(gltf, bufferIndex, x.Renderer.name, - mesh, materials, unityMaterials, removeVertexColor); + mesh, materials, unityMaterials, settings.RemoveVertexColor); var blendShapeIndexMap = new Dictionary(); int exportBlendShapes = 0; @@ -254,8 +271,8 @@ namespace UniGLTF { var morphTarget = ExportMorphTarget(gltf, bufferIndex, mesh, j, - useSparseAccessorForMorphTarget, - exportOnlyBlendShapePosition); + settings.UseSparseAccessorForMorphTarget, + settings.ExportOnlyBlendShapePosition); if (morphTarget.POSITION < 0 && morphTarget.NORMAL < 0 && morphTarget.TANGENT < 0) { continue; diff --git a/Assets/VRM/UniGLTF/Scripts/IO/gltfExporter.cs b/Assets/VRM/UniGLTF/Scripts/IO/gltfExporter.cs index e0605a9d0..c7790e9b6 100644 --- a/Assets/VRM/UniGLTF/Scripts/IO/gltfExporter.cs +++ b/Assets/VRM/UniGLTF/Scripts/IO/gltfExporter.cs @@ -41,7 +41,7 @@ namespace UniGLTF using (var exporter = new gltfExporter(gltf)) { exporter.Prepare(go); - exporter.Export(); + exporter.Export(MeshExportSettings.Default); } var bytes = gltf.ToGlbBytes(); File.WriteAllBytes(path, bytes); @@ -61,24 +61,6 @@ namespace UniGLTF glTF glTF; - public bool UseSparseAccessorForBlendShape - { - get; - set; - } - - public bool ExportOnlyBlendShapePosition - { - get; - set; - } - - public bool RemoveVertexColor - { - get; - set; - } - public GameObject Copy { get; @@ -147,13 +129,13 @@ namespace UniGLTF }; } - public static glTF Export(GameObject go) + public static glTF Export(GameObject go, MeshExportSettings meshExportSettings) { var gltf = new glTF(); using (var exporter = new gltfExporter(gltf)) { exporter.Prepare(go); - exporter.Export(); + exporter.Export(meshExportSettings); } return gltf; } @@ -165,9 +147,9 @@ namespace UniGLTF Copy.transform.ReverseZRecursive(); } - public void Export() + public void Export(MeshExportSettings meshExportSettings) { - FromGameObject(glTF, Copy, UseSparseAccessorForBlendShape, RemoveVertexColor); + FromGameObject(glTF, Copy, meshExportSettings); } public void Dispose() @@ -213,8 +195,7 @@ namespace UniGLTF return node; } - void FromGameObject(glTF gltf, GameObject go, bool useSparseAccessorForMorphTarget = false, - bool removeVertexColor = false) + void FromGameObject(glTF gltf, GameObject go, MeshExportSettings meshExportSettings) { var bytesBuffer = new ArrayByteBuffer(new byte[50 * 1024 * 1024]); var bufferIndex = gltf.AddBuffer(bytesBuffer); @@ -229,7 +210,6 @@ namespace UniGLTF try { - Nodes = go.transform.Traverse() .Skip(1) // exclude root object for the symmetry with the importer .ToList(); @@ -250,7 +230,6 @@ namespace UniGLTF } #endregion - #region Meshes var unityMeshes = Nodes .Select(x => new MeshWithRenderer @@ -276,8 +255,7 @@ namespace UniGLTF MeshBlendShapeIndexMap = new Dictionary>(); foreach (var (mesh, gltfMesh, blendShapeIndexMap) in MeshExporter.ExportMeshes( - gltf, bufferIndex, unityMeshes, Materials, useSparseAccessorForMorphTarget, - ExportOnlyBlendShapePosition, removeVertexColor)) + gltf, bufferIndex, unityMeshes, Materials, meshExportSettings)) { gltf.meshes.Add(gltfMesh); if (!MeshBlendShapeIndexMap.ContainsKey(mesh)) diff --git a/Assets/VRM/UniVRM/Editor/Format/VRMEditorExporter.cs b/Assets/VRM/UniVRM/Editor/Format/VRMEditorExporter.cs index d74dd2cc5..340a9074e 100644 --- a/Assets/VRM/UniVRM/Editor/Format/VRMEditorExporter.cs +++ b/Assets/VRM/UniVRM/Editor/Format/VRMEditorExporter.cs @@ -219,12 +219,7 @@ namespace VRM // 出力 { var sw = System.Diagnostics.Stopwatch.StartNew(); - var vrm = VRMExporter.Export(target, new VRMExporterConfiguration - { - UseSparseAccessorForBlendShape = settings.UseSparseAccessor, - ExportOnlyBlendShapePosition = settings.OnlyBlendshapePosition, - RemoveVertexColor = settings.RemoveVertexColor - }); + var vrm = VRMExporter.Export(target, settings.MeshExportSettings); // vrm.extensions.VRM.meta.title = settings.Title; // vrm.extensions.VRM.meta.version = settings.Version; // vrm.extensions.VRM.meta.author = settings.Author; diff --git a/Assets/VRM/UniVRM/Editor/Format/VRMExportSettings.cs b/Assets/VRM/UniVRM/Editor/Format/VRMExportSettings.cs index 154443c4a..48f4f2c9e 100644 --- a/Assets/VRM/UniVRM/Editor/Format/VRMExportSettings.cs +++ b/Assets/VRM/UniVRM/Editor/Format/VRMExportSettings.cs @@ -47,5 +47,12 @@ namespace VRM /// [Tooltip("Remove vertex color")] public bool RemoveVertexColor = false; - } + + public UniGLTF.MeshExportSettings MeshExportSettings => new UniGLTF.MeshExportSettings + { + UseSparseAccessorForMorphTarget = UseSparseAccessor, + ExportOnlyBlendShapePosition = OnlyBlendshapePosition, + RemoveVertexColor = RemoveVertexColor, + }; + } } diff --git a/Assets/VRM/UniVRM/Scripts/Format/VRMExporter.cs b/Assets/VRM/UniVRM/Scripts/Format/VRMExporter.cs index 02cc32588..1a80bc78e 100644 --- a/Assets/VRM/UniVRM/Scripts/Format/VRMExporter.cs +++ b/Assets/VRM/UniVRM/Scripts/Format/VRMExporter.cs @@ -19,34 +19,22 @@ namespace VRM gltf.extensions.VRM = new glTF_VRM_extensions(); } - public static glTF Export(GameObject go, bool exportOnlyBlendShapePosition = false) - { - var config = VRMExporterConfiguration.Default; - config.ExportOnlyBlendShapePosition = exportOnlyBlendShapePosition; - return Export(go, config); - } - - public static glTF Export(GameObject go, VRMExporterConfiguration configuration) + public static glTF Export(MeshExportSettings configuration, GameObject go) { var gltf = new glTF(); - using (var exporter = new VRMExporter(gltf) + using (var exporter = new VRMExporter(gltf)) { - UseSparseAccessorForBlendShape = configuration.UseSparseAccessorForBlendShape, - ExportOnlyBlendShapePosition = configuration.ExportOnlyBlendShapePosition, - RemoveVertexColor = configuration.RemoveVertexColor, - }) - { - _Export(gltf, exporter, go); + _Export(gltf, exporter, go, configuration); } return gltf; } - public static void _Export(glTF gltf, VRMExporter exporter, GameObject go) + static void _Export(glTF gltf, VRMExporter exporter, GameObject go, MeshExportSettings meshExportSettings) { exporter.Prepare(go); - exporter.Export(); + exporter.Export(meshExportSettings); // avatar var animator = go.GetComponent(); diff --git a/Assets/VRM/UniVRM/Scripts/Format/VRMExporterConfiguation.cs b/Assets/VRM/UniVRM/Scripts/Format/VRMExporterConfiguation.cs deleted file mode 100644 index a998a4bb1..000000000 --- a/Assets/VRM/UniVRM/Scripts/Format/VRMExporterConfiguation.cs +++ /dev/null @@ -1,16 +0,0 @@ -namespace VRM -{ - public struct VRMExporterConfiguration - { - public bool UseSparseAccessorForBlendShape; - public bool ExportOnlyBlendShapePosition; - public bool RemoveVertexColor; - - public static VRMExporterConfiguration Default => new VRMExporterConfiguration - { - UseSparseAccessorForBlendShape = true, - ExportOnlyBlendShapePosition = false, - RemoveVertexColor = false, - }; - } -} diff --git a/Assets/VRM/UniVRM/Scripts/Format/VRMExporterConfiguation.cs.meta b/Assets/VRM/UniVRM/Scripts/Format/VRMExporterConfiguation.cs.meta deleted file mode 100644 index 8073ec287..000000000 --- a/Assets/VRM/UniVRM/Scripts/Format/VRMExporterConfiguation.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 974aea88b487e5543b1c39e5a528f751 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: