Example #1
0
        public void Update(Transform center, float deltaTime, List <SpringBoneLogic.InternalCollider> colliders, VRM10SpringJoint tail)
        {
            if (m_logic == null)
            {
                // 初期化
                if (tail != null)
                {
                    var localPosition = tail.Transform.localPosition;
                    var scale         = tail.Transform.lossyScale;
                    m_logic = new SpringBoneLogic(center, Transform,
                                                  new Vector3(
                                                      localPosition.x * scale.x,
                                                      localPosition.y * scale.y,
                                                      localPosition.z * scale.z
                                                      ));
                }
                else
                {
                    // 親からまっすぐの位置に tail を作成
                    var delta         = Transform.position - Transform.parent.position;
                    var childPosition = Transform.position + delta.normalized * 0.07f;
                    m_logic = new SpringBoneLogic(center, Transform, Transform.worldToLocalMatrix.MultiplyPoint(childPosition));
                }
            }

            m_logic.Update(center, m_stiffnessForce * deltaTime, m_dragForce, m_gravityDir * (m_gravityPower * deltaTime), colliders, m_jointRadius);
        }
            public void Process(Transform center)
            {
                m_center = center;
                if (Joints == null)
                {
                    return;
                }

                // gather colliders
                if (m_colliderList == null)
                {
                    m_colliderList = new List <SpringBoneLogic.InternalCollider>();
                }
                m_colliderList.Clear();
                if (ColliderGroups != null)
                {
                    foreach (var group in ColliderGroups.Where(x => x != null))
                    {
                        foreach (var collider in group.Colliders)
                        {
                            switch (collider.ColliderType)
                            {
                            case VRM10SpringBoneColliderTypes.Sphere:
                                m_colliderList.Add(new SpringBoneLogic.InternalCollider
                                {
                                    ColliderTypes = VRM10SpringBoneColliderTypes.Sphere,
                                    WorldPosition = collider.transform.TransformPoint(collider.Offset),
                                    Radius        = collider.Radius,
                                });
                                break;

                            case VRM10SpringBoneColliderTypes.Capsule:
                                m_colliderList.Add(new SpringBoneLogic.InternalCollider
                                {
                                    ColliderTypes = VRM10SpringBoneColliderTypes.Capsule,
                                    WorldPosition = collider.transform.TransformPoint(collider.Offset),
                                    Radius        = collider.Radius,
                                    WorldTail     = collider.transform.TransformPoint(collider.Tail)
                                });
                                break;
                            }
                        }
                    }
                }

                if (m_logics == null)
                {
                    m_logics = Enumerable.Zip(Joints, Joints.Skip(1), (head, tail) =>
                    {
                        var localPosition = tail.transform.localPosition;
                        var scale         = tail.transform.lossyScale;
                        var logic         = new SpringBoneLogic(center, head.transform,
                                                                new Vector3(
                                                                    localPosition.x * scale.x,
                                                                    localPosition.y * scale.y,
                                                                    localPosition.z * scale.z
                                                                    ));
                        return(head, logic);
                    }).ToList();
                }
                foreach (var(head, logic) in m_logics)
                {
                    logic.Update(center,
                                 head.m_stiffnessForce * Time.deltaTime,
                                 head.m_dragForce,
                                 head.m_gravityDir * (head.m_gravityPower * Time.deltaTime),
                                 m_colliderList, head.m_jointRadius);
                }
            }