Log inGet started
World

Builtin Library

Branchmain
Branchesmainpublish
Commit098ece8e9e

README.md

SpringBones

Swings the hair, cloth, tails and accessories of the body under this entity behind the body's own motion, stops them at the body's colliders, and turns the bones its constraints name from their sources. An avatar whose avatar.json states a secondaryMotion (every avatar a VRM imports to) gets this component when it is instantiated, on every peer, and each peer simulates its own copy of the body.

root.component.add("SpringBones", { avatar = asset.resolve("my_vrm", "avatar") })
local s = root.component.get("SpringBones"):stats()
print(s.applied, s.springs, s.joints, s.colliders, s.constraints, #s.unresolved)
  • avatar (synced): the avatar whose secondaryMotion it applies.
  • motion (synced): the motion applied when no avatar is set, in the same form.
  • paused (synced): holds every bone where the body's pose puts it.

The data

Every bone is named by its name in the body. Positions are in the bone's own space, lengths in metres at the body's scale.

{
  "springs": [
    { "name": "hair_front", "center": "J_Bip_C_Head", "colliders": [0, 1],
      "joints": [
        { "bone": "hair_1", "tail": "hair_2", "stiffness": 1.0, "drag": 0.4,
          "gravityPower": 0.2, "gravityDir": [0, -1, 0], "hitRadius": 0.02 },
        { "bone": "hair_2", "tail": "", "stiffness": 1.0, "drag": 0.4,
          "gravityPower": 0.2, "gravityDir": [0, -1, 0], "hitRadius": 0.02 }
      ] }
  ],
  "colliders": [
    { "bone": "J_Bip_C_Head", "shape": "sphere", "offset": [0, 0.08, 0], "radius": 0.1 },
    { "bone": "J_Bip_C_UpperChest", "shape": "capsule", "offset": [-0.05, 0, 0], "tail": [0.05, 0, 0], "radius": 0.09 }
  ],
  "constraints": [
    { "kind": "roll", "bone": "LowerArm_twist_L", "source": "J_Bip_L_LowerArm", "axis": "X", "weight": 0.5 }
  ]
}
  • A joint's tail is the next bone of its chain; a chain's last bone leaves it empty and its tail continues 7 cm past it. A spring's colliders index colliders from 0, and center names the bone whose space the chain moves in (empty for the world).
  • The solver is the VRM 1.0 spring bone's: each tail carries its inertia less drag, returns toward its rest direction by stiffness, falls along gravityDir by gravityPower, keeps the bone's length and is pushed out of every collider its spring names by its hitRadius.
  • A constraint is rotation (the bone takes the source's rotation away from its rest), roll (the part of it about axis, X, Y or Z) or aim (the bone's axis, PositiveX through NegativeZ, points at the source), each by weight. Constraints apply before the springs.

stats() answers how much of the data the body carries (unresolved names the bones it does not); reset() starts every chain again from the body's rest.