Skip to content

Photo mode

Wraith has a free camera and posing built in, which players reach through Photo mode. They need the game’s camera and characters, and that’s where a plugin for the game, or its engine, comes in. It hooks where the game sets them each frame and hands them over. Wraith does the rest: the keys, settings, windows and drawing.

The Unity plugin does both for Unity games, and the Unreal plugin for Unreal ones, so a game on those only needs this if its camera or characters are its own.

The camera area is the free camera, Wraith.FreeCamera. First claim the camera’s lease with camera.claim(): only the holder’s calls count, so a game’s plugin can take over from its engine’s. Tell Wraith how the game’s world is laid out once, with camera.setWorld(world): which axis is up, which way the camera looks, whether it’s left-handed, and how many units make a metre. Then each frame, pass the camera, a FreeCamera.State, to camera.camera(id, state). While the free camera’s on, Wraith changes it in place to its own. id says which of the game’s cameras it is: 0 for a game with one, or its id in the list below for a game with more.

The camera can point by rotation, a quaternion, or at a target point with roll. Set aim to say which. fov is vertical, in radians.

import { Wraith } from "wraith";
const camera = Wraith.camera();
camera.claim(null);
camera.setWorld({ up: "pos_y", look: "pos_z", left_handed: true, metre: 1 });
// From your hook, each frame
const state = { position, aim: Wraith.FreeCamera.Aim.rotation, target: { x: 0, y: 0, z: 0 }, up: { x: 0, y: 1, z: 0 }, rotation, roll: 0, fov };
camera.camera(0, state);
// Put state.position, state.rotation and state.fov back on the game's camera

Hook somewhere after the game’s own camera code has run for the frame, or it’ll undo the free camera. When the free camera’s turned off, camera leaves the state alone again, so a game that sets its camera every frame snaps straight back. One that doesn’t needs the plugin to put back what it had.

active() says whether the free camera’s on. Any plugin can call focus(point) with a point in the world. That turns the free camera on if it isn’t, and orbits the point. Posing uses it to orbit the picked bone.

The free camera always moves whichever camera’s on screen. A game with several can list them in Photo mode’s Camera panel, where players see which is on screen, and can tick Follow selection to show another instead:

  • cameras(add, rename) gives the plugin’s list, an ItemList. set the game’s cameras on it each time they change, with an id for each that stays the same while it’s around, and current on the one on screen. Pass add and rename if the plugin can make and rename cameras, or leave them out.
  • Each frame, put wantedCamera() on screen, or the game’s own for 0. That can mean switching the camera the game draws with, like the Unity plugin does, or drawing the game’s camera from where the picked one is, like the Unreal plugin does. A camera the player adds can be just a view the plugin keeps, with no object in the game at all.
  • Hand camera whichever’s on screen, with its id. When the id changes, the free camera carries on from the new one rather than moving it where the last one was.
  • When the free camera leaves one of the game’s own cameras, put it back where the game had it. Ones the player added stay where they were put.

Hook wherever the game has just animated a skeleton, and hand its bones to pose. Claim posing’s lease first with posing.claim(), since only the holder’s skeletons are posed. It has five calls:

  • active() says whether posing wants your skeletons right now: you hold the lease and posing’s on. Skip building them when it’s false. It’s cheap.
  • pose(skeleton, matrices), each frame for each character, once the game’s done with the skeleton (animation, IK and physics) and before anything follows it, like attached weapons. Posing changes the matrices in place.
  • shapes(actor, list, weights), for characters with blend shapes or morph targets, like faces. Call it after pose for the same character, with the skeleton’s id, and before the game skins it. Posing changes the weights in place.
  • place(actor, to_world) lets the player move a character. Call it before pose with where the game has it, and it changes to_world to where they’ve moved it, returning true if they have. Use that as the skeleton’s to_world and hand the bones over relative to it. Leave it out for things your plugin can’t move.
  • wanted(actor) says whether the player’s picked that character or edited it. A game that animates far or minor characters less, or at lower detail, can animate just these ones in full while posing’s open.

Getting the spot right matters. Too early and the game’s IK or physics undoes the edits. Too late and anything attached, like a sword in a hand, stays where it was.

A skeleton has an id that stays the same for that character while it’s around, like its address, a name for the list, its bones and to_world. Each bone has a name and its parent‘s place in the list, or -1, and parents come before their children. Edits are kept by bone name, so names should stay the same from frame to frame. matrices points at one matrix per bone, in the same order, from the bones’ space. to_world takes that to the world, or is the identity if they’re in the world already.

Posing draws the bones and the gizmo with the game’s camera, so your plugin needs to claim the view and set it too, with display.setView each frame.

Each shape has a name and the mesh it’s on, and edits are kept by both. weights points at one f32 per shape, in the same order, 0 for none of it and 1 for all of it. Scale the game’s own to that, like Unity’s 0 to 100. Players can edit a shape on one mesh, or every mesh’s shape of the same name at once. For that, what’s before the last . doesn’t count, so Face.blink and Lashes.blink go together.

import { Wraith } from "wraith";
const posing = Wraith.posing();
posing.claim(null);
// From your hook, after the game animates a character
if (posing.active()) {
const bones = [{ name: "hips", parent: -1 }, { name: "spine", parent: 0 }];
// The address of the character's first bone matrix, in the game's memory
posing.pose({ id: BigInt(character), name: "Velvet", bones, to_world: identity }, matricesAddress);
}

Players can give a chain of bones IK, and pick its solver from Wraith’s own and any plugin’s. If the game has IK of its own, like foot placement, posing.addSolver(info, solve, options) lists it too. Any plugin can add one, without the lease.

  • info has an id (letters, digits, _, - and .), a title and help for the list, how many bones a chain it takes can have (min_bones, and max_bones or 0 for no most), and pole if it bends toward one.
  • solve(request) is called on any thread, for each chain using it each frame, after the player’s edits. request.chain is the chain’s matrices, root first, in the character’s space. Return the chain solved, the same length, or nothing to leave it. Wraith handles Match rotation, the weight, and the bones hanging off.
  • options is optional. It draws your solver’s settings on the render thread from a string in your own format, and returns it as changed. Chains and saved poses keep it.

Chains name a plugin’s solver as plugin.id. One added again with the same id replaces it, and it’s gone when removeSolver(id) is called or your plugin goes. Chains using a solver that isn’t loaded are left alone.

const Foot = struct {
out: [3]sdk.math.Mat4 = undefined,
fn solve(self: *Foot, req: W.Ik.Request) []const sdk.math.Mat4 {
if (req.chain.len != 3) return &.{};
@memcpy(&self.out, req.chain);
gameFootIk(&self.out, req.target, if (req.has_pole) req.pole else null);
return &self.out;
}
};
var foot: Foot = .{};
try posing.addSolver(.{ .id = "foot", .title = "Foot", .help = "The game's own foot placement.", .min_bones = 3, .max_bones = 3, .pole = true }, .init(&foot, Foot.solve), null);

Both are in Wraith’s API schemas, camera.sal and posing.sal.

Made with ♥ by Asgard