From 48c7c856a30ec1503c2294f72242a119d4f88c62 Mon Sep 17 00:00:00 2001 From: Masataka SUMI Date: Tue, 21 May 2024 12:10:21 +0900 Subject: [PATCH 1/3] Run parsing of vrm files on a thread pool. --- Assets/VRM10/Runtime/IO/Vrm10.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Assets/VRM10/Runtime/IO/Vrm10.cs b/Assets/VRM10/Runtime/IO/Vrm10.cs index 27be68bf4..fc636e5c5 100644 --- a/Assets/VRM10/Runtime/IO/Vrm10.cs +++ b/Assets/VRM10/Runtime/IO/Vrm10.cs @@ -52,7 +52,11 @@ namespace UniVRM10 ? new RuntimeOnlyAwaitCaller() : new ImmediateCaller(); - using var gltfData = new GlbLowLevelParser(path, await File.ReadAllBytesAsync(path, ct)).Parse(); + using var gltfData = await awaitCaller.Run(() => + { + var bytes = File.ReadAllBytes(path); + return new GlbLowLevelParser(path, bytes).Parse(); + }); return await LoadAsync( gltfData, canLoadVrm0X, @@ -96,7 +100,7 @@ namespace UniVRM10 ? new RuntimeOnlyAwaitCaller() : new ImmediateCaller(); - using var gltfData = new GlbLowLevelParser(string.Empty, bytes).Parse(); + using var gltfData = await awaitCaller.Run(() => new GlbLowLevelParser(string.Empty, bytes).Parse()); return await LoadAsync( gltfData, canLoadVrm0X, From 551ad8e3f2e8d52d28b9f0a6e5208724f9171563 Mon Sep 17 00:00:00 2001 From: Masataka SUMI Date: Tue, 21 May 2024 12:29:29 +0900 Subject: [PATCH 2/3] Add the test whether the load function can finish synchronously. --- Assets/VRM10/Tests/Vrm10ApiTests.cs | 22 ++++++++++++++++++++++ Assets/VRM10/Tests/Vrm10ApiTests.cs.meta | 3 +++ 2 files changed, 25 insertions(+) create mode 100644 Assets/VRM10/Tests/Vrm10ApiTests.cs create mode 100644 Assets/VRM10/Tests/Vrm10ApiTests.cs.meta diff --git a/Assets/VRM10/Tests/Vrm10ApiTests.cs b/Assets/VRM10/Tests/Vrm10ApiTests.cs new file mode 100644 index 000000000..c554c56d4 --- /dev/null +++ b/Assets/VRM10/Tests/Vrm10ApiTests.cs @@ -0,0 +1,22 @@ +using System.Threading.Tasks; +using NUnit.Framework; +using UniVRM10; +using VRMShaders; + +namespace VRM10.Tests +{ + public sealed class Vrm10ApiTests + { + [Test] + public void LoadImmediately() + { + var loadTask = Vrm10.LoadPathAsync( + TestAsset.AliciaPath, + canLoadVrm0X: true, + awaitCaller: new ImmediateCaller() + ); + + Assert.AreEqual(true, loadTask.IsCompleted); + } + } +} \ No newline at end of file diff --git a/Assets/VRM10/Tests/Vrm10ApiTests.cs.meta b/Assets/VRM10/Tests/Vrm10ApiTests.cs.meta new file mode 100644 index 000000000..0cda7db50 --- /dev/null +++ b/Assets/VRM10/Tests/Vrm10ApiTests.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 6bf6de3c68bf4a5994e2b5739f60b913 +timeCreated: 1716261790 \ No newline at end of file From 90c9f99e3f7a40e450e6c3edb42e7daa3be0ec10 Mon Sep 17 00:00:00 2001 From: Masataka SUMI Date: Tue, 21 May 2024 12:30:59 +0900 Subject: [PATCH 3/3] fix namespace --- Assets/VRM10/Tests/Vrm10ApiTests.cs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Assets/VRM10/Tests/Vrm10ApiTests.cs b/Assets/VRM10/Tests/Vrm10ApiTests.cs index c554c56d4..d29dcd45c 100644 --- a/Assets/VRM10/Tests/Vrm10ApiTests.cs +++ b/Assets/VRM10/Tests/Vrm10ApiTests.cs @@ -1,9 +1,7 @@ -using System.Threading.Tasks; -using NUnit.Framework; -using UniVRM10; +using NUnit.Framework; using VRMShaders; -namespace VRM10.Tests +namespace UniVRM10.Test { public sealed class Vrm10ApiTests {