dmnet.st Commando

How it works · write-up

In-game 3D renderer plan (BACKLOG_3D 3D-4)

docs/RENDERER_3D_PLAN.md · 9 KB · updated 2026-11-02

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

  • FirstSectionGame lives in src/play-runtime.ts (mountPlay). Each animation frame it calls game.render(representation), where representation comes from the #representation menu (arcade, guide, model). presentationScene builds an ArcadeScene with the live tile layers, cameraPixels, objects and, for model, worldObjectActors(objects, "model") payloads that ArcadeRenderer only draws as markers.
  • presentationObjects (projectWorldObjects) returns detached WorldObjectPresentation values: lifetime id, archetypeId, typed source, components (each with part, assetId, local offset, own animation, optional visibilityMask), animation (clip, action, tick, phase, remaining, pose (may be null), headingByte), appearance.flash, trajectory for arcs whose height is unknown, and relationships.
  • transform.worldLateral = nativeY and worldForward = cameraPixels + nativeX. Forward is continuous across areas: Area 1 spans 0–9215 (576 columns) and Area 2 starts at cameraBase $4000 (area2_background.json, 592 columns).
  • Heading: guideFacingFromNativeHeading shows heading sector h >> 4 equals the composite facing slot ($00 right, $04 up, $08 left, $0C down in the portrait). So the model yaw is π/2 + h·2π/256 with the stage convention (model forward is +z, up the screen is −z).
  • New since the first plan:
  • Structures: presentationStructures returns 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 are layoutContext, 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_05 wall + gun, bridgeOverlay_22 five patches, gateDoor_14/gateDoorAlias_13 two panels, earthBankOpening_25, openingMask_28 fixed + moving, coveredVehicle_0b body + cover, smallVehicle_2c, cargoTruck_2d two halves, mobileGunner_1f gunner + vehicle, projectileLauncher_03 two parts, aimedEmplacement_27 body + two details, areaOneFinalExitEffect_1f00 five groups with visibilityMask.
  • 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, the gate.*_39E5 four, scene and cinematic clips.
  • Scene objects (source.family scene_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

  1. 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, or stage/hidden/marker with a written reason. A node test enumerates every ObjectClip and every ArcadeActorKind/ArcadeEnemyKind archetype and fails if one is unbound without a reason.
  2. Shared stage ground (src/stage/area-ground.ts). Move the art repaint, relief, face-split and structure placement out of src/stage-app.ts into a function used by both stage.html and the game. Area 1 gets the relief; Area 2 a flat textured ground from area2_background.json placed at its cameraBase, until it gets labels and structures.
  3. 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 forward cameraPixels + 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.flash and component visible toggle the node.
  4. playlab.html integration. A "3D models" option in #representation. Selecting it dynamically imports three.js (import map, as in lowpoly.html) and shows a WebGL canvas in place of the arcade screen. The foreground character layer (HUD, text) is drawn by a second ArcadeRenderer on a transparent overlay. Scenes outside gameplay, and empty projections (the respawn rebuild), draw the 2D frame. Gameplay code is unchanged; the renderer reads only presentationObjects, cameraPixels and the foreground layer.
  5. 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.