Bring in a model and make it a unit
Drop a glTF or GLB on the editor's Assets panel and click Set up as a unit: it writes looks.json, which the view lays over its code. In code, it's a model on the type's look.
ts
// in src/game.ts
import { type GameView, layFiles } from '@v12-engine/client'
import { createGame } from '@v12-engine/engine'
import { LOOKS_FILE } from '@v12-engine/client/looks-file'
import looksFile from './looks.json'
import { rules } from './rules'
/** The looks as written in code: a model by its path in the game's models/ */
const looks: GameView['units']['looks'] = {
archer: {
height: 1.6,
// the model is the whole look: no parts of primitives besides it
shapes: [],
model: {
src: 'units/archer.glb',
scale: 0.8,
// which clip plays for what: the model's clip names (idle, walk, attack, cast, channel, work, death, sleep)
animations: { idle: 'Idle', walk: 'Run', attack: 'Shoot', death: 'Die' }
}
}
}
// what the editor's Set up as a unit wrote (`looks.json`) wins over the code, field by field
export const view: GameView = layFiles(
{
files: { assets: 'games/mygame' },
units: {
looks
}
},
[[LOOKS_FILE, looksFile]]
)
export const game = createGame(rules).view(view)Done: the archer is drawn from units/archer.glb and plays Run as it walks, Shoot as it attacks. Anything the editor wrote in looks.json wins, field by field.
Use a shared model
ts
import { characters } from '@v12-engine/assets'
model: { src: characters.models.knight, scale: 0.6 }In the editor
- Open Window › Assets and drop the file. A glTF with its files becomes one GLB, made smaller on the way.
- Pick it and click Set up as a unit…: scale, turn, clips, team colour.
- Click Look into it to see triangles, materials, clips and cost. The Icon and Sounds tabs give the type its picture, portrait and sounds.
- Click Make lighter levels to add levels of detail (or run
npm run lod). - Click Split into models… to turn one file into a model per part.
Reference
| Look field | What it does |
|---|---|
model.src | Path in the game's folder (files.assets), or a shared model. |
model.scale | Size. |
model.animations | Clip names by action: idle, walk, attack, cast, channel, work, death, sleep. |
shapes | Primitive parts; [] when the model is the whole look. |
height | Where its plate and effects sit. |
See Models and animation, Shared art and Pick what is drawn far away.