From 112353d6dec5bb1d13cd7a7b030d0f4329911b0d Mon Sep 17 00:00:00 2001 From: ousttrue Date: Wed, 26 Sep 2018 00:32:56 +0900 Subject: [PATCH] Updated UniGLTF. ImporterContext constructor --- Scripts/Format/Editor/VRMImporterMenu.cs | 39 ++++++++++--------- .../Format/Editor/vrmAssetPostprocessor.cs | 10 +++-- Scripts/Format/VRMImporter.cs | 4 +- Scripts/Format/VRMImporterContext.cs | 22 ++++++++--- UniGLTF | 2 +- 5 files changed, 45 insertions(+), 32 deletions(-) diff --git a/Scripts/Format/Editor/VRMImporterMenu.cs b/Scripts/Format/Editor/VRMImporterMenu.cs index fff051aaa..28a131552 100644 --- a/Scripts/Format/Editor/VRMImporterMenu.cs +++ b/Scripts/Format/Editor/VRMImporterMenu.cs @@ -8,7 +8,7 @@ namespace VRM { public static class VRMImporterMenu { - [MenuItem(VRMVersion.VRM_VERSION + "/Import", priority =1)] + [MenuItem(VRMVersion.VRM_VERSION + "/Import", priority = 1)] static void ImportMenu() { var path = EditorUtility.OpenFilePanel("open vrm", "", "vrm"); @@ -20,7 +20,11 @@ namespace VRM if (Application.isPlaying) { // load into scene - Selection.activeGameObject = VRMImporter.LoadFromPath(path); + var context = new VRMImporterContext(); + context.Load(path); + context.ShowMeshes(); + context.EnableUpdateWhenOffscreen(); + Selection.activeGameObject = context.Root; } else { @@ -43,24 +47,21 @@ namespace VRM } // import as asset - Import(path, UnityPath.FromUnityPath(assetPath)); + var prefabPath = UnityPath.FromUnityPath(assetPath); + var context = new VRMImporterContext(); + context.ParseGlb(File.ReadAllBytes(path)); + context.SaveTexturesAsPng(prefabPath); + + EditorApplication.delayCall += () => + { + // + // after textures imported + // + context.Load(); + context.SaveAsAsset(prefabPath); + context.Destroy(false); + }; } } - - static void Import(string readPath, UnityPath prefabPath) - { - //var bytes = File.ReadAllBytes(readPath); - var context = new VRMImporterContext(UnityPath.FromFullpath(readPath)); - context.ParseGlb(File.ReadAllBytes(readPath)); - context.SaveTexturesAsPng(prefabPath); - - EditorApplication.delayCall += () => - { - // delay and can import png texture - VRMImporter.LoadFromBytes(context); - context.SaveAsAsset(prefabPath); - context.Destroy(false); - }; - } } } diff --git a/Scripts/Format/Editor/vrmAssetPostprocessor.cs b/Scripts/Format/Editor/vrmAssetPostprocessor.cs index d4a118bdb..cd184777e 100644 --- a/Scripts/Format/Editor/vrmAssetPostprocessor.cs +++ b/Scripts/Format/Editor/vrmAssetPostprocessor.cs @@ -28,16 +28,20 @@ namespace VRM { throw new Exception(); } - var context = new VRMImporterContext(path); + var context = new VRMImporterContext(); context.ParseGlb(File.ReadAllBytes(path.FullPath)); var prefabPath = path.Parent.Child(path.FileNameWithoutExtension + ".prefab"); + + // save texture assets ! context.SaveTexturesAsPng(prefabPath); EditorApplication.delayCall += () => { - // delay and can import png texture - VRMImporter.LoadFromBytes(context); + // + // after textures imported + // + context.Load(); context.SaveAsAsset(prefabPath); context.Destroy(false); }; diff --git a/Scripts/Format/VRMImporter.cs b/Scripts/Format/VRMImporter.cs index cf9950016..9950b3512 100644 --- a/Scripts/Format/VRMImporter.cs +++ b/Scripts/Format/VRMImporter.cs @@ -45,7 +45,6 @@ namespace VRM [Obsolete("use VVRMImporterContext.LoadAsync")] public static void LoadVrmAsync(string path, Action onLoaded, Action onError = null, bool show = true) { - var context = new VRMImporterContext(UnityPath.FromFullpath(path)); LoadVrmAsync(File.ReadAllBytes(path), onLoaded, onError, show); } @@ -71,12 +70,11 @@ namespace VRM public static Task LoadVrmAsync(string path, bool show = true) { - var context = new VRMImporterContext(UnityPath.FromFullpath(path)); + var context = new VRMImporterContext(); context.ParseGlb(File.ReadAllBytes(path)); return LoadVrmAsync(context, show); } - public static Task LoadVrmAsync(Byte[] bytes, bool show = true) { var context = new VRMImporterContext(); diff --git a/Scripts/Format/VRMImporterContext.cs b/Scripts/Format/VRMImporterContext.cs index 13dd4015f..2e6c74586 100644 --- a/Scripts/Format/VRMImporterContext.cs +++ b/Scripts/Format/VRMImporterContext.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Collections.Generic; using UniGLTF; using UnityEngine; - +using System.IO; namespace VRM { @@ -13,13 +13,23 @@ namespace VRM const string HUMANOID_KEY = "humanoid"; const string MATERIAL_KEY = "materialProperties"; - [Obsolete] - public VRMImporterContext(UnityPath gltfPath) : base(gltfPath) + public VRMImporterContext() { } - public VRMImporterContext() + public override void Parse(string path, byte[] bytes) { + var ext = Path.GetExtension(path).ToLower(); + switch (ext) + { + case ".vrm": + ParseGlb(bytes); + break; + + default: + base.Parse(path, bytes); + break; + } } public override void Load() @@ -57,7 +67,7 @@ namespace VRM { using (MeasureTime("texture.Process")) { - var texture = new TextureItem(GLTF, index); + var texture = new TextureItem(index); texture.Process(GLTF, Storage); return texture; } @@ -369,7 +379,7 @@ namespace VRM // 作成する(先行ロード用) if (gltfMeta.texture >= 0 && gltfMeta.texture < GLTF.textures.Count) { - var t = new TextureItem(GLTF, gltfMeta.texture); + var t = new TextureItem(gltfMeta.texture); t.Process(GLTF, Storage); meta.Thumbnail = t.Texture; } diff --git a/UniGLTF b/UniGLTF index 5595029d7..fb2176c8e 160000 --- a/UniGLTF +++ b/UniGLTF @@ -1 +1 @@ -Subproject commit 5595029d7446fa4c1a8136dc47527c87c5a89fdd +Subproject commit fb2176c8ea68d9913241292591b494d88b87ff31