rhodonite
    Preparing search index...

    Class VRMSpringBonePhysicsStrategy

    Physics strategy implementation for VRM spring bone simulation.

    This class handles the physics simulation of VRM spring bones, which are used to create realistic secondary animation for hair, clothing, accessories, and other flexible parts of VRM models. The simulation includes:

    • Inertia and drag forces
    • Gravity effects
    • Stiffness constraints
    • Collision detection and response
    • Bone length normalization

    The physics simulation runs per frame and updates the rotation of spring bone nodes based on physical forces and constraints.

    Implements

    Index
    • Applies the calculated rotation to the spring bone based on the new tail position.

      This method calculates the rotation needed to orient the bone from its head to the new tail position. It takes into account the parent's rotation and the bone's rest rotation to compute the final local rotation.

      Parameters

      • nextTail: Vector3

        The new tail position in world space

      • bone: VRMSpringBone

        The spring bone to apply rotation to

      • worldSpacePosition: Vector3

      Returns IMutableQuaternion

      The calculated local rotation quaternion for the bone

    • Handles collision detection and response for the spring bone.

      This method checks for collisions between the spring bone and all colliders in the provided collision groups. It supports both sphere and capsule colliders. When a collision is detected, the bone's tail position is adjusted to resolve the collision, and the bone length is re-normalized.

      Parameters

      • collisionGroups: VRMColliderGroup[]

        Array of collision groups containing colliders

      • nextTail: Vector3

        The target tail position to check for collisions

      • boneHitRadius: number

        The radius of the bone for collision detection

      • bone: VRMSpringBone

        The spring bone being tested for collisions

      • worldSpacePosition: Vector3

      Returns Vector3

      The adjusted tail position after collision resolution

    • Gets the parent rotation of the specified scene graph component.

      Parameters

      Returns MutableQuaternion

      The parent's rotation quaternion, or identity quaternion if no parent exists

    • Gets the VRM spring system managed by this physics strategy. This is optional and only implemented by strategies that support VRM spring bones.

      Returns VRMSpring | undefined

      The VRM spring system, or undefined if not supported

    • Normalizes the bone length to maintain the original bone length constraint.

      This method ensures that the spring bone maintains its original length regardless of the forces applied during simulation. It calculates the direction from the bone's head to the target tail position and scales it to match the original bone length.

      Parameters

      • nextTail: Vector3

        The target tail position before normalization

      • worldSpacePosition: Vector3
      • bone: VRMSpringBone

        The spring bone to normalize

      Returns IMutableVector3

      The normalized tail position maintaining the original bone length

    • Processes the physics simulation for a single spring bone.

      This method performs the complete physics simulation pipeline:

      1. Calculates inertia from previous frame movement
      2. Applies stiffness forces to maintain bone orientation
      3. Applies external forces (gravity)
      4. Normalizes bone length to maintain constraints
      5. Handles collision detection and response
      6. Updates bone position and rotation

      Parameters

      • config: Config

        The configuration for the physics simulation

      • collisionGroups: VRMColliderGroup[]

        Array of collision groups for collision detection

      • bone: VRMSpringBone

        The spring bone to process

      • Optionalcenter: SceneGraphComponent

        Optional center transform for coordinate space conversion

      Returns void

    • Sets the visibility of all sphere colliders in this physics strategy. This creates visualization spheres for each collider if they don't exist yet.

      Parameters

      • visible: boolean

        Whether the colliders should be visible

      Returns void

    • Sets the VRM spring system to be managed by this physics strategy.

      Parameters

      • sgs: VRMSpring

        The VRM spring system containing bones and configuration

      Returns void

    • Updates the spring bone physics simulation for the current frame.

      This method is called once per frame and triggers the physics update for all spring bones in the associated VRM spring system.

      Parameters

      Returns void

    • Internal update method that processes all spring bones in the system.

      Parameters

      • config: Config
      • bones: VRMSpringBone[]

        Array of VRM spring bones to update

      • spring: VRMSpring

        The VRM spring system containing configuration and colliders

      Returns void