diff --git a/Assets/UniGLTF/Runtime/UniGLTF/RuntimeGltfInstance.cs b/Assets/UniGLTF/Runtime/UniGLTF/RuntimeGltfInstance.cs index 99cfaf86b..73c3e7a33 100644 --- a/Assets/UniGLTF/Runtime/UniGLTF/RuntimeGltfInstance.cs +++ b/Assets/UniGLTF/Runtime/UniGLTF/RuntimeGltfInstance.cs @@ -221,6 +221,11 @@ namespace UniGLTF Destroy(oldResource); } + public void AddResource(T resource) where T : UnityEngine.Object + { + _resources.Add((SubAssetKey.Create(resource), resource)); + } + void OnDestroy() { foreach (var (_, obj) in _resources) diff --git a/Assets/VRM10/Runtime/Components/VRM10Object/VRM10ObjectFirstPerson.cs b/Assets/VRM10/Runtime/Components/VRM10Object/VRM10ObjectFirstPerson.cs index 120ca4387..812264422 100644 --- a/Assets/VRM10/Runtime/Components/VRM10Object/VRM10ObjectFirstPerson.cs +++ b/Assets/VRM10/Runtime/Components/VRM10Object/VRM10ObjectFirstPerson.cs @@ -93,20 +93,25 @@ namespace UniVRM10 { if (x.GetRenderer(go.transform) is SkinnedMeshRenderer smr) { - // オリジナルのモデルを3人称用にする - smr.gameObject.layer = layer.ThirdPersonOnly; - // 頭を取り除いた複製モデルを作成し、1人称用にする var headless = await CreateHeadlessMeshAsync(smr, firstPersonBone, awaitCaller); if (headless != null) { + // オリジナルのモデルを3人称用にする + smr.gameObject.layer = layer.ThirdPersonOnly; + headless.gameObject.layer = layer.FirstPersonOnly; headless.transform.SetParent(smr.transform, false); if (runtime != null) { + runtime.AddResource(headless.sharedMesh); runtime.AddRenderer(headless); } } + else + { + // ヘッドレスを作成しなかった場合は何もしない => both と同じ + } } else if (x.GetRenderer(go.transform) is MeshRenderer mr) { diff --git a/Assets/VRM10_Samples/VRM10FirstPersonSample/VRM10RuntimeLoader.cs b/Assets/VRM10_Samples/VRM10FirstPersonSample/VRM10RuntimeLoader.cs index 3a0feb381..f5b9328fc 100644 --- a/Assets/VRM10_Samples/VRM10FirstPersonSample/VRM10RuntimeLoader.cs +++ b/Assets/VRM10_Samples/VRM10FirstPersonSample/VRM10RuntimeLoader.cs @@ -86,11 +86,13 @@ namespace UniVRM10.FirstPersonSample async Task LoadAsync(string path, VRMShaders.IAwaitCaller awaitCaller) { - var instance = await Vrm10.LoadPathAsync(path, awaitCaller: awaitCaller); + var instance = await Vrm10.LoadPathAsync(path, awaitCaller: awaitCaller, showMeshes: false); // VR用 FirstPerson 設定 await instance.Vrm.FirstPerson.SetupAsync(instance.gameObject, awaitCaller); + instance.GetComponent().ShowMeshes(); + return instance; }