Merge pull request #1878 from ousttrue/feature10/migrate_mod

modGltf 引き数を追加
This commit is contained in:
ousttrue 2022-10-25 15:26:56 +09:00 committed by GitHub
commit 5d43f4b79e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 18 deletions

View File

@ -15,11 +15,11 @@ namespace UniVRM10
/// </summary>
static internal class MigrationVrm
{
public static byte[] Migrate(byte[] vrm0bytes, VRM10ObjectMeta meta = null)
public static byte[] Migrate(byte[] vrm0bytes, VRM10ObjectMeta meta = null, Action<UniGLTF.glTF> 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
/// <param name="data">vrm0 をパースしたデータ</param>
/// <param name="meta">migration 時に合成するライセンス情報</param>
/// <returns></returns>
public static byte[] Migrate(GltfData data, VRM10ObjectMeta meta = null)
public static byte[] Migrate(GltfData data, VRM10ObjectMeta meta = null, Action<UniGLTF.glTF> 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<byte> vrm1Json = default;
{
var f = new JsonFormatter();
GltfSerializer.Serialize(f, gltf);
vrm1Json = f.GetStoreBytes();
}
return Glb.Create(vrm1Json, bin).ToBytes();
}
/// <summary>
@ -71,7 +86,7 @@ namespace UniVRM10
}
}
static byte[] MigrateVrm(glTF gltf, ArraySegment<byte> 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<byte> 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);

View File

@ -12,7 +12,7 @@ namespace UniVRM10
/// <param name="vrm0bytes"></param>
/// <param name="meta">(必須)外部から供給されるライセンス情報</param>
/// <returns></returns>
public static byte[] Migrate(byte[] vrm0bytes, VRM10ObjectMeta meta)
public static byte[] Migrate(byte[] vrm0bytes, VRM10ObjectMeta meta, Action<UniGLTF.glTF> 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);
}
}
}

View File

@ -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);