mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-08-28 13:54:45 -05:00
Improved UnityPath
This commit is contained in:
@@ -46,7 +46,7 @@ public class VRMTest
|
||||
public void VRMSimpleSceneTest()
|
||||
{
|
||||
var go = CreateSimpelScene();
|
||||
var context = new VRMImporterContext(null);
|
||||
var context = new VRMImporterContext();
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
@@ -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 += () =>
|
||||
|
||||
@@ -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<GameObject> onLoaded, Action<Exception> 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<GameObject> onLoaded, Action<Exception> 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;
|
||||
})
|
||||
|
||||
@@ -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<VRMMetaObject>();
|
||||
var meta = ScriptableObject.CreateInstance<VRMMetaObject>();
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
2
UniGLTF
2
UniGLTF
Submodule UniGLTF updated: 1a7612a866...e045f2aff8
Reference in New Issue
Block a user