From 31bcc4eb7e9b017740662517be99212420f72d0d Mon Sep 17 00:00:00 2001 From: ousttrue Date: Tue, 24 Jul 2018 04:15:34 +0900 Subject: [PATCH] Improved UnityPath --- Scripts/Editor/VRMTest.cs | 2 +- Scripts/Format/Editor/vrmAssetPostprocessor.cs | 15 ++++++++++----- Scripts/Format/VRMImporter.cs | 12 ++++++------ Scripts/Format/VRMImporterContext.cs | 12 ++++++------ UniGLTF | 2 +- 5 files changed, 24 insertions(+), 19 deletions(-) diff --git a/Scripts/Editor/VRMTest.cs b/Scripts/Editor/VRMTest.cs index a9c5d78d7..a0b02d8f3 100644 --- a/Scripts/Editor/VRMTest.cs +++ b/Scripts/Editor/VRMTest.cs @@ -46,7 +46,7 @@ public class VRMTest public void VRMSimpleSceneTest() { var go = CreateSimpelScene(); - var context = new VRMImporterContext(null); + var context = new VRMImporterContext(); try { diff --git a/Scripts/Format/Editor/vrmAssetPostprocessor.cs b/Scripts/Format/Editor/vrmAssetPostprocessor.cs index 34bc5ad24..d4a118bdb 100644 --- a/Scripts/Format/Editor/vrmAssetPostprocessor.cs +++ b/Scripts/Format/Editor/vrmAssetPostprocessor.cs @@ -1,4 +1,5 @@ -using System.IO; +using System; +using System.IO; using System.Linq; using UniGLTF; using UnityEditor; @@ -16,17 +17,21 @@ namespace VRM var ext = Path.GetExtension(path).ToLower(); if (ext == ".vrm") { - ImportVrm(path); + ImportVrm(UnityPath.FromUnityPath(path)); } } } - static void ImportVrm(string path) + static void ImportVrm(UnityPath path) { + if (!path.IsUnderAssetsFolder) + { + throw new Exception(); + } var context = new VRMImporterContext(path); - context.ParseGlb(File.ReadAllBytes(path)); + context.ParseGlb(File.ReadAllBytes(path.FullPath)); - var prefabPath = (Path.GetDirectoryName(path) + "/" + Path.GetFileNameWithoutExtension(path) + ".prefab").Replace("\\", "/"); + var prefabPath = path.Parent.Child(path.FileNameWithoutExtension + ".prefab"); context.SaveTexturesAsPng(prefabPath); EditorApplication.delayCall += () => diff --git a/Scripts/Format/VRMImporter.cs b/Scripts/Format/VRMImporter.cs index 97ae4e1bc..036da15f2 100644 --- a/Scripts/Format/VRMImporter.cs +++ b/Scripts/Format/VRMImporter.cs @@ -20,7 +20,7 @@ namespace VRM public static GameObject LoadFromPath(string path) { - var context = new VRMImporterContext(path); + var context = new VRMImporterContext(UniGLTF.UnityPath.FromFullpath(path)); context.ParseGlb(File.ReadAllBytes(path)); LoadFromBytes(context); return context.Root; @@ -28,7 +28,7 @@ namespace VRM public static GameObject LoadFromBytes(Byte[] bytes) { - var context = new VRMImporterContext(null); + var context = new VRMImporterContext(); context.ParseGlb(bytes); LoadFromBytes(context); return context.Root; @@ -388,7 +388,7 @@ namespace VRM { for (int i = 0; i < context.GLTF.textures.Count; ++i) { - var x = new TextureItem(context.GLTF, i, null); + var x = new TextureItem(context.GLTF, i); x.Process(context.GLTF, storage); context.Textures.Add(x); yield return null; @@ -490,14 +490,14 @@ namespace VRM public static void LoadVrmAsync(string path, Action onLoaded, Action onError = null, bool show = true) { - var context = new VRMImporterContext(path); + var context = new VRMImporterContext(UnityPath.FromFullpath(path)); context.ParseGlb(File.ReadAllBytes(path)); LoadVrmAsync(context, onLoaded, onError, show); } public static void LoadVrmAsync(Byte[] bytes, Action onLoaded, Action onError = null, bool show = true) { - var context = new VRMImporterContext(null); + var context = new VRMImporterContext(); context.ParseGlb(bytes); LoadVrmAsync(context, onLoaded, onError, show); } @@ -535,7 +535,7 @@ namespace VRM parent.AddTask(Scheduler.MainThread, () => { - var texture = new TextureItem(ctx.GLTF, index, null); + var texture = new TextureItem(ctx.GLTF, index); texture.Process(ctx.GLTF, ctx.Storage); return texture; }) diff --git a/Scripts/Format/VRMImporterContext.cs b/Scripts/Format/VRMImporterContext.cs index fa2b50d79..a1c5a3506 100644 --- a/Scripts/Format/VRMImporterContext.cs +++ b/Scripts/Format/VRMImporterContext.cs @@ -7,7 +7,7 @@ namespace VRM { public class VRMImporterContext : ImporterContext { - public VRMImporterContext(string path):base(path) + public VRMImporterContext(UnityPath gltfPath = default(UnityPath)) : base(gltfPath) { } @@ -16,9 +16,9 @@ namespace VRM public BlendShapeAvatar BlendShapeAvatar; public VRMMetaObject Meta; - public VRMMetaObject ReadMeta(bool createThumbnail=false) + public VRMMetaObject ReadMeta(bool createThumbnail = false) { - var meta=ScriptableObject.CreateInstance(); + var meta = ScriptableObject.CreateInstance(); meta.name = "Meta"; meta.ExporterVersion = GLTF.extensions.VRM.exporterVersion; @@ -37,11 +37,11 @@ namespace VRM else if (createThumbnail) { // 作成する(先行ロード用) - if(gltfMeta.texture >= 0 && gltfMeta.texture < GLTF.textures.Count) + if (gltfMeta.texture >= 0 && gltfMeta.texture < GLTF.textures.Count) { - var t = new TextureItem(GLTF, gltfMeta.texture, null); + var t = new TextureItem(GLTF, gltfMeta.texture); t.Process(GLTF, Storage); - meta.Thumbnail=t.Texture; + meta.Thumbnail = t.Texture; } } diff --git a/UniGLTF b/UniGLTF index 1a7612a86..e045f2aff 160000 --- a/UniGLTF +++ b/UniGLTF @@ -1 +1 @@ -Subproject commit 1a7612a866487b5a442e93d390ec62a9b1d93961 +Subproject commit e045f2aff8aca0c86ed761a1b0edff3a9c938174