public VRMSpringBone ToSpringBone(GameObject gameObject)
        {
            var targetObject = HierarchyPath.ToGameObject(AttachedTo, gameObject);
            var attachedBone = targetObject.AddComponent <VRMSpringBone>();

            // Copy values
            attachedBone.m_comment        = m_comment;
            attachedBone.m_stiffnessForce = m_stiffnessForce;
            attachedBone.m_gravityPower   = m_gravityPower;
            attachedBone.m_gravityDir     = m_gravityDir;
            attachedBone.m_dragForce      = m_dragForce;
            attachedBone.m_center         = HierarchyPath.ToTransform(m_center);
            attachedBone.RootBones        = HierarchyPath.ToTransforms(RootBones, gameObject);
            attachedBone.m_hitRadius      = m_hitRadius;
            attachedBone.ColliderGroups   = new VRMSpringBoneColliderGroup[ColliderGroups.Count];
            for (var i = 0; i < ColliderGroups.Count; i++)
            {
                var cgAttachedObject = HierarchyPath.ToGameObject(ColliderGroups[i], gameObject);
                if (cgAttachedObject != null)
                {
                    attachedBone.ColliderGroups[i] = cgAttachedObject.GetComponent <VRMSpringBoneColliderGroup>();
                }
            }
            return(attachedBone);
        }
        // Convert to VRMSpringBoneCollider
        public VRMSpringBoneColliderGroup ToSpringBoneColliderGroup(GameObject gameObject)
        {
            var targetObject          = HierarchyPath.ToGameObject(AttachedTo, gameObject);
            var attachedColliderGroup = targetObject.AddComponent <VRMSpringBoneColliderGroup>();

            // Copy values
            attachedColliderGroup.Colliders = new VRMSpringBoneColliderGroup.SphereCollider[Colliders.Count];
            for (var i = 0; i < Colliders.Count; i++)
            {
                attachedColliderGroup.Colliders[i] = new VRMSpringBoneColliderGroup.SphereCollider()
                {
                    Offset = Colliders[i].Offset,
                    Radius = Colliders[i].Radius
                };
            }

            return(attachedColliderGroup);
        }
Пример #3
0
        public DynamicBone ToDynamicBone(GameObject gameObject)
        {
            var targetObject = HierarchyPath.ToGameObject(AttachedTo, gameObject);
            var attachedBone = targetObject.AddComponent <DynamicBone>();

            // Copy values
            attachedBone.m_Root              = HierarchyPath.ToTransform(m_Root, gameObject);
            attachedBone.m_UpdateRate        = m_UpdateRate;
            attachedBone.m_UpdateMode        = m_UpdateMode;
            attachedBone.m_Damping           = m_Damping;
            attachedBone.m_DampingDistrib    = m_DampingDistrib;
            attachedBone.m_Elasticity        = m_Elasticity;
            attachedBone.m_ElasticityDistrib = m_ElasticityDistrib;
            attachedBone.m_Stiffness         = m_Stiffness;
            attachedBone.m_StiffnessDistrib  = m_StiffnessDistrib;
            attachedBone.m_Inert             = m_Inert;
            attachedBone.m_InertDistrib      = m_InertDistrib;
            attachedBone.m_Radius            = m_Radius;
            attachedBone.m_RadiusDistrib     = m_RadiusDistrib;
            attachedBone.m_EndLength         = m_EndLength;
            attachedBone.m_EndOffset         = m_EndOffset;
            attachedBone.m_Gravity           = m_Gravity;
            attachedBone.m_Force             = m_Force;
            attachedBone.m_Colliders         = new List <DynamicBoneColliderBase>();
            foreach (var colliderAttachedObject in HierarchyPath.ToGameObjects(m_Colliders, gameObject))
            {
                var colliders = colliderAttachedObject.GetComponents <DynamicBoneCollider>();
                if (colliders != null)
                {
                    foreach (var collider in colliders)
                    {
                        attachedBone.m_Colliders.Add(collider);
                    }
                }
            }
            attachedBone.m_Exclusions       = HierarchyPath.ToTransforms(m_Exclusions, gameObject);
            attachedBone.m_FreezeAxis       = m_FreezeAxis;
            attachedBone.m_DistantDisable   = m_DistantDisable;
            attachedBone.m_ReferenceObject  = HierarchyPath.ToTransform(m_ReferenceObject, gameObject);
            attachedBone.m_DistanceToObject = m_DistanceToObject;

            return(attachedBone);
        }
Пример #4
0
        public DynamicBoneCollider ToDynamicBoneCollider(GameObject gameObject)
        {
            var targetObject = HierarchyPath.ToGameObject(AttachedTo, gameObject);

            if (targetObject == null)
            {
                Debug.LogError($"GameObject to attatch collider is not found: {HierarchyPath.ReplaceRoot(AttachedTo, gameObject.name)}");
                return(null);
            }
            var attachedCollider = targetObject.AddComponent <DynamicBoneCollider>();

            // Todo: apply transform scale ratio
            // Copy values
            attachedCollider.m_Center    = m_Center;
            attachedCollider.m_Radius    = m_Radius;
            attachedCollider.m_Direction = m_Direction;
            attachedCollider.m_Bound     = m_Bound;
            attachedCollider.m_Height    = m_Height;

            return(attachedCollider);
        }