Log inGet started
World

Builtin Library

Branchmain
Branchesmainpublish
Commit15ce14a4c1

README.md

bodyFacing

Which way a skinned body bundle visibly faces, measured from its skeleton, and the turn that stands it facing -Z, the forward every entity states.

An entity's forward is its local -Z: transform.forward, entity:lookAt, a PlayerSpawn's heading, capture's local front and Locomotion's default forward all read it. A body file faces whichever way its art pipeline authored it (+Z for a Synty or Rocketbox FBX, a VRM 1.0 or a Khronos-convention glTF, -Z for a VRM 0.x, sideways or lying down under the nodes of some exports). A body composed under a front entity turned by alignment(front(parts(bundle))) faces the -Z of front's parent whatever its file did. Locomotion.forward is stated in the frame of the child of its entity that it turns, so front sits under that child:

character       (placed, turned by lookAt / a spawn)
  body          (Locomotion turns this one about up)
    front       (alignment(front(parts(bundle))))
      <bundle nodes>
local bodyFacing = require("@builtin::modules.bodyFacing")
local body = entity.spawn("body", { parent = character.id })
local front = entity.spawn("front", { parent = body.id })
front.localRotation = bodyFacing.alignment(bodyFacing.front(bodyFacing.parts(bundle)))
bundle:instantiate(front)

The avatar asset type composes every body this way, and characterController.install composes the mesh it is given this way under its character_mesh child.

Exports

  • parts(body) -> parts? — what a body bundle is made of: { bundle, meshes, rig, unit, up, template }, the bundle, the skinned meshes its template's SkinnedModels name, the .rig of the first, metres per rig unit and the body's vertical in the rig's space. Nil for a body with no skinned mesh or source rig.
  • front(parts) -> { x, 0, z }? — the way the body visibly faces at rest in the frame its bundle is composed into: the rig's facing (the hip line crossed with the stand axis) turned by the rotations of the skinned mesh's record and every record above it, so a Z-up skeleton stood upright by a node is measured as it is drawn. Nil for a body whose rig names no hips, neck and legs.
  • frontInTopRecord(parts, front) -> { x, y, z }? — that front in the frame of the record holding the skinned mesh among the children of the entity the bundle is composed onto, the record a Locomotion on that entity turns.
  • alignment(front) -> { x, y, z, w } — the turn about +Y that stands front on -Z; the identity for a nil front.