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