diff --git a/Assets/VRM10.Samples/Runtime/ViewerUI.cs b/Assets/VRM10.Samples/Runtime/ViewerUI.cs index 3d87e4089..3fce9ec77 100644 --- a/Assets/VRM10.Samples/Runtime/ViewerUI.cs +++ b/Assets/VRM10.Samples/Runtime/ViewerUI.cs @@ -306,15 +306,15 @@ namespace UniVRM10.Samples { case ".vrm": { - // var context = new ImporterContext(); - var file = File.ReadAllBytes(path); - // context.ParseGlb(file); + var parser =new UniGLTF.GltfParser(); + parser.ParsePath(path); + // context.Load(); // context.ShowMeshes(); // context.EnableUpdateWhenOffscreen(); // context.ShowMeshes(); - var model = UniVRM10.VrmLoader.CreateVrmModel(file, new FileInfo(path)); + var model = UniVRM10.VrmLoader.CreateVrmModel(parser); // UniVRM-0.XXのコンポーネントを構築する var assets = UniVRM10.RuntimeUnityBuilder.ToUnityAsset(model, showMesh: false); diff --git a/Assets/VRM10/Editor/ScriptedImporter/VrmScriptedImporter.cs b/Assets/VRM10/Editor/ScriptedImporter/VrmScriptedImporter.cs index 71bfc5ffd..81d3a1c33 100644 --- a/Assets/VRM10/Editor/ScriptedImporter/VrmScriptedImporter.cs +++ b/Assets/VRM10/Editor/ScriptedImporter/VrmScriptedImporter.cs @@ -24,10 +24,13 @@ namespace UniVRM10 { Debug.Log("OnImportAsset to " + ctx.assetPath); + var parser = new UniGLTF.GltfParser(); + parser.ParsePath(ctx.assetPath); + try { // Create Vrm Model - VrmLib.Model model = VrmLoader.CreateVrmModel(ctx.assetPath); + VrmLib.Model model = VrmLoader.CreateVrmModel(parser); if (model == null) { // maybe VRM-0.X @@ -158,7 +161,12 @@ namespace UniVRM10 public void ExtractTextures() { - this.ExtractTextures(TextureDirName, (path) => { return VrmLoader.CreateVrmModel(path); }); + this.ExtractTextures(TextureDirName, (path) => + { + var parser = new UniGLTF.GltfParser(); + parser.ParsePath(path); + return VrmLoader.CreateVrmModel(parser); + }); AssetDatabase.ImportAsset(assetPath, ImportAssetOptions.ForceUpdate); } @@ -170,7 +178,15 @@ namespace UniVRM10 public void ExtractMaterialsAndTextures() { - this.ExtractTextures(TextureDirName, (path) => { return VrmLoader.CreateVrmModel(path); }, () => { this.ExtractAssets(MaterialDirName, ".mat"); }); + this.ExtractTextures(TextureDirName, (path) => + { + var parser = new UniGLTF.GltfParser(); + parser.ParsePath(path); + return VrmLoader.CreateVrmModel(parser); + }, () => + { + this.ExtractAssets(MaterialDirName, ".mat"); + }); AssetDatabase.ImportAsset(assetPath, ImportAssetOptions.ForceUpdate); } diff --git a/Assets/VRM10/Runtime/Scenes/Sample.cs b/Assets/VRM10/Runtime/Scenes/Sample.cs index 94ced7b0a..36a5ae82b 100644 --- a/Assets/VRM10/Runtime/Scenes/Sample.cs +++ b/Assets/VRM10/Runtime/Scenes/Sample.cs @@ -11,7 +11,10 @@ public class Sample : MonoBehaviour static UniVRM10.ModelAsset Import(byte[] bytes, FileInfo path) { - var model = UniVRM10.VrmLoader.CreateVrmModel(bytes, path); + var parser = new UniGLTF.GltfParser(); + parser.Parse(path.FullName, bytes); + + var model = UniVRM10.VrmLoader.CreateVrmModel(parser); // UniVRM-0.XXのコンポーネントを構築する var assets = UniVRM10.RuntimeUnityBuilder.ToUnityAsset(model, showMesh: false); diff --git a/Assets/VRM10/Runtime/UnityBuilder/VrmLoader.cs b/Assets/VRM10/Runtime/UnityBuilder/VrmLoader.cs index e0657d34d..cc59d996d 100644 --- a/Assets/VRM10/Runtime/UnityBuilder/VrmLoader.cs +++ b/Assets/VRM10/Runtime/UnityBuilder/VrmLoader.cs @@ -1,7 +1,5 @@ -using System; -using System.IO; +using System.IO; using VrmLib; -using UniJSON; using UniGLTF; namespace UniVRM10 @@ -11,24 +9,10 @@ namespace UniVRM10 /// public static class VrmLoader { - // TODO: - const string VRM0X_LICENSE_URL = "https://vrm-consortium.org/"; - - /// - /// Load VRM10 or VRM0x from path - /// - public static Model CreateVrmModel(string path) + public static Model CreateVrmModel(GltfParser parser) { - var bytes = File.ReadAllBytes(path); - return CreateVrmModel(bytes, new FileInfo(path)); - } - - public static Model CreateVrmModel(byte[] bytes, FileInfo path) - { - var parser = new GltfParser(); - parser.Parse(path.FullName, bytes); var storage = new Vrm10Storage(parser); - var model = ModelLoader.Load(storage, path.Name); + var model = ModelLoader.Load(storage, Path.GetFileName(parser.TargetPath)); model.ConvertCoordinate(Coordinates.Unity); return model; } diff --git a/Assets/VRM10/Tests.PlayMode/MaterialTests.cs b/Assets/VRM10/Tests.PlayMode/MaterialTests.cs index fa1a679e4..ded4007e0 100644 --- a/Assets/VRM10/Tests.PlayMode/MaterialTests.cs +++ b/Assets/VRM10/Tests.PlayMode/MaterialTests.cs @@ -43,7 +43,10 @@ namespace UniVRM10.Test private ModelAsset ToUnity(byte[] bytes) { // Vrm => Model - var model = VrmLoader.CreateVrmModel(bytes, new FileInfo("tmp.vrm")); + var parser = new UniGLTF.GltfParser(); + parser.Parse("tmp.vrm", bytes); + + var model = VrmLoader.CreateVrmModel(parser); model.RemoveSecondary(); return ToUnity(model); diff --git a/Assets/VRM10/Tests/ApiSampleTests.cs b/Assets/VRM10/Tests/ApiSampleTests.cs index b2372d1b2..a624f87c9 100644 --- a/Assets/VRM10/Tests/ApiSampleTests.cs +++ b/Assets/VRM10/Tests/ApiSampleTests.cs @@ -12,13 +12,10 @@ namespace UniVRM10.Test { var bytes = MigrationVrm.Migrate(File.ReadAllBytes(path)); - if (!UniGLTF.Glb.TryParse(bytes, out UniGLTF.Glb glb, out Exception ex)) - { - Debug.LogError($"fail to Glb.TryParse: {path} => {ex}"); - return null; - } + var parser = new UniGLTF.GltfParser(); + parser.Parse("migrated", bytes); - var model = UniVRM10.VrmLoader.CreateVrmModel(bytes, new FileInfo(path)); + var model = UniVRM10.VrmLoader.CreateVrmModel(parser); return model; }