Updated UniGLTF. ImporterContext constructor

This commit is contained in:
ousttrue 2018-09-26 00:32:56 +09:00
parent fa93df71bc
commit 112353d6de
5 changed files with 45 additions and 32 deletions

View File

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

View File

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

View File

@ -45,7 +45,6 @@ namespace VRM
[Obsolete("use VVRMImporterContext.LoadAsync")]
public static void LoadVrmAsync(string path, Action<GameObject> onLoaded, Action<Exception> 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<GameObject> 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<GameObject> LoadVrmAsync(Byte[] bytes, bool show = true)
{
var context = new VRMImporterContext();

View File

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

@ -1 +1 @@
Subproject commit 5595029d7446fa4c1a8136dc47527c87c5a89fdd
Subproject commit fb2176c8ea68d9913241292591b494d88b87ff31