How it works · write-up
In-game 3D renderer plan (BACKLOG_3D 3D-4)
Working notes, rendered as they are: they were written while building the game, so expect ROM addresses, register names and references to source files that are not published.
Status: in progress; steps 1–4 implemented, step 5 partly verified (see BACKLOG_3D 3D-4). First recorded 2026-10-17; revised 2026-10-18 after merging main (81 commits), which moved the game host to src/play-runtime.ts, added Area 2 play, source structures (presentationStructures) and many new semantic actors and clips. Main backlog item 27 (replacement art acceptance) is the gameplay-side gate this work feeds.
What exists after the merge
FirstSectionGamelives insrc/play-runtime.ts(mountPlay). Each animation frame it callsgame.render(representation), whererepresentationcomes from the#representationmenu (arcade,guide,model).presentationScenebuilds anArcadeScenewith the live tile layers,cameraPixels,objectsand, formodel,worldObjectActors(objects, "model")payloads thatArcadeRendereronly draws as markers.presentationObjects(projectWorldObjects) returns detachedWorldObjectPresentationvalues: lifetimeid,archetypeId, typedsource,components(each withpart,assetId,localoffset, ownanimation, optionalvisibilityMask),animation(clip,action,tick,phase,remaining,pose(may be null),headingByte),appearance.flash,trajectoryfor arcs whose height is unknown, andrelationships.transform.worldLateral = nativeYandworldForward = cameraPixels + nativeX. Forward is continuous across areas: Area 1 spans 0–9215 (576 columns) and Area 2 starts atcameraBase$4000(area2_background.json, 592 columns).- Heading:
guideFacingFromNativeHeadingshows heading sectorh >> 4equals the composite facing slot ($00right,$04up,$08left,$0Cdown in the portrait). So the model yaw isπ/2 + h·2π/256with the stage convention (model forward is +z, up the screen is −z). - New since the first plan:
- Structures:
presentationStructuresreturns bounded terrain layouts (gunCorridor_0D80,wallOpening_1F80,wallOpening_5F80) with ROM tiles and references to their independent actor owners. Collision stays in the terrain categories. They arelayoutContext, not lifetimes, so the 3D stage layer may use them to place models but must not hide or replace their actors. - Multi-component actors with per-component assets:
bridgeEmplacement_05wall + gun,bridgeOverlay_22five patches,gateDoor_14/gateDoorAlias_13two panels,earthBankOpening_25,openingMask_28fixed + moving,coveredVehicle_0bbody + cover,smallVehicle_2c,cargoTruck_2dtwo halves,mobileGunner_1fgunner + vehicle,projectileLauncher_03two parts,aimedEmplacement_27body + two details,areaOneFinalExitEffect_1f00five groups withvisibilityMask. - New clips:
actor17.attack_3859,soldier26.aim_305A,actor18.lifecycle_37C0,actor27.aim_2F85,actor2a.travel/attack,coveredVehicle.cover_266C,coveredProjectile.flight_2598,vehicle.travel_197E,timedShooter.cycle_244E,actor.die_2B3A,exitEffect.animate_883C,overlay.display_313B,emplacement.wall_213A, thegate.*_39E5four, scene and cinematic clips. - Scene objects (
source.familyscene_0388): section vignettes, entrance and section vehicles, cinematic shadow and pulse.
Semantic objects versus the 3D models
| Semantic archetype / asset | Model | Binding |
|---|---|---|
arcade/player |
player_soldier |
walk_8CD6 → walk; throw_8AB5/throwPending_92FE → throw; hitPending_897A → walk pose held; dieOrdinary_8A7B/dieMoving_8A08 → die; dieLower_8A25 → dieSink. |
arcade/core/<kind> |
enemy_soldier + scheme by kind (status offsets $16AD) |
walk_1657 → walk, enter_1318 → enter, core09.enter_12D9 → kneel, hold_1455 → throw, offsetHold_14C3 → glide, core08.impact_17EE → impact, die_1786 → die, core05.* → bazooka*, core0a.travel_1046 → travel0a, core0a.die_1798 → die. |
arcade/soldier_26, raisedShooter_0e, lowerShooter_2e, soldierSpawner_2f, panelSoldierEmitter_29, mobileGunner_1f/gunner |
enemy_soldier |
Aim/cycle clips → walk pose held (aim) or throw; actor.die_2B3A → die. |
arcade/scenery/palm_0a, rockFormation_00 |
palm (break from scenery.breakup_A405 tick), rock |
Mirrored variant scales x by −1. |
arcade/playerShot, arcade/enemyShot, arcade/grenade, …/cloud blasts |
player_shot, enemy_shot, grenade, blast (explode) |
Grenade and arcing objects report height: null; the renderer draws an art arc from trajectory.remaining. |
gateDoor_14/gateDoorAlias_13 panels |
gate_door (open) |
gate.idle/opening/held/closing_39E5 drive the slide. |
bridgeEmplacement_05 gun, bridgeProjectile_06 |
bridge_gun (gun pivot yaw), gun_shell |
The /wall component is stage-provided (the wall model). |
troopTransport_0a, coveredVehicle_0b (+coveredVehicleProjectile_0c), armoredVehicle_2b, smallVehicle_2c, cargoTruck_2d, mobileGunner_1f/vehicle, mobileExplosiveLauncher_19/returningExplosiveLauncher_2a |
troop_transport, covered_vehicle (+mortar_shell), half_track, jeep, cargo_truck (first half; second hidden), motorbike |
|
alternatingShooter_17, projectileLauncher_03/arcingProjectile_04, soldierEmitter_12, grenadeSupply_23 |
turret, mortar/mortar_shell, hut_door (open), supply_crate |
|
bridgeSpan_1a, bridgeOpening_1b, bridgeOverlay_22, earthBankOpening_25, openingMask_28, emplacementWall |
stage-provided | Drawn by the stage layer (walls, banks, relief); binding says so to avoid double drawing. |
scriptedExplosive_0d, scriptedImpactEffect_16, fadingProjectile_18, aimedEmplacement_27, actor15/24 no-ops, unidentified kinds, final exit effect |
placeholder marker or blast |
Marked with a reason in the binding table; art later. |
Scene objects (scene_0388) |
none | The whole frame falls back to the 2D arcade renderer while any is visible, and outside gameplay (mainScene not null or world handoff). The plan to draw these scenes in 3D is SCENES_3D_PLAN.md (3D-14 to 3D-20). |
Implementation steps
- Art binding table (
src/render3d/art-bindings.ts, no three.js). For an object and component it returns the model, colour scheme, clip and clip time in updates, the yaw, a native anchor offset, orstage/hidden/markerwith a written reason. A node test enumerates everyObjectClipand everyArcadeActorKind/ArcadeEnemyKindarchetype and fails if one is unbound without a reason. - Shared stage ground (
src/stage/area-ground.ts). Move the art repaint, relief, face-split and structure placement out ofsrc/stage-app.tsinto a function used by bothstage.htmland the game. Area 1 gets the relief; Area 2 a flat textured ground fromarea2_background.jsonplaced at itscameraBase, until it gets labels and structures. src/render3d/world-renderer.ts(three.js): - one node per visible component ID, created on first sight and disposed when the ID disappears; - animation set from the semantic tick through the binding, snapped to ROM updates (no wall-clock time); - position x = lateral − 128, z = −forward, y = ground height; yaw from the heading byte; - camera target at forwardcameraPixels + 128, pitched 55° (judgement call: steeper than the stage lab's 42° so the 256-pixel ground fills the portrait screen's far corners); -appearance.flashand componentvisibletoggle the node.playlab.htmlintegration. A "3D models" option in#representation. Selecting it dynamically imports three.js (import map, as inlowpoly.html) and shows a WebGL canvas in place of the arcade screen. The foreground character layer (HUD, text) is drawn by a secondArcadeRendereron a transparent overlay. Scenes outside gameplay, and empty projections (the respawn rebuild), draw the 2D frame. Gameplay code is unchanged; the renderer reads onlypresentationObjects,cameraPixelsand the foreground layer.- Verification. The binding test; the existing representation-invariance tests (item 27); a browser play-through of Area 1 comparing 3D positions with the arcade frame at the same update.
Decisions taken for the first version
- Unidentified or unmodelled actors: a small marker mesh, listed with a reason in the binding table, rather than silently dropping them.
- Interpolation: none. Poses snap to ROM updates, matching the 60 Hz gameplay step.
- Player death: the model's ROM poses play over the first 24 updates and the forward fall fills the rest of the 40-update death.