diff --git a/Assets/VRM10/Runtime/Migration/MigrationVrm.cs b/Assets/VRM10/Runtime/Migration/MigrationVrm.cs index a368818ae..df8e005c5 100644 --- a/Assets/VRM10/Runtime/Migration/MigrationVrm.cs +++ b/Assets/VRM10/Runtime/Migration/MigrationVrm.cs @@ -15,11 +15,11 @@ namespace UniVRM10 /// static internal class MigrationVrm { - public static byte[] Migrate(byte[] vrm0bytes, VRM10ObjectMeta meta = null) + public static byte[] Migrate(byte[] vrm0bytes, VRM10ObjectMeta meta = null, Action modGltf = null) { using (var data = new GlbBinaryParser(vrm0bytes, "migration").Parse()) { - return Migrate(data, meta); + return Migrate(data, meta, modGltf); } } @@ -38,7 +38,7 @@ namespace UniVRM10 /// vrm0 をパースしたデータ /// migration 時に合成するライセンス情報 /// - public static byte[] Migrate(GltfData data, VRM10ObjectMeta meta = null) + public static byte[] Migrate(GltfData data, VRM10ObjectMeta meta = null, Action modGltf = null) { // VRM0 -> Unity var model = ModelReader.Read(data, VrmLib.Coordinates.Vrm0); @@ -54,7 +54,22 @@ namespace UniVRM10 gltf.extensionsUsed.Remove("VRM"); } - return MigrateVrm(gltf, bin, data.Json.ParseAsJson()["extensions"]["VRM"], meta); + MigrateVrm(gltf, data.Json.ParseAsJson()["extensions"]["VRM"], meta); + + if (modGltf != null) + { + modGltf(gltf); + } + + // Serialize whole glTF + ArraySegment vrm1Json = default; + { + var f = new JsonFormatter(); + GltfSerializer.Serialize(f, gltf); + vrm1Json = f.GetStoreBytes(); + } + + return Glb.Create(vrm1Json, bin).ToBytes(); } /// @@ -71,7 +86,7 @@ namespace UniVRM10 } } - static byte[] MigrateVrm(glTF gltf, ArraySegment bin, JsonNode vrm0, VRM10ObjectMeta meta) + static void MigrateVrm(glTF gltf, JsonNode vrm0, VRM10ObjectMeta meta) { var meshToNode = CreateMeshToNode(gltf); @@ -170,16 +185,6 @@ namespace UniVRM10 { MigrationMaterials.Migrate(gltf, vrm0); } - - // Serialize whole glTF - ArraySegment vrm1Json = default; - { - var f = new JsonFormatter(); - GltfSerializer.Serialize(f, gltf); - vrm1Json = f.GetStoreBytes(); - } - - return Glb.Create(vrm1Json, bin).ToBytes(); } public delegate int MeshIndexToNodeIndexFunc(int meshIndex); diff --git a/Assets/VRM10/Runtime/Migration/Migrator.cs b/Assets/VRM10/Runtime/Migration/Migrator.cs index 241a9c11c..548cf9269 100644 --- a/Assets/VRM10/Runtime/Migration/Migrator.cs +++ b/Assets/VRM10/Runtime/Migration/Migrator.cs @@ -12,7 +12,7 @@ namespace UniVRM10 /// /// (必須)外部から供給されるライセンス情報 /// - public static byte[] Migrate(byte[] vrm0bytes, VRM10ObjectMeta meta) + public static byte[] Migrate(byte[] vrm0bytes, VRM10ObjectMeta meta, Action modGltf = null) { if (meta == null) { @@ -25,7 +25,7 @@ namespace UniVRM10 throw new ArgumentException(validation.Message); } } - return MigrationVrm.Migrate(vrm0bytes, meta); + return MigrationVrm.Migrate(vrm0bytes, meta, modGltf); } } } \ No newline at end of file diff --git a/Assets/VRM_0x_and_10_Samples/MigrateExporter/MigrateExporter.cs b/Assets/VRM_0x_and_10_Samples/MigrateExporter/MigrateExporter.cs index 244008d24..afcd98781 100644 --- a/Assets/VRM_0x_and_10_Samples/MigrateExporter/MigrateExporter.cs +++ b/Assets/VRM_0x_and_10_Samples/MigrateExporter/MigrateExporter.cs @@ -46,7 +46,10 @@ namespace UniVRM10.Sample var vrm0bytes = vrm0.ToGlbBytes(); // migrate to vrm1 - var vrm1Bytes = UniVRM10.Migrator.Migrate(vrm0bytes, _meta); + var vrm1Bytes = UniVRM10.Migrator.Migrate(vrm0bytes, _meta, gltf => + { + gltf.asset.generator = "MigrateExporter sample"; + }); var pathObj = VRMShaders.PathObject.FromFullPath(path); var newPath = pathObj.Parent.Child(pathObj.Stem + ".10.vrm"); newPath.WriteAllBytes(vrm1Bytes);