diff --git a/Assets/VRM/Runtime/SpringBone/VRMSpringBone.cs b/Assets/VRM/Runtime/SpringBone/VRMSpringBone.cs index e505b8914..06e5ad58f 100644 --- a/Assets/VRM/Runtime/SpringBone/VRMSpringBone.cs +++ b/Assets/VRM/Runtime/SpringBone/VRMSpringBone.cs @@ -23,11 +23,11 @@ namespace VRM [Header("Settings")] public float m_stiffnessForce = 1.0f; - [SerializeField] [Range(0, 2)] public float m_gravityPower; + [SerializeField][Range(0, 2)] public float m_gravityPower; [SerializeField] public Vector3 m_gravityDir = new Vector3(0, -1.0f, 0); - [SerializeField] [Range(0, 1)] public float m_dragForce = 0.4f; + [SerializeField][Range(0, 1)] public float m_dragForce = 0.4f; [SerializeField] public Transform m_center; @@ -46,6 +46,7 @@ namespace VRM { LateUpdate, FixedUpdate, + Manual, } [SerializeField] public SpringBoneUpdateType m_updateType = SpringBoneUpdateType.LateUpdate; @@ -263,6 +264,15 @@ namespace VRM } } + public void ManualUpdate(float deltaTime) + { + if (m_updateType != SpringBoneUpdateType.Manual) + { + throw new System.ArgumentException("require SpringBoneUpdateType.Manual"); + } + UpdateProcess(deltaTime); + } + public struct SphereCollider { // public Transform Transform; diff --git a/Assets/VRM10/Runtime/FastSpringBone/System/FastSpringBoneScheduler.cs b/Assets/VRM10/Runtime/FastSpringBone/System/FastSpringBoneScheduler.cs index c5079cfc0..f3adb0bad 100644 --- a/Assets/VRM10/Runtime/FastSpringBone/System/FastSpringBoneScheduler.cs +++ b/Assets/VRM10/Runtime/FastSpringBone/System/FastSpringBoneScheduler.cs @@ -13,7 +13,7 @@ namespace UniVRM10.FastSpringBones.System _bufferCombiner = bufferCombiner; } - public JobHandle Schedule() + public JobHandle Schedule(float deltaTime) { var handle = default(JobHandle); handle = _bufferCombiner.ReconstructIfDirty(handle); @@ -34,7 +34,7 @@ namespace UniVRM10.FastSpringBones.System Logics = _bufferCombiner.Logics, Springs = _bufferCombiner.Springs, Transforms = _bufferCombiner.Transforms, - DeltaTime = Time.deltaTime, + DeltaTime = deltaTime, }.Schedule(_bufferCombiner.Springs.Length, 1, handle); handle = new PushTransformJob diff --git a/Assets/VRM10/Runtime/FastSpringBone/System/FastSpringBoneService.cs b/Assets/VRM10/Runtime/FastSpringBone/System/FastSpringBoneService.cs index d3e103977..993e786f9 100644 --- a/Assets/VRM10/Runtime/FastSpringBone/System/FastSpringBoneService.cs +++ b/Assets/VRM10/Runtime/FastSpringBone/System/FastSpringBoneService.cs @@ -3,8 +3,41 @@ using UnityEngine; namespace UniVRM10.FastSpringBones.System { [DefaultExecutionOrder(11000)] + /// + /// VRM-1.0 ではコンポーネントの処理順が規定されている + /// + /// 1. ヒューマノイドボーンを解決 + /// 2. 頭の位置が決まるのでLookAtを解決 + /// 3. ExpressionUpdate + /// 4. コンストレイントを解決 + /// 5. SpringBoneを解決 + /// + /// 1~4 は Vrm10Runtime が管理し LateUpdate で処理される。 + /// このクラスは DefaultExecutionOrder(11000) によりその後ろにまわる。 + /// + /// # [Manual update] + /// + /// foreach(var vrmInstance in allVrm) + /// { + /// vrmInstance.UpdateType = None; + /// vrmInstance.Runtime.Process(); + /// } + /// FastSpringBoneService.Instance.UpdateType = Manual; + /// FastSpringBoneService.Instance.ManualUpdate(); + /// + /// public sealed class FastSpringBoneService : MonoBehaviour { + public enum UpdateTypes + { + Manual, + LateUpdate, + } + + [SerializeField, Header("Runtime")] + public UpdateTypes UpdateType = UpdateTypes.LateUpdate; + + public FastSpringBoneBufferCombiner BufferCombiner { get; private set; } private FastSpringBoneScheduler _fastSpringBoneScheduler; @@ -50,7 +83,19 @@ namespace UniVRM10.FastSpringBones.System private void LateUpdate() { - _fastSpringBoneScheduler.Schedule().Complete(); + if (UpdateType == UpdateTypes.LateUpdate) + { + _fastSpringBoneScheduler.Schedule(Time.deltaTime).Complete(); + } + } + + public void ManualUpdate(float deltaTime) + { + if (UpdateType != UpdateTypes.Manual) + { + throw new global::System.ArgumentException("require UpdateTypes.None"); + } + _fastSpringBoneScheduler.Schedule(deltaTime).Complete(); } } } \ No newline at end of file