Log inGet started
World

Builtin Library

Branchmain
Branchesmainpublish
Commit5597fb7c06

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

NameUnitRangeWhat it shapes
heightmetres0.5 to 3the standing height
widthfactor0.5 to 2across the whole body
legsfactor0.6 to 1.5the length of the legs, hip to ankle
armsfactor0.6 to 1.5the length of the arms, shoulder to wrist
torsofactor0.6 to 1.5the length of the torso, hips to neck
headfactor0.6 to 1.6the size of the head
shouldersfactor0.6 to 1.6the width of the shoulders
hipsfactor0.6 to 1.6the 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): whether name is 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 }. joints is the form skeleton.rebind takes, bones the shaped skeleton (its rest pose the shaped bind) and factor the uniform scale height took. 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 bodies derive has built since the engine started.
  • specKey(spec): the key a rebind spec is shared under, equal for two specs skeleton.rebind bakes the same.
  • structureOf(bones): the rig structure of a skeleton in the deforms().bones form.