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

Constructors

Methods

  • 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

    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

    Returns Vector3

    The adjusted tail position after collision resolution

  • 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

    • 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

    Returns void