Log inGet started
Package

clothing.module

Newest version

This package holds more than this page lists. See all of its files in its world.

README.md

clothing

Layered clothing for humanoid bodies. A garment is a skinned mesh authored once on one body, the standard body (@builtin::avatars.humanoid) or any conforming humanoid, and fit wraps it onto any other conforming body without hand-fitting: a taller or broader body, a body in another bind pose, a body whose rig names its bones differently.

  • Each of the garment's bones is matched to the body's bone of the same humanoid role (bonesOf finds the roles from the shape of a skin whatever its joints are named).
  • Every vertex is carried by the bones that move it, from where it sits on the garment's body to the same place on the new one: each bone's length, the way it points and the body's size.
  • Then each vertex is laid as far off the new body's surface as it stood off the body it was authored on (when the garment states that body as reference), and outside the body and every garment layered under it (opts.under).
  • Every triangle keeps facing out: the way it faced on the body it was authored on, and the way the normals it is drawn with face, which turn with the fitted cloth. A fold the carry or the laying makes is turned back, and the cloth draws back toward where it stood before it was laid wherever that leaves one; each point that leaves inside a garment under it is then put outside again, alone, bridged from the points around it or with them lifted along, whichever turns nothing over.

The vertices are what is laid outside: between them an inner garment can still show through an outer one at its edges (a sleeve hem, the edges of an open front, under the arm).

Every distance is a share of the body's size (hips to head), so one garment fits a body measured in centimetres and one measured in metres alike (distances).

FunctionDoes
fit(garment, body, opts?)The garment's geometry bound to the body's skin, in the body's space
hide(surface, over, { size, covers?, bones? })The surface's triangles left once those the garments over cover are taken out; with covers, only what those parts of the body move, a part standing a little out through a garment included
covers(geometry, bones?)The parts of the body (torso, arms, ...) a skinned garment covers
shell(body, { covers, offset?, reach?, open?, smooth?, colour? })A garment cut from a body's own triangles (torso, arms, hands, legs, feet, head), set off its surface and smoothed into cloth; reach how far down the arms and legs it goes ({ arms = 0.35 } short sleeves, { legs = 0.45 } shorts), open an opening down the front, colour its vertex colour
bonesOf(skin){ [vrmBone] = jointName } for a humanoid skin, or nil

An avatar wears clothing through avatarAppearance: a worn item whose meshes are skinned to a humanoid skeleton is layered clothing, worn in a clothing slot (torsoInner, torsoOuter, legs, feet, hands; avatarAppearance.layers), fitted to the avatar's body, drawn by its skeleton, and the body and the clothing under it are not drawn where it covers them. A body's hair, ears and tail (the chains its descriptor names) lie over clothing and stay drawn, and of a body drawn as several meshes (a VRM's face, hair and outfit) the clothing is fitted to the one the torso and limbs move.

local clothing = require("@builtin::modules.clothing")
local avatarAppearance = require("@builtin::modules.avatarAppearance")

-- A shirt and a jacket cut from the standard body, saved as garments.
local standard = asset.resolve("@builtin::avatars.humanoid", "avatar"):definition().body
local body = require("@builtin::modules.bodyFacing").parts(standard).meshes[1]
local geometry = asset.resolve(body.guid, "mesh"):load():geometry()
local shirt = clothing.shell(geometry, { covers = { "torso", "arms" }, offset = 0.02 })
shirt.dest = "/source/clothes/shirt.mesh"
local shirtRef = asset.create("mesh", "shirt", shirt)

-- Worn on any conforming avatar, it fits that avatar's body.
local doc = avatarAppearance.new("@builtin::avatars.humanoid")
doc.worn = { { slot = "torsoInner", item = shirtRef.guid } }
avatarAppearance.apply(root, doc)