From 289e9e90b9b2b4fab4af7ff002bb5ee211a6f662 Mon Sep 17 00:00:00 2001 From: Masataka SUMI Date: Tue, 5 Jul 2022 21:49:47 +0900 Subject: [PATCH] Fix vrm10 springbone initializing problem. --- .../Components/Vrm10Runtime/Vrm10Runtime.cs | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/Assets/VRM10/Runtime/Components/Vrm10Runtime/Vrm10Runtime.cs b/Assets/VRM10/Runtime/Components/Vrm10Runtime/Vrm10Runtime.cs index 102edcf05..15f504d54 100644 --- a/Assets/VRM10/Runtime/Components/Vrm10Runtime/Vrm10Runtime.cs +++ b/Assets/VRM10/Runtime/Components/Vrm10Runtime/Vrm10Runtime.cs @@ -17,7 +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 readonly IReadOnlyDictionary m_defaultTransformStates; private FastSpringBoneBuffer m_fastSpringBoneBuffer; @@ -48,17 +48,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)); + // ランタイムインポートならここに到達してゼロコストになる + m_defaultTransformStates = instance.InitialTransformStates; } else { // エディタでプレハブ配置してる奴ならこっちに到達して収集する - m_defaultTransformStates = target.GetComponentsInChildren().ToDictionary(tf=> tf, tf=>(tf.position, tf.rotation)); + m_defaultTransformStates = target.GetComponentsInChildren() + .ToDictionary(tf => tf, tf => new TransformState(tf)); } m_fastSpringBoneService = FastSpringBoneService.Instance; @@ -111,18 +112,20 @@ namespace UniVRM10 gravityPower = joint.m_gravityPower, stiffnessForce = joint.m_stiffnessForce }, - DefaultLocalRotation = GetOrAddDefaultTransformState(joint.transform).rotation + DefaultLocalRotation = GetOrAddDefaultTransformState(joint.transform).LocalRotation, }).ToArray(), }).ToArray()); } - private (Vector3 position, Quaternion rotation) GetOrAddDefaultTransformState(Transform tf) + private TransformState GetOrAddDefaultTransformState(Transform tf) { if (m_defaultTransformStates.TryGetValue(tf, out var defaultTransformState)) { return defaultTransformState; } - return m_defaultTransformStates[tf] = (tf.position, tf.rotation); + + Debug.LogWarning($"{tf.name} does not exist on load."); + return new TransformState(null); } private static BlittableColliderType TranslateColliderType(VRM10SpringBoneColliderTypes colliderType) @@ -140,16 +143,16 @@ namespace UniVRM10 /// /// 毎フレーム関連コンポーネントを解決する - /// + /// /// * Contraint /// * Spring /// * LookAt /// * Expression - /// + /// /// public void Process() { - // + // // constraint // foreach (var constraint in m_constraints)