Skip to content

Unit portraits ​

The portrait box in the HUD shows the selected unit's face, live: its model playing its idle, framed on its head and shoulders. While someone speaks, it shows the speaker talking instead, as a classic RTS shows a transmission.

Quick start ​

ts
// a type's portrait, in its look (or in looks.json)
looks: { giant: { ...giant, portrait: { distance: 2.4, angle: 0.3, talk: 'Roar', moods: { angry: 'Roar Loud' }, background: '#1b2433' } } }

The giant's portrait is now closer, turned a little, roars when it talks and roars louder when angry.

Common tasks ​

Use pictures instead of live faces ​

ts
hud: { portraits: 'picture' } // 'live' when left out
client.hud.setPortraits('picture')

A game of pictures never loads the portrait stage's code. The picture comes from PortraitLook.picture, IconSet.portraits, IconSet.units, or the type's glyph.

Make a unit talk in the portrait box ​

Any line whose speaker has a face shows them talking: a cinematic's cut.say, the dialog lane, the rules' world.dialog.say, a mission rule's say.

ts
// someone not on the map, closer, angry
await cut.say('td.giant', 'Who crosses my bridge?', { portrait: { type: 'giant', zoom: 1.3 }, emotion: 'angry' })
// a rules' line said by a named unit of the map
world.dialog.say('everyone', { speaker: 'td.giant', text: 'line.bridge', unit: 'bridgeGiant', emotion: 'angry' })

Show the speaker in the dialog box instead ​

ts
cinematics: { dialog: { portraitIn: 'box' } } // 'hud' where the HUD's faces are live
client.setDialogLook({ portraitIn: 'box' })

With nothing selected (no portrait box up), the dialog box shows the speaker anyway.

Put a portrait on your own canvas ​

ts
const box = client.portraits.box(canvas, { every: 2 }) // draw every other frame
box.show({ unit: selectedId })
box.show({ type: 'giant' }, { talking: true, emotion: 'angry' })
box.setVisible(false)
box.stop()

client.portraits.show(canvas, spec, options) shows a single portrait (still: false: no picture where it can't be live).

Editor ​

  1. Open the unit's model in the Model view.
  2. Pick the Portrait tab.
  3. Set distance, height, angle and the light; the face updates as you go.
  4. Save: it is written to the game's looks.json under portrait.

Reference ​

Who a portrait shows (PortraitSpec) ​

SpecShows
{ unit: 'hero' }a unit on the map (a name, a ref, an id)
{ type: 'giant' }a unit type, for someone not on the map
{ model: 'herald.glb' }a model of its own
an image addressa picture
mode: 'still'a picture of the type's model instead of a live face
zoomcloser

A line's portrait can also set any field of PortraitLook over the type's.

A type's portrait (PortraitLook, UnitLook.portrait) ​

FieldWhat
picturethe picture used for 'picture' portraits and while the face loads
modela portrait model of its own (the unit's when left out)
distance, height, angle, pitch, fovthe camera
framewhat the camera sees; left out, fitted to head and shoulders from the bounds and head bone
scalethe model's size
lightcolor, intensity, direction, ambient
backgroundCSS behind it
idlethe clip it plays at rest
talkthe clip it talks in; false for no movement
moodsa talk clip per emotion

looks.json's portrait is laid over the code's, field by field.

How a face talks ​

It plays, in order of what exists: the line's talk, the look's clip for the line's emotion (moods), a talk <mood> clip, the look's talk, a portrait talk or talk clip. With none, it plays its idle and nods its head.

Framing ​

  • A unit: head and shoulders.
  • A building, a resource, anything not a unit (by its type's kind, PortraitHost.kindOf), or a headless unit wider than tall: whole, seen three quarters from above and its right, filling the round box.
  • A type with no model: its parts (UnitLook.shapes), seen a little from its right.

How it is drawn ​

A copy of the model stands on a stage of its own (a scene never drawn to the screen), drawn by a side view of the renderer straight onto the box's canvas, with nothing read back. The box follows the selection without making its target again, shows the picture until the face is drawn (PortraitOptions.onDrawn), and keeps the picture where it can't be live (no model, a model that failed). It draws nothing while out of sight. The HUD's box draws every other frame (PortraitOptions.every: 2).

The box shows in the selection sheet (one unit), the group panel (the subgroup's first unit, Tab to the next) and the hero panel.

What it costs ​

On a fast GPU at 2× DPR, one live face is lost in the noise. Nine faces cost about 2 ms a frame drawn every other frame, 2.9 ms every frame.