From 135ec7a0da5406d7500688bd8af2bd1bcbf123c0 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Fri, 25 Oct 2024 14:09:31 +0900 Subject: [PATCH 1/2] =?UTF-8?q?SpringboneRuntime=20=E3=81=8C=20null=20?= =?UTF-8?q?=E3=81=A0=E3=81=A8=E3=80=80NullReference=20Exception?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit SpringboneRuntime が null になるのは、scene 配置 play の時だけ。 --- .../Components/Vrm10Instance/Vrm10Instance.cs | 56 ++++++++++++------- Assets/VRM10/Runtime/IO/Vrm10Importer.cs | 28 ++++------ 2 files changed, 49 insertions(+), 35 deletions(-) diff --git a/Assets/VRM10/Runtime/Components/Vrm10Instance/Vrm10Instance.cs b/Assets/VRM10/Runtime/Components/Vrm10Instance/Vrm10Instance.cs index dd90a264a..2134ec5cb 100644 --- a/Assets/VRM10/Runtime/Components/Vrm10Instance/Vrm10Instance.cs +++ b/Assets/VRM10/Runtime/Components/Vrm10Instance/Vrm10Instance.cs @@ -115,31 +115,49 @@ namespace UniVRM10 } } + /// + /// SpringboneRuntime が無かった時にデフォルトの runtime を作成する + /// + /// - Importer に SpringboneRuntime 引数が無かった時 + /// - Scene 配置 model のスタートアップ + /// + /// + /// + /// + internal static IVrm10SpringBoneRuntime MakeSpringboneRuntime(GameObject root) + { + if (root != null) + { + var provider = root.GetComponent(); + if (provider != null) + { + // 明示的カスタマイズ + return provider.CreateSpringBoneRuntime(); + } + } + + if (Application.isEditor) + { + // note: test, timeline などで Singleton(DontDestroyOnLoad) が都合が悪い + return new Vrm10FastSpringboneRuntimeStandalone(); + } + + // default + return new Vrm10FastSpringboneRuntime(); + } + internal Vrm10Runtime MakeRuntime(bool useControlRig) { if (m_springBoneRuntime == null) { - // シーン配置モデルが play された - var provider = GetComponent(); - if (provider != null) - { - // 明示的カスタマイズ - m_springBoneRuntime = provider.CreateSpringBoneRuntime(); - } - else - { - // deafult に fallback - if (Application.isEditor) - { - m_springBoneRuntime = new Vrm10FastSpringboneRuntimeStandalone(); - } - else - { - m_springBoneRuntime = new Vrm10FastSpringboneRuntime(); - } - } + // springbone が無い => シーン配置モデルが play されたと見做す + m_springBoneRuntime = MakeSpringboneRuntime(gameObject); m_springBoneRuntime.InitializeAsync(this, new ImmediateCaller()); } + else + { + // importer 内で InitializeAsync が呼び出し済み + } return new Vrm10Runtime(this, useControlRig, m_springBoneRuntime); } diff --git a/Assets/VRM10/Runtime/IO/Vrm10Importer.cs b/Assets/VRM10/Runtime/IO/Vrm10Importer.cs index c3c05ff38..9e56a7366 100644 --- a/Assets/VRM10/Runtime/IO/Vrm10Importer.cs +++ b/Assets/VRM10/Runtime/IO/Vrm10Importer.cs @@ -54,24 +54,20 @@ namespace UniVRM10 m_externalMap = new Dictionary(); } - m_springboneRuntime = MakeDefaultRuntime(springboneRuntime, isAssetImport); - } - - static IVrm10SpringBoneRuntime MakeDefaultRuntime(IVrm10SpringBoneRuntime runtime, bool isAssetImport) - { - if (runtime != null) + if (springboneRuntime == null) { - return runtime; + if (isAssetImport) + { + // 何もしない dummy + springboneRuntime = new Vrm10NopSpringboneRuntime(); + } + else + { + // default の SpringboneRuntime を作成する + springboneRuntime = Vrm10Instance.MakeSpringboneRuntime(null); + } } - - if (isAssetImport) - { - // 何もしない dummy - return new Vrm10NopSpringboneRuntime(); - } - - // Vrm10Instance.MakeRuntime に移譲 - return null; + m_springboneRuntime = springboneRuntime; } static void AssignHumanoid(List nodes, UniGLTF.Extensions.VRMC_vrm.HumanBone humanBone, VrmLib.HumanoidBones key) From 9c933390f13f76b21ab6baaaee0bb672a9f13390 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Fri, 25 Oct 2024 17:58:46 +0900 Subject: [PATCH 2/2] =?UTF-8?q?default=20=E3=81=AE=20SpringboneRuntime=20?= =?UTF-8?q?=E3=81=AE=E6=9D=A1=E4=BB=B6=E8=A6=8B=E7=9B=B4=E3=81=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Components/Vrm10Instance/Vrm10Instance.cs | 45 ++++++------------- Assets/VRM10/Runtime/IO/Vrm10Importer.cs | 11 ++++- 2 files changed, 22 insertions(+), 34 deletions(-) diff --git a/Assets/VRM10/Runtime/Components/Vrm10Instance/Vrm10Instance.cs b/Assets/VRM10/Runtime/Components/Vrm10Instance/Vrm10Instance.cs index 2134ec5cb..005719eef 100644 --- a/Assets/VRM10/Runtime/Components/Vrm10Instance/Vrm10Instance.cs +++ b/Assets/VRM10/Runtime/Components/Vrm10Instance/Vrm10Instance.cs @@ -115,43 +115,24 @@ namespace UniVRM10 } } - /// - /// SpringboneRuntime が無かった時にデフォルトの runtime を作成する - /// - /// - Importer に SpringboneRuntime 引数が無かった時 - /// - Scene 配置 model のスタートアップ - /// - /// - /// - /// - internal static IVrm10SpringBoneRuntime MakeSpringboneRuntime(GameObject root) - { - if (root != null) - { - var provider = root.GetComponent(); - if (provider != null) - { - // 明示的カスタマイズ - return provider.CreateSpringBoneRuntime(); - } - } - - if (Application.isEditor) - { - // note: test, timeline などで Singleton(DontDestroyOnLoad) が都合が悪い - return new Vrm10FastSpringboneRuntimeStandalone(); - } - - // default - return new Vrm10FastSpringboneRuntime(); - } - internal Vrm10Runtime MakeRuntime(bool useControlRig) { if (m_springBoneRuntime == null) { // springbone が無い => シーン配置モデルが play されたと見做す - m_springBoneRuntime = MakeSpringboneRuntime(gameObject); + var provider = GetComponent(); + if (provider != null) + { + // 明示的カスタマイズ + m_springBoneRuntime = provider.CreateSpringBoneRuntime(); + } + + if (m_springBoneRuntime == null) + { + // シーン配置 play のデフォルトは singletone ではない方 + m_springBoneRuntime = new Vrm10FastSpringboneRuntimeStandalone(); + } + m_springBoneRuntime.InitializeAsync(this, new ImmediateCaller()); } else diff --git a/Assets/VRM10/Runtime/IO/Vrm10Importer.cs b/Assets/VRM10/Runtime/IO/Vrm10Importer.cs index 9e56a7366..3e920d2bd 100644 --- a/Assets/VRM10/Runtime/IO/Vrm10Importer.cs +++ b/Assets/VRM10/Runtime/IO/Vrm10Importer.cs @@ -63,8 +63,15 @@ namespace UniVRM10 } else { - // default の SpringboneRuntime を作成する - springboneRuntime = Vrm10Instance.MakeSpringboneRuntime(null); + if (!Application.isPlaying) + { + // play中でない。test 対策 + springboneRuntime = new Vrm10FastSpringboneRuntimeStandalone(); + } + else + { + springboneRuntime = new Vrm10FastSpringboneRuntime(); + } } } m_springboneRuntime = springboneRuntime;