REDCODE / DOCS

Sector view: a streaming sector in 3D

Draft 0.3, 2026-11-20, agreed with the owner (decisions below); the package’s API agreed with EDGEbuilder on 2026-11-20. The owner asked on 2026-11-19 whether EDGEbuilder could open a 3D sector view of REDcode’s instead of hosting one of its own. Nothing is built. It comes after Animations A3 and New File, unless the owner moves it. EDGEbuilder’s E0 has answered its questions (below).

What there is today

The split

One VS Code extension cannot put another extension’s webview inside its own. EDGEbuilder could only open REDcode’s panel as a tab of its own, or bundle the drawing code itself. Hosting EDGEbuilder’s editing (gizmos, selection, scene state, Library overlays) inside REDcode would make REDcode the host of EDGEbuilder’s editor and tie the two release cycles. The owner took the same line on 2026-11-15, when #2’s scene tree and Bake moved to EDGEbuilder for VS Code. So the view is in three layers:

Layer What Where
1. The drawing package The game’s things in a three.js scene: a sector’s items from sector.nodes, each unique mesh loaded once from its GLB and drawn as instances, distance culling by the items’ streaming ranges, markers for lights and other kinds that have no mesh, the flying camera, a pick that answers the item. Two halves: a host half (no VS Code imports) that asks the bridge, exports through a cache folder it is given, and streams progress; a page half that draws. The mesh viewer’s own code moves into it, so there is one renderer An npm package from this repo, beside packages/redcode-mcp, like @edgemodders/edgemat-core and EDGEfab’s core. MIT. Name to agree: @edgemodders/world-view
2. REDcode’s sector mode A .streamingsector opens in 3D, read-only, as a mesh does, with Tree one click away. A click on a thing selects its nodeData entry and node in the tree and the Properties view. Game sectors and a project’s copies, a mod’s through archive. REDcodeApi.openSector(path, { select? }) opens it at one entry, for EDGEbuilder’s “show me” and any other tool src/sectorView.ts and a sector mode in media/cr2w/editor.js, over the package
3. EDGEbuilder’s sector view Its own panel over the same package: Library scenes over the sector, add and move objects with its gizmo, B4b’s edits, bake and Open in game EDGEbuilder for VS Code, its E2 and E3

E0’s answers

EDGEbuilder ran E0 on 2026-11-19 (REDbridge 0.15.0, game 2.5, an RTX 4090), on this repo’s mesh viewer approach as it is: plain GLBs (no materials, the most detailed LOD), three.js 0.170 (its results, EDGEbuilder #8):

  exterior_-22_7_0_0 (most copies) exterior_-23_-3_0_0 (most entries) City Center, level 0
Unique meshes in copies 105 in 8,986 347 in 3,616 6,522 in 605,801, over 577 sectors
Other things 202 1,703 (765 decals, 242 lights, 189 entities, …)  
GLB export, first and again 2.1 s (8.8 MB), 0.04 s 11.4 s (29 MB), 0.23 s about 3 to 4 min and 0.5 GB, estimated
Everything drawn 193 draw calls, 2.2 M triangles, 1,760 fps 711 calls, 3.0 M triangles, 680 fps  

What follows for the package:

What layer 1 starts with

The package’s API

Agreed with EDGEbuilder in #8 on 2026-11-20; its answers were agreed with the owner. TypeScript, ES modules. three is a peer dependency, so each extension bundles its own copy.

Names. Every drawn thing has a string id. A sector’s item is <sector path>#<entry>, with entry the node data index: what ArchiveXL’s deletions and REDnode’s registry use, and what a scene format 3 removal names. #<entry>.<copy> is one copy of an instanced mesh. EDGEbuilder does not use it yet (ArchiveXL’s sub-element deletions come later), but the form leaves room for it. Any other id belongs to the caller (EDGEbuilder’s scene objects), and the page treats both alike for picking, highlighting and hiding.

Host half (@edgemodders/world-view/host, Node, no VS Code imports):

interface Bridge { request<T>(method: string, params?: object): Promise<T> }   // REDcode's BridgeClient fits

const loader = createSectorLoader(bridge, {
  cacheDir: string,
  kinds?: string[],
  onMesh(m: { mesh: string; glb: string; placements: { id: string; matrix: number[] }[] }): void,
  onMarkers(ms: { id: string; kind: string; class: string; resource?: string; matrix: number[]; box?: Box }[]): void,
  onUnload(sector: string): void,                    // every id under "<sector>#" leaves the page
  onProgress(p: { done: number; total: number; etaMs?: number }): void,
})
loader.set(sectors: { path: string; archive?: string; root?: string }[]): Promise<{ skipped: { id: string; why: string }[] }>
    // loads the sectors new to the list and unloads those that left it; a newer set() cancels the exports an older one still has queued
loader.dispose()

sectorsOver(bridge, path): Promise<string[]>                                       // a level-0 sector and the coarser ones over it
sectorsNear(bridge, point: number[], distance: number, { levels? }): Promise<string[]>   // for a view that follows its camera
texturedGlb(bridge, mesh, cacheDir): Promise<string>                               // the mesh with its materials, for one picked object
entityGlb(bridge, ent, appearance, cacheDir): Promise<string>

sectorsOver and sectorsNear only return lists, through sector.find; loading by point and distance is loader.set(await sectorsNear(...)). Meshes come as they are exported, cached ones first, so the page fills in while the rest export. A mesh shared by two sectors is exported once, and its placements are sent per sector. glb is a file path; each host turns it into a webview URI or bytes.

Page half (@edgemodders/world-view/page):

const view = createWorldView(canvas, { colourBy: "mesh" | "material", culling: "streaming" | "none" })
view.addMesh(mesh, glb: ArrayBuffer, placements)        // one InstancedMesh per GLB primitive
view.addMarkers(markers)
view.unloadSector(path)                                 // what the host's onUnload asks for
view.addObject(id, object3d) / view.removeObject(id)    // the caller's own things, in the same scene
view.replaceMesh(id, glb)                               // a textured or entity GLB for one id
view.setHidden(ids, "hidden" | "ghost" | "shown")       // a removal: its entry and its proxies' entries together
view.highlight(ids)
view.pick(x, y) -> { id, point } | null / view.onPick(cb)
view.onPointer(cb)                                      // down, move and up on the canvas, with the id under it
view.toCanvas(worldPoint) -> [x, y] / view.rayFrom(x, y) -> { origin, direction }   // for a gizmo and box selection
view.camera.pose / view.camera.setPose(pose) / view.frame(ids)
view.flyTo(ids?, "top" | "start"?)                     // frame, gliding there
view.hold(move, on, { fast?, slow? }) / view.flySpeed / view.onFlySpeed(cb)   // on-screen camera buttons
view.scene, view.camera, view.renderer
view.dispose()

As built, part 1

Built 2026-11-20 on REDbridge 0.12.0’s sector.find and sector.nodes; hand test pending (testing).

Checked before the hand test:

Part 2: #31’s light everywhere

Built the same day. The mesh view (webview/meshViewer.ts) and the animation view (webview/animViewer.ts) light through the package’s stage, as the sector view does, in place of their own hemisphere and camera light. Light (0.5×, 1×, 1.5× and 2.5×) and Fixed light are one shared control (lightControls in webview/viewerKit.ts). The setting is kept in the workspace’s state under redcode.light, so per window as #31 asks, and passed in by both the CR2W editor’s host and the glTF viewer’s host.

A directional light needs only a direction, so the stage keeps one. In camera mode it comes from over the viewer’s shoulder, and Fixed light freezes the direction it had. That works the same for a mesh at the origin and for a sector 1,400 m from it.

Checked in Chrome: the mesh view with a game mesh exported with its materials showed the control and readable shading. The first tone and environment values washed the sector’s colours almost to white, so they were turned down: exposure 0.8, environment 0.45. Not judged yet: EDGEmat’s rendered metals and roughness, which #31 is for. EDGEmat sends those next. Glass and glow, #31’s later rows, wait for EDGEmat’s new fields.

Part 3: the camera (2026-11-21)

The owner asked after the M1 hand test: buttons for zooming, panning, strafing and speed, as EDGEbuilder’s free camera works, and a double-click that flies close to a thing. Built the same day.

Input Does
Left drag Orbit, as before
Right drag Look round where the camera stands; W A S D fly and Q E go down and up while it is held (they work without it too, once the view has the keys)
Middle drag, or Ctrl with the left Pan (Shift with the left drew a pan too until selection took Shift+drag for its box, the same day)
Wheel Closer, towards the cursor (zoomToCursor); with the right button held, the fly speed
Shift, Ctrl Faster (×4), slower (×0.25), with the keys and the buttons
F Frame the picked thing, gliding there
Double-click Pick the thing and glide close to it

These are the package’s own (EDGEbuilder’s in-game viewport uses the same mapping), so EDGEbuilder’s sector view gets them too. A right click no longer picks, since the right button is the look.

REDcode’s camera row under the toolbar: Zoom + and −, Move (Forward, Back, strafe left and right), Pan up and down, Height up and down, Orbit both ways, each moving while its button is held (view.hold); Speed − and + (view.flySpeed, shown as ×1.0 and following the wheel); Top (from above, on the picked thing or the sector) and Reset (the view it opened with), both gliding (view.flyTo); and ? for a line naming the mouse and keys. Frame glides too.

Checked in Chrome over the real bridge: every held move goes the right way (forward and back along the view, strafing level, height along the world’s up, zoom changing the distance only, orbit keeping the target), Top looks straight down, Reset comes back to the opening side, a double-click on node 848.7 picked it and glided to 2.5 m from it, a right click kept the pick, the wheel with the right button held raised the speed to ×1.3. Chrome drew 2 frames a second in that window, so how the moves feel is the hand test’s.

Part 4: the tree in its own tab (2026-11-26)

The owner asked, from a modder’s idea of the tree in the bottom panel beside Output and Terminal. An editor tab cannot go into the bottom panel (it holds views only), so there are two ways out of the editor, both the editor’s own page in a tree mode (data-mode="tree") and one more page on the open file:

  To Tab The Sector view
What A button beside Tree, on a file that has a view of its own (a sector’s or mesh’s 3D, a table) A view in a Sector container of the bottom panel, shown while a CR2W file is open
Where it goes Any editor group, beside or below the 3D view, or its own window The bottom panel by default, or a sidebar
Which file The one it was opened from; it closes with that file The one in the active editor, as the Properties view follows it

The selection goes both ways. A pick in 3D moves the tree to its node data entry. A click in the tree selects the entry it is in, or every entry placing a nodes.<n>, in 3D and frames it, quietly (selectEntry’s quiet, so the tree keeps its deeper path), and only when the entry changes, so opening fields inside one leaves the camera alone. A tree page’s redraws send no selection. As built: openTreeTab (view type redcode.cr2wTree) and a second Cr2wPropertiesView (redcode.tree, in the container redcodePanel, when the context redcode.cr2wOpen) in src/cr2wEditor.ts, treeOnly and followInSector in media/cr2w/editor.js. Hand-tested by the owner on 2026-11-26 (docs/testing.md, The tree in its own tab); the container’s title went from “REDcode Tree” to “Sector” after it. Not built: undo from the tree tab, and the tab coming back after a window reload.

Order

  1. EDGEbuilder’s E0 (done 2026-11-19, above) runs with REDcode’s mesh viewer code as it is, from a script, and answers the timing question. The package’s shape follows from its answer: how many meshes a downtown sector has, how long their exports take, and whether instancing and culling are enough.
  2. The package and REDcode’s sector mode, on the API above (agreed 2026-11-20). The API is the contract between the two, so a change to it is agreed in EDGEbuilder #8 or a later issue first.
  3. EDGEbuilder’s E2 on the package.
  4. Right after REDcode’s part: REDcode’s half of Sector Tools (the owner, 2026-11-20). The app is an EDGEbuilder app pack (EDGEbuilder #9) that draws with the same package in the game; REDcode links its sector mode to it.

Decisions

Agreed with the owner on 2026-11-19: each of the three as proposed. The owner expects EDGEbuilder to reach its E0 probe soon, after its Doors phase.

  1. The three layers, rather than REDcode alone hosting the view or EDGEbuilder alone writing its own. Proposal: the three layers.
  2. Where the package lives: in this repo, since the mesh viewer is here and its code moves into it. The other way is a repo of its own. Proposal: this repo.
  3. When: after A3 and New File, with E0 free to run before that on today’s viewer code. Proposal: as said.

The request to agree the package’s shape with EDGEbuilder is EDGEbuilder #8.

Not in this design