Builtin Library
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 turnsboneso its bone points at its tail, which carries its inertia lessdrag, returns toward its rest direction bystiffness, falls alonggravity_dirbygravity_power, keeps the bone's length and is pushed out of its chain's colliders byhit_radius.tailis 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 intocollidersfrom 0.colliders—{ bone, shape, offset, tail, radius }: asphereatoffsetor acapsulefromoffsettotail, in the bone's space.constraints—{ kind, bone, source, axis, weight }:rotation,roll(aboutaxis,X,YorZ) oraim(axis,PositiveXthroughNegativeZ, 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 } },
})