Add a security-camera screen / minimap
Goal
Show an independent camera's live view on a mesh in the world. Start with a game that has a mesh actor named monitor and a manifest mesh asset suitable for its screen.
Files you will edit
src/game.ts
Steps
Add this helper and call it from the game's
init(ctx)after spawning the monitor. Bind the mesh component, rather than the actor id:tsimport { actors, sceneCapture, SceneCaptureActor, spawnActor, type GameContext, } from 'gameable'; function installMonitor(ctx: GameContext): void { const screen = actors.named('monitor'); if (!screen) throw new Error('Place a mesh actor named monitor first'); const camera = spawnActor(ctx, SceneCaptureActor, { name: 'security-camera', position: { x: 0, y: 3, z: 8 }, }); const capture = camera.entity; sceneCapture.configure(capture, { target: { width: 512, height: 256 }, fovYDeg: 60, everyFrame: true, onMovement: false, }); sceneCapture.hideActor(capture, screen); sceneCapture.bind(capture, screen.component('mesh'), 0); }The capture looks down -Z. Binding replaces
mapon material slot zero; use the screen's material slot if the model has several. Hiding the monitor from this capture prevents it filming its own screen. It remains visible in the main view. The capture renders at most once per frame, only while a visible mesh reads it; it does not take over the player camera.For a minimap, place/orient the capture actor above the level looking down using the editor, then configure its lens during init:
tsconst camera = actors.named('security-camera'); if (camera) { sceneCapture.configure(camera.entity, { projection: 'orthographic', orthoWidth: 40, target: { width: 256, height: 256 }, }); }sceneCaptureComponent(options)can instead attach a capture to your own actor.sceneCapture.create(entity, options)adds one to an existing entity; that entity id is the capture handle. For a still image, set botheveryFrameandonMovementfalse, then callcaptureScene(capture)when needed.showOnlyActorplusprimitiveRenderMode: 'showOnlyList'limits content;sourceselectsfinalColor,sceneColor,depth,normalorbaseColor. Capture grading supports exposure, contrast, saturation, tint and vignette.
Verify
Run npm run dev in the game. Move something in front of the security camera: its screen updates while the player's view stays in place. Hide the reader mesh and confirm it stops demanding captures. sceneCapture.unbind(meshEntity, 0) restores its original material; sceneCapture.destroy(capture) releases the target.