Avatars: attaching items, reading the body, refusing what a game cannot use, dressing a player, expressions
This guide is how a game reads and relies on an avatar. Making one, changing it, dressing it
and saving it to a person's account with the avatar toolbox is guides { path: "core/avatars" }.
Attach an item to a hand, the head, the back
The Humanoid component on an avatar's root seats an item on a standard
attachment point. The point is found on each body from its skeleton's shape, so
the same call works on a Synty, Mixamo, VRM or unnamed rig:
local h = entity(playerId).component.get("Humanoid")
h:attach("rightGrip", sword.id) -- in the right fist
h:attach("hat", helmet.id, { position = { 0, 0.02, 0 } }) -- on the crown
h:attach("bodyBack", backpack.id) -- on the back
h:attach("viewpoint", camera.id) -- at the eyes, riding the head
The 19 points: origin, hat, hair, faceFront, faceCenter, neckBase,
leftCollar, rightCollar, leftShoulderTop, rightShoulderTop,
bodyFront, bodyBack, waistFront, waistCenter, waistBack, leftGrip,
rightGrip, leftSole, rightSole. Each point's frame is the avatar's own
axes on a body in a T-pose with its palms down (+Y up, +Z forward, +X the body's
left), carried by the bone under it: a blade modelled along +Z and seated on
rightGrip leaves the fist on the thumb's side on every body. opts.position
and opts.scale are metres in that frame, whatever units the rig was authored
in. An item stays seated when the avatar swaps its body. The VRM bone names
(rightHand, head, leftUpperLeg) and the humanoid roles (righthand) seat
an item at the bone itself.
Read the body
h:descriptor() reads the body against the standard:
local d = h:descriptor()
print(d.height * d.scale) -- how tall it stands in the world
print(d.viewpoint.position.y) -- eye height
print(d.proportions.shoulderWidth) -- size a backpack to the body
print(d.points.rightGrip.bone) -- the bone that carries a point
proportions (head, shoulderWidth, hipWidth, torso, arm, leg, in
metres) sizes what the body wears. An avatar asset answers the same before it
is spawned: asset.resolve("hero", "avatar"):descriptor().
Turn away an avatar a game cannot use
h:validate() (or avatarRef:validate()) names every rule of the standard the
body breaks: a body that is not a humanoid, a missing required bone, an
attachment point it cannot carry, a face expression with no blend shape, a height
outside 0.5 to 3 m. summary says it in one line per rule in the player's
language, ready for a player:
local v = h:validate({ rules = { "type", "bone", "point", "height" } }) -- no faces needed
if not v.ok then
for _, line in v.summary do print(line) end
end
rules names what the game relies on; the default holds the body to all of
them. The avatarStandard module's README has the whole descriptor and the
expression tiers (VRM presets, Oculus visemes, ARKit).
Dress an avatar: the appearance document
How a person wears their avatar (which avatar, body shape, colours, worn items in
order, the animation pack, emotes, parameter defaults) is one small data document,
the avatarAppearance module's. It is ZeroMind's outfit document field for field,
so an outfit an account saved reads as it is. The Appearance component carries it
on the avatar root (the entity carrying Humanoid: player.avatar for a player)
as synced data: every peer receives the document (a few hundred bytes), never a
mesh, and composes the same character, the worn items seated on the standard
attachment points of whichever body it is. Put it on the player prototype's body
and every joining player carries one.
local avatarAppearance = require("@builtin::modules.avatarAppearance")
local doc = avatarAppearance.new("@builtin::avatars.humanoid")
doc.body_shape = { height = 1.9, legs = 1.15, shoulders = 1.2 } -- metres, then factors (1 as built)
doc.colours = { body = "#3366cc" }
doc.worn = {
{ slot = "hat", item = "@builtin::meshes.cone", adjust = { y = 0.06, scale = 0.25 } },
{ slot = "held", item = "my_sword" }, -- `held` is the right grip
}
-- the avatar root a player's body is: `player.avatar`, here the local player's
local body = layers.active.players.localPlayer.avatar
body.component.add("Appearance", {})
local look = body.component.get("Appearance")
look:wear(doc) -- every peer composes it
print(look:size(), look:address()) -- bytes on the wire, its sha256
Wearing another document recomposes only what differs: an item both wear stays
as it is. A game reads a player's appearance (look:get()) and changes what its
match shows without touching the player's document:
look:override({
worn = { hat = "team_helmet", held = false }, -- replace the hat, drop the held item
body_shape = { height = { min = 1.6, max = 1.8 } }, -- clamp the height
animation_pack = "match_locomotion", -- force a pack
})
Only the peer that owns an avatar writes its synced fields, so each player's own engine wears its document and sets the game's rules on its own body: a match flag the host flips on a synced entity of its own, read by every player's engine, turns the rules on everywhere, and every peer sees the result.
avatarAppearance.outfits() keeps named outfits with one current, in ZeroMind's
{ current, outfits } shape; avatarAppearance.fromDescriptor(d) reads a
profile's avatar_descriptor as a document. The module's README lists every
field, slot and adjustment.
A look that follows the player into every world
A person's look lives on their OrigoZero account: the outfits they saved and the
one they wear now. When a player joins a world, their own engine reads the
account and writes that look into the Appearance document of the body that
binds, so every peer sees it with no world script involved: the current outfit,
else the document the profile's avatar_descriptor maps to, else the avatar as
it stands. A body without Humanoid wears nothing, and a game's override rules
still apply over the account's look.
local avatarAppearance = require("@builtin::modules.avatarAppearance")
local doc = avatarAppearance.new("@builtin::avatars.humanoid")
doc.body_shape = { height = 2.0 }
doc.colours = { body = "#cc2222" }
doc.worn = { { slot = "hat", item = "@builtin::meshes.cone", adjust = { y = 0.05, scale = 0.25 } } }
local r = avatarAppearance.saveOutfit("Tall red", doc, { makeCurrent = true })
-- r: { ok, outfit, current } or { ok = false, error, declined?, code? }
local me = avatarAppearance.accountAppearance() -- { ok, outfits, current?, look?, from?, address?, account? }
avatarAppearance.wearOutfit("Tall red") -- by name or id; nil wears none
avatarAppearance.deleteOutfit("Tall red")
Saving, wearing and deleting an outfit change how the signed-in account appears
to everyone, and the local player then wears the account's new look. On a
person's sign-in the engine asks them in its own dialog first, naming the account
it changes. On an agent account's own sign-in (me.account.isAgent) a write asks
nobody and is the agent's own: ZeroMind decides it by the agent's credential and
never changes the person's look with it. When ZeroMind refuses such a write
(code = "AGENT_APPROVAL_REQUIRED", with agentAccount naming the account), the
agent's look is the one it wears in the session, which every peer in the world
sees. A worn item travels to other worlds by its reference, so an item
meant to follow the player is a built-in asset or a published one every world
resolves.
The person does all of this themselves on the Outfits tab of the app menu,
in every world and in the editor (its account menu opens it): the look they
wear now, their saved outfits, Save for the look their avatar wears, and Wear
and Delete for each outfit. appMenu.open("outfits") puts it in front of them.
An agent changing its person's look
An agent signed in as its own agent account changes the look of the person it acts for by asking, and the person decides from their own sign-in:
local person = avatarAppearance.accountAppearance({ forPerson = true }) -- their outfits, read only
local r = avatarAppearance.saveOutfit("Vita", doc, { makeCurrent = true, forPerson = true })
-- r: { ok, state = "pending" | "applied", id, note, request }
avatarAppearance.wearOutfit("Pirate", { forPerson = true }) -- one of the person's outfits
local now = avatarAppearance.agentRequest(r.id, { waitSeconds = 60 }) -- its outcome
A request waits (state = "pending") and changes nothing until the person
approves it. The person allows a change in one of two ways: they approve it on
their Outfits tab (or in ZeroMind's Settings, Bot accounts), where it shows
what it asks for and the parts of their look it changes, or they let that agent
change their look without asking, after which each request applies as it is
made (state = "applied", decidedVia = "standing"). Either way the change is
listed on their Outfits tab as the agent's, with Undo while it is still worn.
An agent never deletes one of the person's outfits, and no agent credential
approves a request or gives itself a permission. On the person's sign-in the
same decisions are approveAgentRequest(id) (asked in the engine's dialog),
declineAgentRequest(id), undoAgentRequest(id), agents() and
allowAgent(id, allow) (letting it is asked in the engine's dialog, naming the
agent). A ZeroMind that does not serve agent requests refuses each of these
code = "AGENT_REQUESTS_UNAVAILABLE", with nothing asked and nothing changed.
Expressions: a hat toggle, a face, a wagging tail, a puppet
An avatar carries its own expressions as data, with no script: parameters (named bools,
ints 0 to 255 and floats -1 to 1, synced or local, saved or not), an animator (layers,
each a state machine over the parameters, whose states pose blend shapes and bones, show and
hide parts, set shader data and play .animation clips) and an expression menu the person works from the app
menu's Expressions tab with a mouse, a finger or a gamepad. Every peer runs the same animator
from the parameters it receives, so a toggle reaches everyone within a tenth of a second and a
player who joins later sees the avatar as it stands.
local hero = asset.create("avatar", "fox_hero", {
body = body,
parts = { -- seated on every peer
{ name = "Hat", mesh = "@builtin::meshes.cone", point = "hat", scale = 0.25 },
{ name = "Tail", mesh = "@builtin::meshes.cylinder", point = "waistBack", -- swings from the hips
position = { 0, 0, -0.15 }, rotation = { 90, 0, 0 }, scale = { 0.05, 0.3, 0.05 } },
{ name = "Ear_L", mesh = "@builtin::meshes.cone", point = "hat", position = { 0.08, 0, 0 }, scale = 0.1 },
},
parameters = {
{ name = "Hat", type = "bool", default = true, saved = true },
{ name = "Mood", type = "int", saved = true }, -- 0 neutral, 1 happy, 2 sad
{ name = "EarAngle", type = "float", saved = true },
},
animator = { layers = {
{ name = "Hat", states = { { name = "On" }, { name = "Off", motion = { hide = { "Hat" } } } },
transitions = { { from = "On", to = "Off", when = "!Hat", duration = 0 },
{ from = "Off", to = "On", when = "Hat", duration = 0 } } },
{ name = "Face", states = { { name = "Neutral" },
{ name = "Happy", motion = { shapes = { happy = 1 } } }, { name = "Sad", motion = { shapes = { sad = 1 } } } },
transitions = { { to = "Happy", when = "Mood == 1", duration = 0.2 }, { to = "Sad", when = "Mood == 2", duration = 0.2 },
{ to = "Neutral", when = "Mood == 0", duration = 0.2 } } },
{ name = "Tail", states = { { name = "Wag", motion = { blend = "Voice", motions = {
{ at = 0, motion = {} },
{ at = 1, motion = { length = 0.5, keys = {
{ t = 0, bones = { Tail = { rotation = { 0, -30, 0 } } } },
{ t = 0.25, bones = { Tail = { rotation = { 0, 30, 0 } } } } } } } } } } } },
{ name = "Ears", states = { { name = "Puppet", motion = { blend = "EarAngle", motions = {
{ at = 0, motion = {} }, { at = 1, motion = { bones = { Ear_L = { rotation = { 0, 0, 60 } } } } } } } } } },
} },
menu = {
{ type = "toggle", label = "Hat", parameter = "Hat" },
{ type = "submenu", label = "Mood", items = {
{ type = "toggle", label = "Happy", parameter = "Mood", value = 1 },
{ type = "toggle", label = "Sad", parameter = "Mood", value = 2 } } },
{ type = "radial", label = "Ears", parameter = "EarAngle" },
},
})
print(hero:animator().syncedBits, hero:animator().cost.units) -- 25 bits; the work a frame does
A state plays an animation clip with motion = { clip = "A_Wave", loop = false, speed = 1 }
(A_Wave and A_Dance here name .animation assets the world holds; any clip on a humanoid
rig plays on any humanoid body):
a gesture or an emote on the body, under the layer's mask (a region such as rightArm or
upperBody, roles or bone names) and weight, while the locomotion keeps the legs. A clip
crossfades with the layer's transitions and stands in a blend beside poses. Every peer plays
it at the same point: the animator runs on the session clock and starts a state at the moment
the avatar channel dates the parameter that entered it (or the emote's start time).
animator = { layers = {
{ name = "Gestures", mask = { "rightArm" },
states = { { name = "Rest" }, { name = "Wave", motion = { clip = "A_Wave" } } },
transitions = { { from = "Rest", to = "Wave", when = "Gesture == 1", duration = 0.2 },
{ from = "Wave", to = "Rest", when = "Gesture != 1", duration = 0.2 } } },
{ name = "Emotes", mask = { "upperBody" },
states = { { name = "None" }, { name = "Dance", motion = { clip = "A_Dance" } } },
transitions = { { from = "None", to = "Dance", when = "Emote == 3" },
{ from = "Dance", to = "None", when = "Emote != 3" } } },
} }
-- anim:set("Gesture", 1) waves on every peer; anim:emote(3) dances; anim:layers().Gestures.clips[1].time
Emote names an emote for the 10 seconds after it starts. An emote clip that plays once
(loop = false) bounds its state by EmoteTime, the seconds since the emote started: enter on
when = { "Emote == 3", "EmoteTime < 1.5" } and leave on "EmoteTime >= 1.5" (1.5 being the
clip's length), so the body returns to its locomotion when the clip ends.
Voice is a built-in parameter: how loud the owner speaks while their microphone runs (the
Expressions tab has the switch). The built-ins (Grounded, Speed, VelocityX/Y/Z,
Voice, Viseme, Emote, EmoteTime, IsOwner, TrackingMode, Gait) are read-only.
parts are the avatar's own pieces beyond its body, each a mesh seated on an attachment point
(with a material and a color if it needs them); every peer seats its own copy. A part turns
about the point it hangs from, its mesh placed in the point's frame (+Y up, +Z the way the body
faces, +X its left). The person
opens the tab with the pause menu, and a script with appMenu.open("expressions"); its rows
are the elements expressions-1, expressions-2, ... in the order the menu lists them. A name in bones, show and hide is any entity under the
avatar: a bone of the body (turned on top of the locomotion playing on it), a declared part or
anything else seated on it (turned from where it was seated), or an attachment point, which
names everything worn there (hat names the appearance's worn hat too).
A game or a component of the avatar's own reads and sets the same parameters through the
AvatarAnimator on the avatar root (anim:set("Hat", false) on the peer that owns it,
anim:get("Speed") anywhere). Saved parameters come back when the person returns: they are
written into the appearance document, so an outfit saved on the account carries them, and the
values the person sets themselves from the Expressions tab are kept on their device for that
avatar. A value a script sets (a world's or an agent's) is never written to the person's
device, so persistence is checked by hand: play, change it in the tab, leave and come back. More than 256 synced bits are refused when
the avatar is created, the overrun stated. The avatarAnimator module's README has the whole
data form and what cost counts.