skeleton
The skeleton pose-data pipeline: sample a clip into a pose buffer, and bind/apply a pose buffer onto a Skeleton + Model entity.
require("@builtin::modules.api.engine.skeleton") -- skeleton (also available as global 'skeleton')
The skeleton namespace: 30 functions.
globals/skeleton/applyPose
skeleton.applyPose(sinkHandle: number, poseBuffer: Substrate.TypedBuffer) -> boolean
Snapshot the buffer's first layout.total_floats values and
queue a pending apply for the next ECS drain. Returns false on
unknown sink/buffer or buffer too small for the layout. The
Buffer is unchanged.
Parameters
sinkHandlenumber— Sink handle frombindPose.poseBufferSubstrate.TypedBuffer— The pose buffer to apply.
Returns boolean — True on success.
globals/skeleton/bindClip
skeleton.bindClip(zanimBytes: buffer | string, boneOrder: { string }, restPose: { number }?, shapes: { ClipShape }?) -> ClipBindInfo?
Decode a zanim payload and bind it to boneOrder,
precomputing which of the clip's channels feed each bone so
per-frame sampleClip is allocation-free. With restPose (the
body's stride-10 rest, one record per bone of boneOrder), every
sampleClip writes the body's complete local pose: a bone the clip
does not name holds its rest record, and a bone it names takes the
clip's rotation, its rest translation plus the clip's displacement
from the clip's start, and its rest scale. With shapes (the
body's blend shapes), every sample writes after the bone records one
weight per shape and then one coverage per shape: a shape one of the
clip's weight tracks names (by any of the shape's names, exactly, else
ignoring case, spaces, _, - and .) takes the track's weight at
coverage 1, every other shape its rest weight at coverage 0.
boneOrder may be empty for a body with shapes and no bones. Returns
{ handle, matched, total, duration, shapesMatched, shapesTotal },
or nil on a malformed payload, a bind with neither bones nor shapes,
or a rest pose short of one record per bone. Check matched: 0 means
the clip drives none of these bones.
Parameters
zanimBytesbuffer | string— The clip'sdata.zanimpayload bytes (binary-safe).boneOrder{ string }— Output bone names — one stride-10 record per bone.restPose{ number }(optional) — The body's stride-10 rest pose; given, samples are complete local poses over it.shapes{ ClipShape }(optional) — The body's blend shapes, written after the bones.
Returns ClipBindInfo? — { handle, matched, total, duration, shapesMatched, shapesTotal }, or nil.
local info = skeleton.bindClip(bytes, layout.boneOrder, layout.restPose)
local face = skeleton.bindClip(bytes, {}, nil, { "mouthSmileLeft", "eyeBlink" })
globals/skeleton/bindPose
skeleton.bindPose(entityId: (string | entityRef)?, opts: SkeletonLayout) -> number?
Register a pose sink targeting entityId. The opts table
carries the layout: boneOrder is the bone-name array
({"hip", "spine", ...}), stride defaults to 10
(translation.xyz + rotation.xyzw + scale.xyz). Pass entityId
as nil to use the current component's owning entity.
Parameters
entityId(string | entityRef)(optional) — Engine entity id or proxy, or nil for the current entity.optsSkeletonLayout—{ boneOrder, stride }.
Returns number? — Sink handle, or nil.
local h = skeleton.bindPose(nil, { boneOrder = bones, stride = 10 })
globals/skeleton/clipBones
skeleton.clipBones(zanimBytes: buffer | string) -> { string }?
Decode a zanim payload and return its bone-name array. Pure:
build a bind order or a retarget map from a clip without binding a
sampler. Returns nil on bytes that aren't a valid zanim payload.
Parameters
zanimBytesbuffer | string— The clip'sdata.zanimpayload bytes (binary-safe).
Returns { string }? — Bone names referenced by the clip, or nil.
local names = skeleton.clipBones(assert(vfs.read(path .. "/data.zanim")))
globals/skeleton/clipDecode
skeleton.clipDecode(zanimBytes: buffer | string) -> string?
Decode a zanim payload to its readable JSON form
({ name, duration, channels, bone_names }), the clip as text to
read, store or diff. The binary parse is the engine's. Code that
transforms a clip's channels in Luau (e.g. the retarget bake) reads
the same clip as a table with clipToTable, which skips the text.
Returns nil on bytes that aren't a valid zanim payload. Inverse of
clipEncode.
Parameters
zanimBytesbuffer | string— The clip'sdata.zanimpayload bytes (binary-safe).
Returns string? — The clip as a JSON string, or nil.
local json = require("@builtin::modules.json")
local clipJson = skeleton.clipDecode(bytes)
local clip = if clipJson then json.decode(clipJson) else nil
globals/skeleton/clipEncode
skeleton.clipEncode(jsonString: string) -> string?
Encode a clip's JSON form (the shape clipDecode returns) back
to a zanim payload — the bytes a .animation stores and
bindClip/sampleClip consume. Inverse of clipDecode. A clip
held as a table encodes with clipFromTable, which skips the text.
Returns nil on invalid JSON.
Parameters
jsonStringstring— A clip JSON document.
Returns string? — The clip's zanim payload bytes, or nil.
local json = require("@builtin::modules.json")
local bytes = skeleton.clipEncode(json.encode(clip))
globals/skeleton/clipFromTable
skeleton.clipFromTable(clip: { [string]: any }) -> (string?, string?)
Encode a clip table (the shape clipToTable returns) to a zanim
payload, the bytes a .animation stores and bindClip/sampleClip
consume. Every field is required and every number finite. Inverse of
clipToTable. Returns nil and the reason, naming the field, when the
table is not a clip.
Parameters
clip{ [string]: any }— A clip table:{ name, duration, channels, bone_names }.
Returns (string?, string?) — The clip's zanim payload bytes, or nil and the reason.
local bytes = skeleton.clipFromTable(clip)
globals/skeleton/clipPack
skeleton.clipPack(packed: PackedClip) -> (string?, string?)
Encode a clip in packed form (the shape clipUnpack returns) into
zanim bytes. Channels may share one run of times by naming the same
keyOffset; interpolation defaults to Linear; with no boneNames the
clip names its bones in the order its channels first drive them.
times and values take a compute readback's resultBytes()
directly. Returns nil and the reason, naming the channel, when a
channel's keys fall outside the runs or its times run backwards.
Parameters
packedPackedClip— The packed clip.
Returns (string?, string?) — The clip's zanim payload bytes, or nil and the reason.
local bytes = skeleton.clipPack(packed)
globals/skeleton/clipShapes
skeleton.clipShapes(zanimBytes: buffer | string) -> { string }?
Decode a zanim payload and return the names of the blend
shapes (morph targets) its weight tracks drive, in the order the
tracks first name them. Returns nil on bytes that aren't a valid
zanim payload.
Parameters
zanimBytesbuffer | string— The clip'sdata.zanimpayload bytes (binary-safe).
Returns { string }? — Blend-shape names the clip drives, or nil.
local shapes = skeleton.clipShapes(assert(vfs.read(path .. "/data.zanim")))
globals/skeleton/clipToTable
skeleton.clipToTable(zanimBytes: buffer | string) -> { [string]: any }?
Decode a zanim payload to a table: { name, duration, channels = { { target_bone, path, keyframes_in, keyframes_out, interpolation } }, bone_names }, the shape clipDecode writes as JSON, built by the engine
in place. path is Translation, Rotation, Scale or Weights (a
blend shape's weight, one value a key, target_bone naming the shape);
interpolation is Linear, Step or CubicSpline. Inverse of clipFromTable.
Returns nil on bytes that aren't a valid zanim payload.
Parameters
zanimBytesbuffer | string— The clip'sdata.zanimpayload bytes (binary-safe).
Returns { [string]: any }? — The clip as a table, or nil.
local clip = skeleton.clipToTable(bytes)
globals/skeleton/clipUnpack
skeleton.clipUnpack(zanimBytes: buffer | string) -> PackedClip?
Decode a zanim payload into its packed form: a channel table
({ bone, path, interpolation, keyOffset, keyCount, valueOffset },
offsets 0-based element indices) and two buffers of little-endian
f32s, times and values, holding every channel's keys channel after
channel (3 floats a key for Translation and Scale, 4 for Rotation, 1 for
Weights, three times that for CubicSpline). A Weights channel's bone
names the blend shape it drives. The runs go straight into a typed buffer
(buf:writeBytes(packed.values)) for a compute pass. Returns nil on
bytes that aren't a valid zanim payload. Inverse of clipPack.
Parameters
zanimBytesbuffer | string— The clip'sdata.zanimpayload bytes (binary-safe).
Returns PackedClip? — The packed clip, or nil.
local packed = skeleton.clipUnpack(bytes)
globals/skeleton/jointTransforms
skeleton.jointTransforms(entityId: string | entityRef) -> table
Read a skinned entity's per-joint world transforms for the current animated pose.
Parameters
entityIdstring | entityRef— Engine entity id or proxy of a skinned entity.
Returns table — Array of joint transforms: { position, matrix, parent, name }.
local joints = skeleton.jointTransforms(meshId)
globals/skeleton/sampleClip
skeleton.sampleClip(handle: number, time: number, poseBuffer: Substrate.TypedBuffer) -> boolean
Sample the bound clip at time (clamped to [0, duration])
and write one stride-10 pose record per bound bone into the
Buffer, starting at index 0, then, for a clip bound with shapes,
one weight per shape and one coverage per shape. Bones the clip
does not drive are written as identity, or as their rest record for
a clip bound with a rest pose. Returns false on unknown
handle/buffer or a buffer too small for what the sampler writes.
Parameters
handlenumber— Sampler handle frombindClip.timenumber— Sample time in seconds.poseBufferSubstrate.TypedBuffer— The stride-10 pose buffer written into.
Returns boolean — True on success.
globals/skeleton/unbindClip
skeleton.unbindClip(handle: number) -> boolean
Drop the bound clip sampler from the registry.
Parameters
handlenumber— Sampler handle to remove.
Returns boolean — True if the sampler existed.
globals/skeleton/unbindPose
skeleton.unbindPose(sinkHandle: number) -> boolean
Remove the sink from the registry.
Parameters
sinkHandlenumber— Sink handle to remove.
Returns boolean — True if the sink was present.
typed/builtin//modules/api/engine/skeleton/skeleton/applyPose
skeleton.applyPose(sinkHandle: number, poseBuffer: Substrate.TypedBuffer) -> boolean
Snapshot the buffer's first layout.total_floats values and
queue a pending apply for the next ECS drain. Returns false on
unknown sink/buffer or buffer too small for the layout. The
Buffer is unchanged.
Parameters
sinkHandlenumber— Sink handle frombindPose.poseBufferSubstrate.TypedBuffer— The pose buffer to apply.
Returns boolean — True on success.
typed/builtin//modules/api/engine/skeleton/skeleton/bindClip
skeleton.bindClip(zanimBytes: buffer | string, boneOrder: { string }, restPose: { number }?, shapes: { ClipShape }?) -> ClipBindInfo?
Decode a zanim payload and bind it to boneOrder,
precomputing which of the clip's channels feed each bone so
per-frame sampleClip is allocation-free. With restPose (the
body's stride-10 rest, one record per bone of boneOrder), every
sampleClip writes the body's complete local pose: a bone the clip
does not name holds its rest record, and a bone it names takes the
clip's rotation, its rest translation plus the clip's displacement
from the clip's start, and its rest scale. With shapes (the
body's blend shapes), every sample writes after the bone records one
weight per shape and then one coverage per shape: a shape one of the
clip's weight tracks names (by any of the shape's names, exactly, else
ignoring case, spaces, _, - and .) takes the track's weight at
coverage 1, every other shape its rest weight at coverage 0.
boneOrder may be empty for a body with shapes and no bones. Returns
{ handle, matched, total, duration, shapesMatched, shapesTotal },
or nil on a malformed payload, a bind with neither bones nor shapes,
or a rest pose short of one record per bone. Check matched: 0 means
the clip drives none of these bones.
Parameters
zanimBytesbuffer | string— The clip'sdata.zanimpayload bytes (binary-safe).boneOrder{ string }— Output bone names — one stride-10 record per bone.restPose{ number }(optional) — The body's stride-10 rest pose; given, samples are complete local poses over it.shapes{ ClipShape }(optional) — The body's blend shapes, written after the bones.
Returns ClipBindInfo? — { handle, matched, total, duration, shapesMatched, shapesTotal }, or nil.
local info = skeleton.bindClip(bytes, layout.boneOrder, layout.restPose)
local face = skeleton.bindClip(bytes, {}, nil, { "mouthSmileLeft", "eyeBlink" })
typed/builtin//modules/api/engine/skeleton/skeleton/bindPose
skeleton.bindPose(entityId: (string | entityRef)?, opts: SkeletonLayout) -> number?
Register a pose sink targeting entityId. The opts table
carries the layout: boneOrder is the bone-name array
({"hip", "spine", ...}), stride defaults to 10
(translation.xyz + rotation.xyzw + scale.xyz). Pass entityId
as nil to use the current component's owning entity.
Parameters
entityId(string | entityRef)(optional) — Engine entity id or proxy, or nil for the current entity.optsSkeletonLayout—{ boneOrder, stride }.
Returns number? — Sink handle, or nil.
local h = skeleton.bindPose(nil, { boneOrder = bones, stride = 10 })
typed/builtin//modules/api/engine/skeleton/skeleton/clipBones
skeleton.clipBones(zanimBytes: buffer | string) -> { string }?
Decode a zanim payload and return its bone-name array. Pure:
build a bind order or a retarget map from a clip without binding a
sampler. Returns nil on bytes that aren't a valid zanim payload.
Parameters
zanimBytesbuffer | string— The clip'sdata.zanimpayload bytes (binary-safe).
Returns { string }? — Bone names referenced by the clip, or nil.
local names = skeleton.clipBones(assert(vfs.read(path .. "/data.zanim")))
typed/builtin//modules/api/engine/skeleton/skeleton/clipDecode
skeleton.clipDecode(zanimBytes: buffer | string) -> string?
Decode a zanim payload to its readable JSON form
({ name, duration, channels, bone_names }), the clip as text to
read, store or diff. The binary parse is the engine's. Code that
transforms a clip's channels in Luau (e.g. the retarget bake) reads
the same clip as a table with clipToTable, which skips the text.
Returns nil on bytes that aren't a valid zanim payload. Inverse of
clipEncode.
Parameters
zanimBytesbuffer | string— The clip'sdata.zanimpayload bytes (binary-safe).
Returns string? — The clip as a JSON string, or nil.
local json = require("@builtin::modules.json")
local clipJson = skeleton.clipDecode(bytes)
local clip = if clipJson then json.decode(clipJson) else nil
typed/builtin//modules/api/engine/skeleton/skeleton/clipEncode
skeleton.clipEncode(jsonString: string) -> string?
Encode a clip's JSON form (the shape clipDecode returns) back
to a zanim payload — the bytes a .animation stores and
bindClip/sampleClip consume. Inverse of clipDecode. A clip
held as a table encodes with clipFromTable, which skips the text.
Returns nil on invalid JSON.
Parameters
jsonStringstring— A clip JSON document.
Returns string? — The clip's zanim payload bytes, or nil.
local json = require("@builtin::modules.json")
local bytes = skeleton.clipEncode(json.encode(clip))
typed/builtin//modules/api/engine/skeleton/skeleton/clipFromTable
skeleton.clipFromTable(clip: { [string]: any }) -> (string?, string?)
Encode a clip table (the shape clipToTable returns) to a zanim
payload, the bytes a .animation stores and bindClip/sampleClip
consume. Every field is required and every number finite. Inverse of
clipToTable. Returns nil and the reason, naming the field, when the
table is not a clip.
Parameters
clip{ [string]: any }— A clip table:{ name, duration, channels, bone_names }.
Returns (string?, string?) — The clip's zanim payload bytes, or nil and the reason.
local bytes = skeleton.clipFromTable(clip)
typed/builtin//modules/api/engine/skeleton/skeleton/clipPack
skeleton.clipPack(packed: PackedClip) -> (string?, string?)
Encode a clip in packed form (the shape clipUnpack returns) into
zanim bytes. Channels may share one run of times by naming the same
keyOffset; interpolation defaults to Linear; with no boneNames the
clip names its bones in the order its channels first drive them.
times and values take a compute readback's resultBytes()
directly. Returns nil and the reason, naming the channel, when a
channel's keys fall outside the runs or its times run backwards.
Parameters
packedPackedClip— The packed clip.
Returns (string?, string?) — The clip's zanim payload bytes, or nil and the reason.
local bytes = skeleton.clipPack(packed)
typed/builtin//modules/api/engine/skeleton/skeleton/clipShapes
skeleton.clipShapes(zanimBytes: buffer | string) -> { string }?
Decode a zanim payload and return the names of the blend
shapes (morph targets) its weight tracks drive, in the order the
tracks first name them. Returns nil on bytes that aren't a valid
zanim payload.
Parameters
zanimBytesbuffer | string— The clip'sdata.zanimpayload bytes (binary-safe).
Returns { string }? — Blend-shape names the clip drives, or nil.
local shapes = skeleton.clipShapes(assert(vfs.read(path .. "/data.zanim")))
typed/builtin//modules/api/engine/skeleton/skeleton/clipToTable
skeleton.clipToTable(zanimBytes: buffer | string) -> { [string]: any }?
Decode a zanim payload to a table: { name, duration, channels = { { target_bone, path, keyframes_in, keyframes_out, interpolation } }, bone_names }, the shape clipDecode writes as JSON, built by the engine
in place. path is Translation, Rotation, Scale or Weights (a
blend shape's weight, one value a key, target_bone naming the shape);
interpolation is Linear, Step or CubicSpline. Inverse of clipFromTable.
Returns nil on bytes that aren't a valid zanim payload.
Parameters
zanimBytesbuffer | string— The clip'sdata.zanimpayload bytes (binary-safe).
Returns { [string]: any }? — The clip as a table, or nil.
local clip = skeleton.clipToTable(bytes)
typed/builtin//modules/api/engine/skeleton/skeleton/clipUnpack
skeleton.clipUnpack(zanimBytes: buffer | string) -> PackedClip?
Decode a zanim payload into its packed form: a channel table
({ bone, path, interpolation, keyOffset, keyCount, valueOffset },
offsets 0-based element indices) and two buffers of little-endian
f32s, times and values, holding every channel's keys channel after
channel (3 floats a key for Translation and Scale, 4 for Rotation, 1 for
Weights, three times that for CubicSpline). A Weights channel's bone
names the blend shape it drives. The runs go straight into a typed buffer
(buf:writeBytes(packed.values)) for a compute pass. Returns nil on
bytes that aren't a valid zanim payload. Inverse of clipPack.
Parameters
zanimBytesbuffer | string— The clip'sdata.zanimpayload bytes (binary-safe).
Returns PackedClip? — The packed clip, or nil.
local packed = skeleton.clipUnpack(bytes)
typed/builtin//modules/api/engine/skeleton/skeleton/jointTransforms
skeleton.jointTransforms(entityId: string | entityRef) -> table
Read a skinned entity's per-joint world transforms for the current animated pose.
Parameters
entityIdstring | entityRef— Engine entity id or proxy of a skinned entity.
Returns table — Array of joint transforms: { position, matrix, parent, name }.
local joints = skeleton.jointTransforms(meshId)
typed/builtin//modules/api/engine/skeleton/skeleton/sampleClip
skeleton.sampleClip(handle: number, time: number, poseBuffer: Substrate.TypedBuffer) -> boolean
Sample the bound clip at time (clamped to [0, duration])
and write one stride-10 pose record per bound bone into the
Buffer, starting at index 0, then, for a clip bound with shapes,
one weight per shape and one coverage per shape. Bones the clip
does not drive are written as identity, or as their rest record for
a clip bound with a rest pose. Returns false on unknown
handle/buffer or a buffer too small for what the sampler writes.
Parameters
handlenumber— Sampler handle frombindClip.timenumber— Sample time in seconds.poseBufferSubstrate.TypedBuffer— The stride-10 pose buffer written into.
Returns boolean — True on success.
typed/builtin//modules/api/engine/skeleton/skeleton/unbindClip
skeleton.unbindClip(handle: number) -> boolean
Drop the bound clip sampler from the registry.
Parameters
handlenumber— Sampler handle to remove.
Returns boolean — True if the sampler existed.
typed/builtin//modules/api/engine/skeleton/skeleton/unbindPose
skeleton.unbindPose(sinkHandle: number) -> boolean
Remove the sink from the registry.
Parameters
sinkHandlenumber— Sink handle to remove.
Returns boolean — True if the sink was present.