public SpringBoneConfiguration(GameObject gameObject)
        {
            foreach (var bone in gameObject.GetComponentsInChildren <VRMSpringBone>())
            {
                SpringBones.Add(SerializableSpringBone.FromSpringBone(bone));
            }

            foreach (var colliderGroup in gameObject.GetComponentsInChildren <VRMSpringBoneColliderGroup>())
            {
                SpringBoneColliderGroups.Add(SerializableSpringBoneColliderGroup.FromSpringBoneColliderGroup(colliderGroup));
            }
        }
Exemplo n.º 2
0
        public List <SerializableSpringBone> ConvertBones(List <SerializableDynamicBone> dynamicBones, bool attacheToSecondary)
        {
            var springBones = new List <SerializableSpringBone>();

            foreach (var dyBone in dynamicBones)
            {
                var spBone = new SerializableSpringBone();

                if (attacheToSecondary)
                {
                    spBone.AttachedTo = $"{gameObject.name}/secondary";
                }
                else
                {
                    spBone.AttachedTo = dyBone.AttachedTo;
                }

                Debug.Log($"Object to attach: {spBone.AttachedTo}");

                spBone.m_stiffnessForce = dyBone.m_Stiffness * 4.0f;                                           // The max value of SpringBone is 4.0f

                spBone.m_gravityPower = dyBone.m_Gravity.magnitude > 2.0f ? 2.0f : dyBone.m_Gravity.magnitude; // The max value is 2.0f

                spBone.m_gravityDir = spBone.m_gravityPower == 0 ? new Vector3(0, -1.0f, 0) : dyBone.m_Gravity / dyBone.m_Gravity.magnitude;

                spBone.RootBones = new List <string>()
                {
                    dyBone.m_Root
                };

                // Radius of DynamicBone is relative to its parant. This value should be tuned manually because RadiusDistrib is not applied.
                spBone.m_hitRadius = dyBone.m_Radius * dyBone.TransformScale.x;

                spBone.ColliderGroups = new List <string>(dyBone.m_Colliders);

                springBones.Add(spBone);
            }

            return(springBones);
        }
        public static SerializableSpringBone FromSpringBone(VRMSpringBone bone)
        {
            Debug.Log($"Convert SpringBone to serializable: Root={bone.RootBones[0].name}");

            var serializableBone = new SerializableSpringBone();

            serializableBone.AttachedTo = HierarchyPath.FromTransform(bone.gameObject.transform);

            // Copy values
            serializableBone.m_comment        = bone.m_comment;
            serializableBone.m_stiffnessForce = bone.m_stiffnessForce;
            serializableBone.m_gravityPower   = bone.m_gravityPower;
            serializableBone.m_gravityDir     = bone.m_gravityDir;
            serializableBone.m_dragForce      = bone.m_dragForce;
            if (bone.m_center != null)
            {
                serializableBone.m_center = HierarchyPath.FromTransform(bone.m_center);
            }
            if (bone.RootBones != null)
            {
                foreach (var rootBone in bone.RootBones)
                {
                    serializableBone.RootBones.Add(HierarchyPath.FromTransform(rootBone));
                }
            }
            serializableBone.m_hitRadius = bone.m_hitRadius;
            if (bone.ColliderGroups != null)
            {
                foreach (var colliderGroup in bone.ColliderGroups)
                {
                    serializableBone.ColliderGroups.Add(HierarchyPath.FromTransform(colliderGroup.transform));
                }
            }

            return(serializableBone);
        }