bodyShape.module
This package holds more than this page lists. See all of its files in its world.
README.md
bodyShape
A humanoid body reshaped by name, baked into a derived body. A shape names the
body's standing height in metres and, as factors where 1 is the body as built,
its width across the whole body, the length of its legs, arms and torso,
the size of its head and the width of its shoulders and hips, plus weights
for the blend shapes the body carries. The derived body's rest pose is its bind
pose, so everything that reads the skeleton (a retargeted clip, the attachment
points, the viewpoint, the height) reads the shaped body, and it costs a frame
what the body it was derived from costs.
The avatar toolbox's avatar.shape reshapes the worn avatar through this
module, and an Appearance document states a character's shape as
body_shape = { legs = 1.2, shoulders = 1.3 }.
Parameters
| Name | Unit | Range | What it shapes |
|---|---|---|---|
height | metres | 0.5 to 3 | the standing height |
width | factor | 0.5 to 2 | across the whole body |
legs | factor | 0.6 to 1.5 | the length of the legs, hip to ankle |
arms | factor | 0.6 to 1.5 | the length of the arms, shoulder to wrist |
torso | factor | 0.6 to 1.5 | the length of the torso, hips to neck |
head | factor | 0.6 to 1.6 | the size of the head |
shoulders | factor | 0.6 to 1.6 | the width of the shoulders |
hips | factor | 0.6 to 1.6 | the width of the hips |
A blend shape takes a weight from 0 to 1 (blendRange). A value outside its
range is held to the range.
How a shape composes
Every factor composes from the body as built: the legs, arms and torso stretch
along their bones, the head scales about its joint, the shoulders and hips widen
across the body, width widens all of it, the feet stay on the ground, and
height then scales the result about the ground under the hips to the height
named. The body's frame (up, left and facing) is read from its hips, its neck or
head and both upper legs.
local bodyShape = require("@builtin::modules.bodyShape")
local result, err = bodyShape.deforms(bones, roles, { legs = 1.2, head = 0.9 })
if result then
local body = bodyShape.derive(meshGuid, meshBytes, { joints = result.joints })
-- draw body.mesh with body.bones, then let it go:
bodyShape.release(body)
end
Functions and fields
parameters: the parameters in the order they compose, each{ name, unit, min, max, about }.ranges: each parameter's{ min, max }by name.blendRange: the weight range of a blend shape.isParameter(name): whethernameis one of the parameters.clamp(name, value): the value held to its range, or nil for a value that is not a finite number.bindSkeleton(bones): the bind pose of a skeleton's bones in the mesh's model space, or nil when a bone has no invertible inverse bind.framed(bones, roles): whether a body's bones and humanoid roles carry the frame a shape is read against.deforms(bones, roles, shape, heightOf?): the joint deformations that give a body a shape,{ joints, bones, factor }.jointsis the formskeleton.rebindtakes,bonesthe shaped skeleton (its rest pose the shaped bind) andfactorthe uniform scaleheighttook. Returns(nil, reason)when the body carries no frame to read.derive(meshKey, meshBytes, spec): the derived body of a skinned mesh under a rebind spec,{ key, mesh, bones }. One derived body is made per mesh and spec and shared by every holder of it; it raises naming what the spec cannot take.release(body): lets a derived body go; once nothing holds it, its mesh is released.held(): the derived bodies held now,{ { key, holders } }.builds: how many derived bodiesderivehas built since the engine started.specKey(spec): the key a rebind spec is shared under, equal for two specsskeleton.rebindbakes the same.structureOf(bones): the rig structure of a skeleton in thedeforms().bonesform.