diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/ImporterContext.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/ImporterContext.cs
index bc9828bfb..32ee65408 100644
--- a/Assets/UniGLTF/Runtime/UniGLTF/IO/ImporterContext.cs
+++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/ImporterContext.cs
@@ -12,76 +12,11 @@ using UnityEditor;
namespace UniGLTF
{
-
-
///
/// GLTF importer
///
public class ImporterContext : IDisposable
{
- #region MeasureTime
- bool m_showSpeedLog
-#if VRM_DEVELOP
- = true
-#endif
- ;
- public bool ShowSpeedLog
- {
- set { m_showSpeedLog = value; }
- }
-
- public struct KeyElapsed
- {
- public string Key;
- public TimeSpan Elapsed;
- public KeyElapsed(string key, TimeSpan elapsed)
- {
- Key = key;
- Elapsed = elapsed;
- }
- }
-
- public struct MeasureScope : IDisposable
- {
- Action m_onDispose;
- public MeasureScope(Action onDispose)
- {
- m_onDispose = onDispose;
- }
- public void Dispose()
- {
- m_onDispose();
- }
- }
-
- public List m_speedReports = new List();
-
- public IDisposable MeasureTime(string key)
- {
- var sw = System.Diagnostics.Stopwatch.StartNew();
- return new MeasureScope(() =>
- {
- m_speedReports.Add(new KeyElapsed(key, sw.Elapsed));
- });
- }
-
- public string GetSpeedLog()
- {
- var total = TimeSpan.Zero;
-
- var sb = new StringBuilder();
- sb.AppendLine("【SpeedLog】");
- foreach (var kv in m_speedReports)
- {
- sb.AppendLine(string.Format("{0}: {1}ms", kv.Key, (int)kv.Elapsed.TotalMilliseconds));
- total += kv.Elapsed;
- }
- sb.AppendLine(string.Format("total: {0}ms", (int)total.TotalMilliseconds));
-
- return sb.ToString();
- }
- #endregion
-
#region Animation
protected IAnimationImporter m_animationImporter;
public void SetAnimationImporter(IAnimationImporter animationImporter)
@@ -355,11 +290,16 @@ namespace UniGLTF
public bool EnableLoadBalancing;
- public virtual async Awaitable LoadAsync()
+ public virtual async Awaitable LoadAsync(Func MeasureTime = null)
{
+ if (MeasureTime == null)
+ {
+ MeasureTime = new ImporterContextSpeedLog().MeasureTime;
+ }
+
if (Root == null)
{
- Root = new GameObject("_root_");
+ Root = new GameObject("GLTF");
}
// UniGLTF does not support draco
@@ -379,7 +319,7 @@ namespace UniGLTF
using (MeasureTime("ReadMesh"))
{
var x = meshImporter.ReadMesh(this, index);
- var y = await BuildMeshAsync(x, index);
+ var y = await BuildMeshAsync(MeasureTime, x, index);
Meshes.Add(y);
}
}
@@ -423,21 +363,15 @@ namespace UniGLTF
AnimationImporter.Import(this);
}
- await OnLoadModel();
-
- if (m_showSpeedLog)
- {
- Debug.Log(GetSpeedLog());
- }
+ await OnLoadModel(MeasureTime);
}
- protected virtual async Awaitable OnLoadModel()
+ protected virtual async Awaitable OnLoadModel(Func MeasureTime)
{
- Root.name = "GLTF";
- await LoopAwaitable.Create();
+ // do nothing
}
- async Awaitable BuildMeshAsync(MeshImporter.MeshContext x, int i)
+ async Awaitable BuildMeshAsync(Func MeasureTime, MeshImporter.MeshContext x, int i)
{
using (MeasureTime("BuildMesh"))
{
diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/ImporterContextExtensions.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/ImporterContextExtensions.cs
index 04f1c2e98..88ef55e69 100644
--- a/Assets/UniGLTF/Runtime/UniGLTF/IO/ImporterContextExtensions.cs
+++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/ImporterContextExtensions.cs
@@ -1,5 +1,6 @@
using System.IO;
using UniGLTF.AltTask;
+using UnityEngine;
namespace UniGLTF
{
@@ -32,9 +33,10 @@ namespace UniGLTF
///
public static void Load(this ImporterContext self)
{
+ var meassureTime = new ImporterContextSpeedLog();
using (var queue = TaskQueue.Create())
{
- var task = self.LoadAsync();
+ var task = self.LoadAsync(meassureTime.MeasureTime);
// 中断された await を消化する
while (!task.IsCompleted)
@@ -43,6 +45,10 @@ namespace UniGLTF
queue.ExecuteOneCallback();
}
}
+
+#if VRM_DEVELOP
+ Debug.Log(meassureTime.GetSpeedLog());
+#endif
}
}
}
diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/ImporterContextSpeedLog.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/ImporterContextSpeedLog.cs
new file mode 100644
index 000000000..db3c45561
--- /dev/null
+++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/ImporterContextSpeedLog.cs
@@ -0,0 +1,60 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace UniGLTF
+{
+ public class ImporterContextSpeedLog
+ {
+ public struct KeyElapsed
+ {
+ public string Key;
+ public TimeSpan Elapsed;
+ public KeyElapsed(string key, TimeSpan elapsed)
+ {
+ Key = key;
+ Elapsed = elapsed;
+ }
+ }
+
+ public struct MeasureScope : IDisposable
+ {
+ Action m_onDispose;
+ public MeasureScope(Action onDispose)
+ {
+ m_onDispose = onDispose;
+ }
+ public void Dispose()
+ {
+ m_onDispose();
+ }
+ }
+
+ public List m_speedReports = new List();
+
+ public IDisposable MeasureTime(string key)
+ {
+ var sw = System.Diagnostics.Stopwatch.StartNew();
+ return new MeasureScope(() =>
+ {
+ m_speedReports.Add(new KeyElapsed(key, sw.Elapsed));
+ });
+ }
+
+ public string GetSpeedLog()
+ {
+ var total = TimeSpan.Zero;
+
+ var sb = new StringBuilder();
+ sb.AppendLine("【SpeedLog】");
+ foreach (var kv in m_speedReports)
+ {
+ sb.AppendLine(string.Format("{0}: {1}ms", kv.Key, (int)kv.Elapsed.TotalMilliseconds));
+ total += kv.Elapsed;
+ }
+ sb.AppendLine(string.Format("total: {0}ms", (int)total.TotalMilliseconds));
+
+ return sb.ToString();
+ }
+ }
+}
diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/ImporterContextSpeedLog.cs.meta b/Assets/UniGLTF/Runtime/UniGLTF/IO/ImporterContextSpeedLog.cs.meta
new file mode 100644
index 000000000..1df8a4951
--- /dev/null
+++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/ImporterContextSpeedLog.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: e99bb16028e30ce4b972caecca5343b1
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/VRM/Runtime/IO/VRMImporterContext.cs b/Assets/VRM/Runtime/IO/VRMImporterContext.cs
index a3ae2051c..428368341 100644
--- a/Assets/VRM/Runtime/IO/VRMImporterContext.cs
+++ b/Assets/VRM/Runtime/IO/VRMImporterContext.cs
@@ -53,7 +53,7 @@ namespace VRM
}
#region OnLoad
- protected override async Awaitable OnLoadModel()
+ protected override async Awaitable OnLoadModel(Func MeasureTime)
{
Root.name = "VRM";