Skip to content

Scenes: several objects in one picture

nwn-bake scene <spec.json> <out.png> draws placeables, models, creatures and items together, each placed, turned and scaled, at one camera: two models side by side at the same scale, a chess board, a lineup of creatures. The other pictures (thumb, placeable-thumb, item-thumb) are one object each, framed by itself at a fixed tilt.

nwn-bake scene <spec.json|-> <out.png|out.webp> [--frames-dir <dir>] [--items <dir>] [--strict-items] [--module <module>] [--root <install>] [--user <folder>] [--tlk <name>]

The spec is JSON, read from the file or from stdin (-). Its schema is scene.schema.json. serve takes the same spec as a request (below). The picture is drawn with Moonglow's renderer, as the other pictures are, so it needs a GPU or Mesa lavapipe.

The spec

{
  "width": 1200, "height": 800,
  "objects": [
    {"placeable": 112, "position": [0, 0, 0]},
    {"creature": "blueprints/nw_goblina.utc", "position": [-1.5, 0, 0], "facing": 270},
    {"item": "blueprints/nw_wswls001.uti", "position": [1.5, 0, 1], "scale": 2},
    {"model": "plc_a01", "position": [3, 0, 0], "textures": [["plc_a01", "plc_a02"]]}
  ],
  "camera": {"yaw": -90, "pitch": 30},
  "lines": [{"from": [0, 0, 0], "to": [8, 0, 0], "colour": "#ffcc00"}],
  "axes": [{"at": [0, 0, 0], "length": 1}],
  "points": [[0, 0, 0], [8, 8, 0]],
  "light": "day",
  "shadows": false,
  "background": "#1a1c24"
}

Coordinates are the game's: metres, x east, y north, z up. Paths are read as given (relative to the current folder). Everything but one object, line or axis marker may be left out. Unknown fields are an error, and so is a spec that does not check: it is checked before the game is opened.

  • width, height: the picture, 1 to 8,192 pixels a side (1024 by 768).
  • objects: each one of
  • placeable: a row of placeables.2da, drawn as a placed placeable shows it (its idle animation and its particles);
  • model: a model by resref, on its own;
  • creature: a creature blueprint (.utc, or nwn_gff's .utc.json) or a character (.bic), dressed in what it wears;
  • character: a character described in the spec, with no file: a race, a gender, a phenotype, a cloak, a robe, armour parts and a horse (Characters);
  • item: an item blueprint (.uti or .uti.json), as item-thumb draws it.

And for each: - position: its model's origin ([0, 0, 0]); - facing: degrees counter-clockwise from east, as the game's GetFacing (270: south, towards the default camera). The game's models face north unturned, so a model is turned by its facing less 90. A placeable of a .git with Bearing b (radians) faces b in degrees plus 90; - scale: its size, 1 as the game draws it; - textures: [old, new] texture names, as ReplaceObjectTexture replaces them: on a creature's body, not on what it wears; - anim, t: the animation and the seconds into it. A creature or item stands in pause1, a placeable or model in its idle state (else default). - camera: where the picture is taken from. Every field may be left out: - target: the middle of the picture (the middle of the box round everything drawn); - position: where the camera is. With target, the camera looks from here at the target. Without, it looks from here along yaw and pitch, at a target distance (10) metres away; - yaw: the camera's side of the target, degrees counter-clockwise from east (-90: from the south, looking north); - view: front, back, left, right or side (the same as right): the side of the first object the camera is on, by that object's facing, in place of yaw. From the right, the object faces the picture's right. Not with position; - pitch: the camera's height above the horizon, -89.9 to 89.9 (30, as area-iso's corner views). 89.9 looks straight down; with a yaw of -90, north is up; - distance: metres from the target (as near as shows everything drawn, with 2.5% to spare a side); - fov: the field of view, top to bottom, in degrees (40, as the other pictures); - orthographic: true for a picture in which a thing is the same size near and far; - scale: in an orthographic picture, pixels a metre (as large as shows everything drawn). - lines: straight lines a pixel wide, from, to and colour (#rrggbb or #rrggbbaa, white when left out). An object in front of a line hides it. - axes: axis markers: lines from at, length metres (1) east in red, north in green and up in blue. - points: points to find in the picture. Nothing is drawn for them; the answer gives their pixel positions. - light: "day", the light of the other pictures (the default), or the sun as an area has it: {"ambient": "#rrggbb", "diffuse": "#rrggbb", "toward": [x, y, z]}, the colours as the .are gives them (SunAmbientColor, SunDiffuseColor) and the direction towards the sun (the game's default sun's when left out). - shadows: the sun's shadows, cast by every object onto the placeables and models (a board or a floor under the others), at the Shadow Opacity of 60 most of the game's areas have. Off by default. - background: "transparent" or "#rrggbb", as area-iso's --background (#1a1c24, the other pictures' dark grey). - turntable: frames of the camera turning round its target, written as an animated WebP (Turntables).

The framing takes in the objects as they stand (each one's box in its animation), the lines and the axis markers, but not the points.

Orthographic pictures

Moonglow's renderer draws in perspective only. An orthographic picture is taken through a long lens: the camera stands 2,000 m plus 200 times the scene's radius from the target, with a field of view narrow enough for the picture's height in metres. A thing at the far side of the scene is drawn under 1% smaller than at the near side. With position, only its direction from the target counts.

Transparent pictures

The renderer clears to a colour. A transparent picture is drawn twice, on black and on white, and each pixel's alpha is how little of the white shows through; its colour is the one on black over its alpha. It takes twice as long.

Turntables

A turntable is the scene seen from all round: the camera turns round its target, and each frame is a picture.

{
  "width": 600, "height": 800,
  "objects": [{"character": {"race": "elf", "gender": "female", "cloak": 1}, "anim": "walk"}],
  "camera": {"view": "front", "pitch": 12},
  "turntable": {"frames": 36, "delay": 80, "animate": true}
}
nwn-bake scene turntable.json out.webp --frames-dir frames
  • frames: how many, 2 to 720.
  • degrees: how far the camera turns over them, counter-clockwise seen from above (360). Frame i is i times degrees over frames round from the camera the spec gives, so a whole turn loops without showing a frame twice.
  • delay: how long each frame shows in the animation, in milliseconds (100: ten frames a second).
  • animate: each object's animation plays with the frames, frame i being i delays past the object's t. Off, every frame has the object's own t.
  • quality: the WebP's quality, 0 to 100 (90); lossless: every pixel kept instead, a larger file.

The objects are read and composed once, their textures sent to the GPU once; each frame then only moves the camera (and with animate, the objects' time). 36 frames of a character, 600 by 800, take 2.0 s on Mesa lavapipe, where 36 scene runs of one picture each take 38 s.

The camera keeps its target, its height and its distance (in an orthographic picture, its scale) all the way round. A distance or scale left out is the one that frames the scene from every side, so it stays one size as it turns: a long scene is framed for its long side. A camera at a position turns round its target at the distance it stands. With animate, the framing takes in each object as it stands in every frame.

The output is an animated WebP that loops for ever, so out ends in .webp; a spec without a turntable is a PNG. With --frames-dir, each frame is also written there as a PNG: 0000.png, 0001.png, ... (the folder is made). A GIF or a WebM is left to whatever reads the frames.

Characters

A picture of an armour, a cloak, a robe, a backpack or a mount needs someone to wear it. character describes one in the spec instead of in a .utc built for the purpose:

{
  "width": 900, "height": 900,
  "objects": [{"character": {"race": "elf", "gender": "female", "phenotype": 3, "cloak": 1, "tail": 16}, "anim": "run", "t": 0.3}],
  "camera": {"view": "side", "pitch": 12}
}
  • race: a racialtypes.2da row, by number or by its Label (any case: "human", "halfelf"); its Appearance is the body. Human when left out. appearance: an appearance.2da row instead of the race's.
  • gender: "male" (the default) or "female", or a gender.2da row.
  • phenotype: a phenotype.2da row (0): 0 normal, 2 large, 3 and 5 mounted. A part the phenotype has no model of is its DefaultPhenoType's, as the game finds it: a rider's head is phenotype 0's.
  • head: the head's number (1). 0 is no head.
  • body: body parts other than the first, by part ({"torso": 2}). Every part left out is 1, but the belt and the shoulders, which a bare body has none of (0), as the toolset makes a new creature. A part is named as in the toolset's fields (torso, lshin, rfarm, lshoul, ...) or as in its models (chest, shinl, forer, shol, ...).
  • armour: an armour's parts by the same names, robe among them ({"torso": 5, "lshoul": 3, "robe": 4}). A part of 0 or 1 shows the body's, as in the game. The character is given the armour proficiency the armour needs, so it is not taken off.
  • robe: a parts_robe.2da row (the same as armour's robe); cloak: a cloakmodel.2da row; wings: a wingmodel.2da row.
  • tail: a tailmodel.2da row. The game's horses are tails (c_horse1a, row 16 in the game's table) under a rider of a mounted phenotype.
  • colours: PLT colours by layer: skin, hair, tattoo1, tattoo2 on the body; cloth1, cloth2, leather1, leather2, metal1, metal2 on the armour and the cloak (0 when left out).

The object's anim and t pose it, as a creature's (pause1); the horse moves with its rider (run, walk). The game's own mounted cloaks (pmh3_cloak_001 and the like) are empty models, so a rider wears no cloak without a hak that has them: give the user folder with the haks (--user).

Equipped items

A creature blueprint names the items it wears by resref. They are looked up as for thumb: in the folder --items names first (<resref>.uti or <resref>.uti.json, subfolders too), then the user folder's override and haks, then the game. An item found nowhere is left off the creature, with a warning on stderr that names the object, the item and its slot, and in the answer's missing_items. With --strict-items, it fails the picture instead.

The answer

scene prints one line of JSON on stdout:

{
  "width": 1200, "height": 800,
  "camera": {"eye": [0.0, -14.2, 9.1], "target": [0.0, 0.0, 0.9], "fov": 40.0, "orthographic": false, "scale": 58.3},
  "bounds": [[-2.1, -0.6, 0.0], [8.0, 0.7, 2.3]],
  "points": [[600.0, 455.2], [1012.7, 301.4]],
  "objects": [
    {"kind": "placeable", "bounds": [[-0.5, -0.5, 0.0], [0.5, 0.5, 1.1]], "missing_models": [], "missing_items": []}
  ]
}
  • camera: where the camera was (eye), what it looked at (target), its field of view in degrees (the long lens's, when orthographic) and the pixels a metre at the target (everywhere, when orthographic). For a turntable, the first frame's.
  • bounds: the box round everything drawn, lowest corner then highest.
  • points: each point's pixel position from the picture's top-left corner, in the spec's order; null for a point behind the camera.
  • frames: a turntable's frames, in their order: each one's camera and points, as above. Not there without a turntable.
  • objects: one for each object, in the spec's order: its kind (placeable, model, creature, character or item), its box, the models it names that the game does not have or cannot read (name, or name: why), and the equipped items not found ({"slot", "resref"}, as serve gives them).

In serve

{"scene": {"objects": [{"placeable": 112}]}, "out": "/path/to/out.png", "items": "/path/to/uti", "strict_items": false}

scene is the spec, out the PNG to write (with a turntable, the animated WebP), frames_dir a folder for a turntable's frames as PNGs (--frames-dir), items and strict_items as for a creature's picture. The answer is the one above, with "ok": true.