A 3D map in the editor, with terrain and roads.

3D & HD-2D

HD-2D Renderer

reactor_3d.js · 13,377 lines · 214 public functions

A 3D map in the editor, with terrain and roads.

What This Module Does

The core of the 3D renderer. A 3D map is still an ordinary RPG Maker map: the grid, passability and events work as always, and 3D data lives in a sidecar file (Map###.r3d.json). Three.js draws on PixiJS's own WebGL context, so windows, pictures and plugin sprites still draw on top of the world.

Example

// Is the current map 3D?
const is3D = Reactor3D.mapMode($dataMap) !== Reactor3D.MODE_2D;

// Ease the camera to an isometric view over 60 frames
Reactor3D.Camera.change({ mode: "isometric" }, 60);

// Is there a stair at this tile?
const stair = Reactor3D.stairAt($dataMap, $gamePlayer.x, $gamePlayer.y);

Classes & Namespaces

Design Notes from the Source Code

A 3D view of an ordinary RPG Maker map.

Design constraints this file exists to honour:

  1. The grid stays authoritative. Game_Map, Game_Character, passability, region logic and the event interpreter keep operating on the same width * height * 6 planes. A 3D event model is the exception: its authored size occupies every tile the mesh covers, so collision matches what is on screen.

  2. The map file is never rewritten. Elevation and geometry live in a sidecar (Map###.r3d.json), so a 2D project never gains a file, and a 3D map's Map###.json remains valid RPG Maker data describing its 2D footprint.

  3. Three.js loads on demand. It is ~2 MB; a project with no 3D maps must never download or parse it, so there is no entry in scriptUrls.

  4. Three draws on PIXI's own WebGL context (_initializeShared): each map pass renders into a WebGLRenderTarget that PIXI samples as a texture, so there is no per-frame copy and PIXI keeps drawing windows, pictures, weather and every plugin-authored sprite over the world exactly as it does in 2D. If that handover fails, _initializeCanvas falls back to a separate 3D canvas at z-index 0 under the game canvas. Screen effects keep their WebGL1 overlay; attached effects share the view GPU when supported.

  5. This file is the core of the 3D runtime, not all of it. A concern that outgrows it lives in one reactor_3d_<concern>.js named in Reactor3D.EXTENSIONS (lighting and shadows, models, model effects, the world builder, speech, foliage), loaded right after this file everywhere: scriptUrls in the game, the extension list in the editor, and the tail of this file in Node.

Reactor3D

Namespace and lifecycle. Everything is static; there is at most one viewport.

View reactor_3d.js on GitHub · Show internal (_) functions