fix Dispose

This commit is contained in:
ousttrue
2021-03-08 19:47:52 +09:00
parent 538f6fa919
commit 3a7fc7735e
15 changed files with 119 additions and 2112 deletions

View File

@@ -50,16 +50,18 @@ namespace VRM.Samples
var parser = new GltfParser();
parser.ParseGlb(bytes);
var context = new VRMImporterContext(parser);
using (var context = new VRMImporterContext(parser))
{
// metaを取得(todo: thumbnailテクスチャのロード)
var meta = await context.ReadMetaAsync();
Debug.LogFormat("meta: title:{0}", meta.Title);
// metaを取得(todo: thumbnailテクスチャのロード)
var meta = await context.ReadMetaAsync();
Debug.LogFormat("meta: title:{0}", meta.Title);
// ParseしたJSONをシーンオブジェクトに変換していく
await context.LoadAsync();
// ParseしたJSONをシーンオブジェクトに変換していく
await context.LoadAsync();
OnLoaded(context);
OnLoaded(context);
}
}
void OnLoaded(VRMImporterContext context)

View File

@@ -90,23 +90,24 @@ namespace VRM.Samples
var parser = new GltfParser();
parser.Parse(path, bytes);
var context = new VRMImporterContext(parser);
// metaを取得(todo: thumbnailテクスチャのロード)
var meta = await context.ReadMetaAsync();
Debug.LogFormat("meta: title:{0}", meta.Title);
// ParseしたJSONをシーンオブジェクトに変換していく
if (m_loadAsync)
using (var context = new VRMImporterContext(parser))
{
await context.LoadAsync();
}
else
{
context.Load();
}
// metaを取得(todo: thumbnailテクスチャのロード)
var meta = await context.ReadMetaAsync();
Debug.LogFormat("meta: title:{0}", meta.Title);
OnLoaded(context);
// ParseしたJSONをシーンオブジェクトに変換していく
if (m_loadAsync)
{
await context.LoadAsync();
}
else
{
context.Load();
}
OnLoaded(context);
}
}
/// <summary>
@@ -167,10 +168,12 @@ namespace VRM.Samples
void OnLoaded(VRMImporterContext context)
{
var root = context.Root;
root.transform.SetParent(transform, false);
//メッシュを表示します
context.ShowMeshes();
context.DisposeOnGameObjectDestroyed();
// add motion
var humanPoseTransfer = root.AddComponent<UniHumanoid.HumanPoseTransfer>();

View File

@@ -1,188 +0,0 @@
#pragma warning disable 0414
using System;
using System.IO;
using UnityEngine;
#if (NET_4_6 && UNITY_2017_1_OR_NEWER)
using System.Threading.Tasks;
#endif
namespace VRM.Samples
{
public class VRMRuntimeLoaderNet4 : MonoBehaviour
{
[SerializeField, Header("GUI")]
CanvasManager m_canvas;
[SerializeField]
LookTarget m_faceCamera;
[SerializeField, Header("loader")]
UniHumanoid.HumanPoseTransfer m_source;
[SerializeField]
UniHumanoid.HumanPoseTransfer m_target;
[SerializeField, Header("runtime")]
VRMFirstPerson m_firstPerson;
#if (NET_4_6 && UNITY_2017_1_OR_NEWER && !UNITY_WEBGL)
VRMBlendShapeProxy m_blendShape;
void SetupTarget()
{
if (m_target != null)
{
m_target.Source = m_source;
m_target.SourceType = UniHumanoid.HumanPoseTransfer.HumanPoseTransferSourceType.HumanPoseTransfer;
m_blendShape = m_target.GetComponent<VRMBlendShapeProxy>();
m_firstPerson = m_target.GetComponent<VRMFirstPerson>();
var animator = m_target.GetComponent<Animator>();
if (animator != null)
{
m_firstPerson.Setup();
if (m_faceCamera != null)
{
m_faceCamera.Target = animator.GetBoneTransform(HumanBodyBones.Head);
}
}
}
}
private void Awake()
{
SetupTarget();
}
private void Start()
{
if (m_canvas == null)
{
Debug.LogWarning("no canvas");
return;
}
m_canvas.LoadVRMButton.onClick.AddListener(LoadVRMClicked);
m_canvas.LoadBVHButton.onClick.AddListener(LoadBVHClicked);
}
// Byte列を得る
async static Task<Byte[]> ReadBytesAsync(string path)
{
return File.ReadAllBytes(path);
}
async static Task<VRMImporterContext> LoadAsync(Byte[] bytes)
{
var context = new VRMImporterContext();
// GLB形式でJSONを取得しParseします
context.ParseGlb(bytes);
// ParseしたJSONをシーンオブジェクトに変換していく
await context.LoadAsyncTask();
return context;
}
/// <summary>
/// Taskで非同期にロードする例
/// </summary>
async void LoadVRMClicked()
{
#if UNITY_STANDALONE_WIN
var path = FileDialogForWindows.FileDialog("open VRM", ".vrm");
#elif UNITY_EDITOR
var path = UnityEditor.EditorUtility.OpenFilePanel("Open VRM", "", "vrm");
#else
var path = Application.dataPath + "/default.vrm";
#endif
if (string.IsNullOrEmpty(path))
{
return;
}
var context = new VRMImporterContext();
var bytes = await ReadBytesAsync(path);
// GLB形式でJSONを取得しParseします
context.ParseGlb(bytes);
// metaを取得(todo: thumbnailテクスチャのロード)
var meta = context.ReadMeta();
Debug.LogFormat("meta: title:{0}", meta.Title);
// ParseしたJSONをシーンオブジェクトに変換していく
var now = Time.time;
await context.LoadAsyncTask();
var delta = Time.time - now;
Debug.LogFormat("LoadVrmAsync {0:0.0} seconds", delta);
OnLoaded(context);
}
void LoadBVHClicked()
{
#if UNITY_STANDALONE_WIN
var path = FileDialogForWindows.FileDialog("open BVH", ".bvh");
if (!string.IsNullOrEmpty(path))
{
LoadBvh(path);
}
#elif UNITY_EDITOR
var path = UnityEditor.EditorUtility.OpenFilePanel("Open BVH", "", "bvh");
if (!string.IsNullOrEmpty(path))
{
LoadBvh(path);
}
#else
LoadBvh(Application.dataPath + "/default.bvh");
#endif
}
void OnLoaded(VRMImporterContext context)
{
var root = context.Root;
root.transform.SetParent(transform, false);
//メッシュを表示します
context.ShowMeshes();
// add motion
var humanPoseTransfer = root.AddComponent<UniHumanoid.HumanPoseTransfer>();
if (m_target != null)
{
GameObject.Destroy(m_target.gameObject);
}
m_target = humanPoseTransfer;
SetupTarget();
}
void LoadBvh(string path)
{
Debug.LogFormat("ImportBvh: {0}", path);
var context = new UniHumanoid.BvhImporterContext();
context.Parse(path);
context.Load();
if (m_source != null)
{
GameObject.Destroy(m_source.gameObject);
}
m_source = context.Root.GetComponent<UniHumanoid.HumanPoseTransfer>();
SetupTarget();
}
#endif
}
}

View File

@@ -1,12 +0,0 @@
fileFormatVersion: 2
guid: 649886f2803ade846a93be89f73e35c7
timeCreated: 1517899576
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -314,15 +314,15 @@ namespace VRM.Samples
var parser = new GltfParser();
parser.ParseGlb(file);
var context = new VRMImporterContext(parser);
await m_texts.UpdateMetaAsync(context);
await context.LoadAsync();
context.DisposeOnGameObjectDestroyed();
context.ShowMeshes();
context.EnableUpdateWhenOffscreen();
context.ShowMeshes();
SetModel(context.Root);
using (var context = new VRMImporterContext(parser))
{
await m_texts.UpdateMetaAsync(context);
await context.LoadAsync();
context.EnableUpdateWhenOffscreen();
context.ShowMeshes();
context.DisposeOnGameObjectDestroyed();
SetModel(context.Root);
}
break;
}
@@ -334,10 +334,9 @@ namespace VRM.Samples
var context = new UniGLTF.ImporterContext(parser);
context.Load();
context.DisposeOnGameObjectDestroyed();
context.ShowMeshes();
context.EnableUpdateWhenOffscreen();
context.ShowMeshes();
context.DisposeOnGameObjectDestroyed();
SetModel(context.Root);
break;
}
@@ -350,10 +349,9 @@ namespace VRM.Samples
var context = new UniGLTF.ImporterContext(parser);
context.Load();
context.DisposeOnGameObjectDestroyed();
context.ShowMeshes();
context.EnableUpdateWhenOffscreen();
context.ShowMeshes();
context.DisposeOnGameObjectDestroyed();
SetModel(context.Root);
break;
}