Log inGet started
Package

EcsSecondaryMotion.module

Newest version

This package holds more than this page lists. See all of its files in its world.

README.md

ecs.SecondaryMotion

Spec for the SecondaryMotion component, which maps to the native SecondaryMotion: the secondary motion of a skinned body. Spring chains swing hair, cloth and accessories behind the body's motion and stop at its colliders; bone constraints turn one bone from another. The engine applies it every frame after the body's pose and before its skinning, on the bones it names by entity id: constraints first, in the order listed, then the joints.

The SpringBones component builds it from bone names (an avatar's secondaryMotion); this is the engine's own form.

Fields

  • paused — holds every bone where the body's pose puts it.
  • revision — raised to read every bone's rest again and start the chains from it.
  • joints — { bone, tail, chain, stiffness, drag, gravity_power, gravity_dir, hit_radius }: each joint turns bone so its bone points at its tail, which carries its inertia less drag, returns toward its rest direction by stiffness, falls along gravity_dir by gravity_power, keeps the bone's length and is pushed out of its chain's colliders by hit_radius. tail is the next bone of the chain; empty, the tail continues 7 cm past the bone.
  • chains — { center, colliders }: the bone whose space the chain moves in (empty for the world) and the colliders its tails stop at, indices into colliders from 0.
  • colliders — { bone, shape, offset, tail, radius }: a sphere at offset or a capsule from offset to tail, in the bone's space.
  • constraints — { kind, bone, source, axis, weight }: rotation, roll (about axis, X, Y or Z) or aim (axis, PositiveX through NegativeZ, toward the source).
ecs.insert(skinnedId, ecs.SecondaryMotion {
    joints = { { bone = hairId, tail = hairTipId, chain = 0, stiffness = 1, drag = 0.4,
        gravity_power = 0.2, gravity_dir = { x = 0, y = -1, z = 0 }, hit_radius = 0.02 } },
    chains = { { center = "", colliders = { 0 } } },
    colliders = { { bone = headId, shape = "sphere", offset = { x = 0, y = 0.08, z = 0 }, tail = { x = 0, y = 0, z = 0 }, radius = 0.1 } },
})