From b537a4a3eaaff0be12f12e42bc72cb0296cb269a Mon Sep 17 00:00:00 2001 From: amamagi Date: Mon, 27 Jun 2022 12:53:21 +0900 Subject: [PATCH] add default transform states --- .../Components/Vrm10Runtime/Vrm10Runtime.cs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Assets/VRM10/Runtime/Components/Vrm10Runtime/Vrm10Runtime.cs b/Assets/VRM10/Runtime/Components/Vrm10Runtime/Vrm10Runtime.cs index efaefef26..07adca4d6 100644 --- a/Assets/VRM10/Runtime/Components/Vrm10Runtime/Vrm10Runtime.cs +++ b/Assets/VRM10/Runtime/Components/Vrm10Runtime/Vrm10Runtime.cs @@ -1,5 +1,7 @@ using System; +using System.Collections.Generic; using System.Linq; +using UniGLTF; using UnityEngine; using UniVRM10.FastSpringBones.Blittables; using UniVRM10.FastSpringBones.System; @@ -15,6 +17,7 @@ namespace UniVRM10 private readonly IVrm10Constraint[] m_constraints; private readonly Transform m_head; private readonly FastSpringBoneService m_fastSpringBoneService; + private readonly Dictionary m_defaultTransformStates; private FastSpringBoneBuffer m_fastSpringBoneBuffer; @@ -47,6 +50,18 @@ namespace UniVRM10 // for UnitTest return; } + + var instance = target.GetComponent(); + if (instance != null) + { + // ランタイムインポートならここに到達してほぼゼロコストになる + m_defaultTransformStates = instance.Nodes.ToDictionary(tf=> tf, tf=>(tf.position, tf.rotation)); + } + else + { + // エディタでプレハブ配置してる奴ならこっちに到達して収集する + m_defaultTransformStates = target.GetComponentsInChildren().ToDictionary(tf=> tf, tf=>(tf.position, tf.rotation)); + } m_fastSpringBoneService = FastSpringBoneService.Instance; m_fastSpringBoneBuffer = CreateFastSpringBoneBuffer(m_target.SpringBone);