Class in reactor_3d.js

Reactor3D

119 functions in 7 groups · hide internal

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

Quick Reference

Setup & Creation 7

ensureLoaded() Load three.js once, resolving immediately on later calls.
createSidecar() Build a fresh sidecar for a map that has none.
prepareReflections() A frame's reflections, before its draw: a face of the reflection capture (from inside the nearest mirror-brig…
prepareWorldFrame() A frame's shared work before its draw: the shadow rows, then the reflections.
createClassification() An empty classification file, ready to be filled in by the editor.
loadClassification() Fetch the classification file once per session.
createCamera() Creates the camera.

Getting Information 3

currentFlags() The running game's tileset, when there is a running game.
currentTileSize() The project's tile size, from the data the game has loaded.
currentTilesetId() The current tileset id.

Checks (True / False) 9

isLoaded() True once three.js is present.
isSupported() Whether this machine can present a 3D map at all.
isMap3D() Whether it is map3 d.
hasPaintedObjects() Whether this map has any painted 3D objects at all.
isPictureTile() Tiles laid out as a plain grid of pictures: B-G and A5, but not A1-A4.
isClassified() True where a tile has been classified rather than guessed.
isEventProp() Whether this event is now standing in the scene, and so must not also be drawn flat over it — otherwise a doo…
isPrepared() Whether it is prepared.
shouldRender3D() Whether this map should actually be drawn in 3D right now.

Actions 9

clearUnpackState() The unpack flags PIXI sets, cleared before three takes the context.
setShaderErrorChecks() three checks every new program's compile and link by asking the driver on the spot: a synchronous wait on the…
releaseBattlerState() A battler's target is GPU memory; it goes with the state that owned it, and so do its model copy's own parts,…
clampToTile() Stop a quad sampling outside its own tile, at any distance.
setClassification() Sets the classification.
clampRoomHeight() Clamp room height.
clampCliffSlope() Clamp cliff slope.
beginPrepare() Begin prepare.
setGameCanvasTransparent() Let the 3D canvas underneath show through, or cover it again.

Events, Commands & Input 1

onContextRestored() Called when context restored happens.

Updating & Drawing 7

renderScene() The game, editor map and model previews use the same colour-draw path.
_renderScene() Render scene.
paintBattlerFrame() Draw a battler's scene for this frame into its sprite.
_paintBattlerCanvas() The copy path: drawn on the private battler renderer, copied through the bitmap's canvas and uploaded.
_paintBattlerShared() Paint battler shared.
paintModelSpriteCanvas() Paint a model sprite through its bitmap's canvas on the standalone renderer when context sharing is unavailab…
renderBlocker() Why a map that asked for 3D is not getting it, or null when it is.

Other 83

touchMaterial() The one route for whatever changes a model's material after it is made: its colour, opacity, see-through and…
workerUrl() The editor supplies same-origin URLs for its externally loaded runtime.
extensionsLoaded() True once every extension has attached.
unsupportedReason() Unsupported reason.
viewport() Viewport.
acquireViewport() Acquire viewport.
mapMode() Render mode for a loaded map.
elevationAt() Elevation at.
objectIdAt() The 3D object a cell's tile has been painted into, or 0 for none.
objectGroundAt() Whether a painted cell is the object's footing rather than its height.
deriveElevation() A starting elevation derived from the map's own passability.
Viewport() Viewport.
samplesForScale() MSAA for a given scale: a half-size target has nothing left to smooth.
adaptScale() Adapt scale.
sharedContextAvailable() Whether the running PIXI can lend three its context and sample the result.
watchContextRestore() Watch context restore.
noteDrawnTriangles() What a scene's draw cost, measured at full detail where levels were not in use (GeometryDetail.wanted).
adoptGlTexture() Point a PIXI texture source at a GL texture PIXI did not create.
classification() Classification.
classKey() The id a class is stored under.
tileClass() How a tile behaves in 3D: explicit if classified, otherwise AUTO.
topFaceFor() The tile whose art covers the top of a raised wall.
standInFor() The tile a foliage cut-out takes its picture from.
sheetCell() Where a B-E tile sits on its sheet, in whole tiles.
objectAt() The declared object a tile belongs to, and where it sits inside it.
tileRole() How a tile behaves inside its object; standing for anything unattached.
foliagePredicate() Tiles that draw as a cut-out per cell over ground that stays flat.
panelPredicate() Tiles that stand still and face a direction.
abovePredicate() Tiles the 2D tilemap draws *above* characters — the star flag.
uprightPredicate() Upright predicate.
sceneryPredicate() Tiles that stand on their own cell rather than joining a facade.
pointOf() The world point a standing place actually resolves to.
footward() Half a cell towards the camera, along the ground.
billboardUp() The up axis a cut-out is built on: world up, leaned by the tilt.
standingPlaceFor() Where in the world a character is standing, for drawing purposes.
facadeAt() Where a cell's art was stood up, if it was.
facadeIn() The same question against a particular table.
surfaceHeightAt() The height of the surface a character standing on this cell rests on.
probeEvent() Everything about where one event is being drawn, in one line of console.
eventTiles() The tiles that events put on the map.
eventShapeFromNote() How an event with a character-sheet graphic should stand in 3D.
eventStaysOnGround() Whether an event refuses to join whatever is built at its cell.
facingRotation() The turn about the vertical axis that points a plane the named way.
mapWithEventTiles() Map with event tiles.
MapScene() Map scene.
parallaxIsGround() A parallax-mapped map's picture, laid flat as the ground it is.
parallaxGroundLayers() Every parallax that is ground on this map, in the order they stack.
noteParallaxLayers() <MultiParallax> blocks in a map note, as plain records.
parallaxNameOf() Which parallax a bitmap came from, by name.
defaultParallaxLoader() Load a parallax by name.
materialFileExists() Whether img/materials holds name (plain or encrypted), by disk or a web build's file index; false when unknow…
roomFor() The map's room, or null when no piece of one has an image.
skyFor() The sky a 3D map stands under: the room's own, else the map's parallax when that parallax is a backdrop rathe…
roomImageNames() Every parallax name the room and its sky use, once each, for a loader to fetch.
cliffBand() Where rock starts and where it is whole, as steepness (1 - n.y): at slope degrees and 14 degrees on.
cliffTint() A cliff's tint as a rock piece's: the colour's own numbers, multiplied in; white for none.
groundSlopeMaterial() Ground slope material.
billboardTiltFor() Billboard tilt for.
straightenBillboardDepth() Write a leaned billboard's depth as if it stood bolt upright at its anchor.
billboardMaterial() Billboard material.
roundLightTexture() The soft disc every light is stamped with.
roundLightCanvas() The falloff picture itself, shared with the flat renderer's sprites.
flatConeLightCanvas() A flat sprite is rectangular, so its texture must supply the cone shape.
flatLightOpacity() Keep flat haze translucent, using the volume renderer's body strengths.
coneLightTexture() The same, for a cone.
coneLightCanvas() The cone's falloff picture, shared with the flat renderer's sprites.
beamLightCanvas() A beam's falloff picture: a bar of constant width with a bright core and soft shoulders, fading only gently a…
mirrorFinishKept() Mirror finish kept.
mirrorOf() How strongly a model mirrors: its shiniest lit material's reflection (0 for none), worked out once it has mes…
colourOnly() A target that draws into target's colour and nothing else: the same GL texture, attached to a framebuffer of…
sphereBodyGeometry() A unit sphere, scaled per light.
beamBodyGeometry() A unit cylinder starting at the origin and running along -Y; scaled to a beam's width and length.
coneBodyGeometry() A unit cone with its apex at the origin, opening along -Y; scaled and aimed per light.
lightBodyMaterial() The haze of a light's body: brightest where its surface faces the eye and fading to nothing at the silhouette…
beamBodyMaterial() The body of a beam. The sphere and cone material fades to nothing at the silhouette, which reads as a soft ba…
groundTileFromRay() Pick the nearest horizontal ground surface, including elevated tiles.
screenToGroundTile() Screen to ground tile.
defaultCameraDistance() How far back the camera sits when a map does not say.
aimCamera() Point camera at a grid position.
projectToScreen() Where a world position lands on the game canvas.
standScaleAt() How a sprite has to be scaled to stand on the same plane a 3D object does.
screenScaleAt() Screen scale at.
characterHiddenByCamera() Character hidden by camera.

Setup & Creation

ensureLoaded

static source
Reactor3D.ensureLoaded()

Load three.js once, resolving immediately on later calls.

Details

Load three.js once, resolving immediately on later calls.

Rejection is deliberately swallowed into a resolved false: a project whose three.js is missing should fall back to the 2D tilemap with a console error, not fail to boot.

createSidecar

static source
Reactor3D.createSidecar(width, height)

Build a fresh sidecar for a map that has none.

Details

Build a fresh sidecar for a map that has none.

Kept here rather than in the editor so the runtime and the editor cannot disagree about the shape of the file.

prepareReflections

static source
Reactor3D.prepareReflections(renderer, mapScene, scene, camera, scale)

A frame's reflections, before its draw: a face of the reflection capture (from inside the nearest mirror-bright model, else the camera) and the planar mirrors near the camera.

Details

A frame's reflections, before its draw: a face of the reflection capture (from inside the nearest mirror-bright model, else the camera) and the planar mirrors near the camera. The map's viewport and the battle room both call this, so a model shines the same in either. Once a frame, after the world matrices are current. scale is the share of the screen's size the frame is drawn at (the view's render scale), 1 when left out.

prepareWorldFrame

static source
Reactor3D.prepareWorldFrame(renderer, mapScene, scene, camera, shadows, scale)

A frame's shared work before its draw: the shadow rows, then the reflections.

Details

A frame's shared work before its draw: the shadow rows, then the reflections. The map's viewport and the battle room both call this. shadows is false to skip the rows (a battle room that does not hold them), or the options Shadows.render takes, plus mapData. scale as prepareReflections takes it.

createClassification

static source
Reactor3D.createClassification()

An empty classification file, ready to be filled in by the editor.

loadClassification

static source
Reactor3D.loadClassification()

Fetch the classification file once per session.

Details

Fetch the classification file once per session.

Only a 3D map asks for it, so a 2D project issues no extra request. A missing file is the ordinary state rather than an error: every tile then falls back to the flag heuristic, which is what an unclassified project already gets.

createCamera

static source
Reactor3D.createCamera(settings)

Creates the camera.

Getting Information

currentFlags

static source
Reactor3D.currentFlags()

The running game's tileset, when there is a running game.

Details

The running game's tileset, when there is a running game.

Guarded with typeof rather than a plain truth test: the editor loads this same file to draw its 3D viewport, and there $gameMap is not merely null, it was never declared.

currentTileSize

static source
Reactor3D.currentTileSize()

The project's tile size, from the data the game has loaded.

Details

The project's tile size, from the data the game has loaded.

Game_Map.tileWidth reads the same field; this exists because the geometry is built before a scene has a map object, and outside a running game the editor supplies the number itself.

currentTilesetId

static source
Reactor3D.currentTilesetId()

The current tileset id.

Checks (True / False)

isLoaded

static source
Reactor3D.isLoaded()

True once three.js is present.

Details

True once three.js is present. Callers that must not await use this to decide whether a 3D map can be shown this frame.

isSupported

static source
Reactor3D.isSupported()

Whether this machine can present a 3D map at all.

Details

Whether this machine can present a 3D map at all.

Checked before the library is fetched so a WebGL-less host does not pay 2 MB to discover it cannot draw.

isMap3D

static source
Reactor3D.isMap3D(mapData)

Whether it is map3 d.

hasPaintedObjects

static source
Reactor3D.hasPaintedObjects(mapData)

Whether this map has any painted 3D objects at all.

isPictureTile

static source
Reactor3D.isPictureTile(tileId)

Tiles laid out as a plain grid of pictures: B-G and A5, but not A1-A4.

isClassified

static source
Reactor3D.isClassified(tilesetId, tileId)

True where a tile has been classified rather than guessed.

isEventProp

static source
Reactor3D.isEventProp(eventId)

Whether this event is now standing in the scene, and so must not also be drawn flat over it — otherwise a door appears twice, once lying down.

isPrepared

static source
Reactor3D.isPrepared()

Whether it is prepared.

shouldRender3D

static source
Reactor3D.shouldRender3D(mapData)

Whether this map should actually be drawn in 3D right now.

Actions

clearUnpackState

static source
Reactor3D.clearUnpackState(gl)

The unpack flags PIXI sets, cleared before three takes the context.

setShaderErrorChecks

static source
Reactor3D.setShaderErrorChecks(renderer)

three checks every new program's compile and link by asking the driver on the spot: a synchronous wait on the GPU process per program, which lands mid-game whenever a material is first drawn.

Details

three checks every new program's compile and link by asking the driver on the spot: a synchronous wait on the GPU process per program, which lands mid-game whenever a material is first drawn. A playtest keeps the checks, so a broken shader still says why; a released game does not pay for them.

releaseBattlerState

static source
Reactor3D.releaseBattlerState(state, resizing)

A battler's target is GPU memory; it goes with the state that owned it, and so do its model copy's own parts, unless the state lives on (resizing).

clampToTile

static source
Reactor3D.clampToTile(material, cacheKey)

Stop a quad sampling outside its own tile, at any distance.

Details

Stop a quad sampling outside its own tile, at any distance.

The half-texel inset in uvRect fixes the boundary case: it moves the sample off the fence between two tiles. It cannot fix the far case. Zoomed out, one screen pixel covers many texels, and the GPU picks one from somewhere in that footprint — which at the edge of a tile is somewhere in the next tile along. The inset would have to grow with the zoom, and the zoom is not a constant.

So the rule is stated where it can be enforced exactly: every vertex carries the rectangle of the sheet its quad is entitled to, and the fragment shader clamps to it before sampling. View-independent, and correct at every zoom by construction rather than by choosing a big enough number.

Mipmaps are not the answer here and would make it worse: a mip level of an unpadded atlas is built by averaging across tile boundaries, so the bleeding is baked into the texture rather than merely sampled from it.

Composed rather than assigned, because the billboard material already has an onBeforeCompile building its quad in the vertex shader.

setClassification

static source
Reactor3D.setClassification(data)

Sets the classification.

clampRoomHeight

static source
Reactor3D.clampRoomHeight(value)

Clamp room height.

clampCliffSlope

static source
Reactor3D.clampCliffSlope(value)

Clamp cliff slope.

beginPrepare

static source
Reactor3D.beginPrepare(mapData)

Begin prepare.

setGameCanvasTransparent

static source
Reactor3D.setGameCanvasTransparent(transparent)

Let the 3D canvas underneath show through, or cover it again.

Details

Let the 3D canvas underneath show through, or cover it again.

The two canvases are stacked — 3D at z-index 0, the game canvas at 1 — so PIXI can keep drawing windows, pictures and every plugin sprite over the top. That only works if the game canvas is transparent where nothing is drawn, and PIXI clears to opaque black by default: the 3D ground was being rendered correctly and then painted over, every frame, which looks exactly like 3D not working.

Written for whichever PIXI is present. v7 and v8 keep it on a background system; v5 and v6 on the renderer itself.

Events, Commands & Input

onContextRestored

static source
Reactor3D.onContextRestored()

Called when context restored happens.

Updating & Drawing

renderScene

static source
Reactor3D.renderScene(renderer, scene, camera)

The game, editor map and model previews use the same colour-draw path.

_renderScene

static internal source
Reactor3D._renderScene(renderer, scene, camera)

Render scene.

paintBattlerFrame

static source
Reactor3D.paintBattlerFrame(state, sprite)

Draw a battler's scene for this frame into its sprite.

Details

Draw a battler's scene for this frame into its sprite. On a shared context the scene renders straight into a target the sprite's texture has been pointed at, no copy; otherwise it renders on the private battler renderer and is copied through the bitmap and uploaded, as it always was.

_paintBattlerCanvas

static internal source
Reactor3D._paintBattlerCanvas(state)

The copy path: drawn on the private battler renderer, copied through the bitmap's canvas and uploaded.

_paintBattlerShared

static internal source
Reactor3D._paintBattlerShared(viewport, state, sprite)

Paint battler shared.

paintModelSpriteCanvas

static source
Reactor3D.paintModelSpriteCanvas(state)

Paint a model sprite through its bitmap's canvas on the standalone renderer when context sharing is unavailable.

Details

Paint a model sprite through its bitmap's canvas on the standalone renderer when context sharing is unavailable. Normally the sprite samples a GPU target directly; only a changed, visible pose asks for a repaint.

renderBlocker

static source
Reactor3D.renderBlocker(mapData)

Why a map that asked for 3D is not getting it, or null when it is.

Details

Why a map that asked for 3D is not getting it, or null when it is.

Every gate between "the note says <3d>" and "the scene is built" could fail quietly and leave an ordinary 2D map on screen, which is indistinguishable from the feature not existing. There is nothing to debug from that, so each gate names itself here and createReactor3D prints it once.

Other

touchMaterial

static source
Reactor3D.touchMaterial(material)

The one route for whatever changes a model's material after it is made: its colour, opacity, see-through and depth flags, its picture, the uniform holders in its userData (rrBlend, rrDissolve, rrCutBody, rrFightStump, rrShine, rrLook, rrEmissive), or the material a model's mesh draws with.

Details

The one route for whatever changes a model's material after it is made: its colour, opacity, see-through and depth flags, its picture, the uniform holders in its userData (rrBlend, rrDissolve, rrCutBody, rrFightStump, rrShine, rrLook, rrEmissive), or the material a model's mesh draws with. Each writer calls this in the block of its write; material.userData.rrStamp then differs from what a reader last saw (Reactor3D.StillParts' groups by colour, which draw a copy of the material and must let go of it the update it changes). It changes nothing else. editor/tests/material-stamp.test.cjs fails on a writer in runtime/ that does not call it.

workerUrl

static source
Reactor3D.workerUrl(name)

The editor supplies same-origin URLs for its externally loaded runtime.

extensionsLoaded

static source
Reactor3D.extensionsLoaded()

True once every extension has attached.

Details

True once every extension has attached. The editor loads the files one script at a time with a frame between them, and its frame loop must not take the core alone for the whole runtime.

unsupportedReason

static source
Reactor3D.unsupportedReason()

Unsupported reason.

viewport

static source
Reactor3D.viewport()

Viewport.

acquireViewport

static source
Reactor3D.acquireViewport()

Acquire viewport.

mapMode

static source
Reactor3D.mapMode(mapData)

Render mode for a loaded map.

Details

Render mode for a loaded map.

$dataMap.meta is populated by DataManager's notetag pass, so <3d> works as an escape hatch that survives a round trip through RPG Maker itself. The sidecar wins when both are present, because that is the authored source.

elevationAt

static source
Reactor3D.elevationAt(mapData, x, y)

Elevation at.

objectIdAt

static source
Reactor3D.objectIdAt(mapData, x, y, layer)

The 3D object a cell's tile has been painted into, or 0 for none.

Details

The 3D object a cell's tile has been painted into, or 0 for none.

A tileset can say what a tile is, and that is all it can say: an autotile id is a corner arrangement shared by forty-eight shapes, so every shop built from one wall kind is the same tile as every other. Which cells make up one building is a fact about a placement, and it can only be said on the map.

Stored per layer, because a tree on B standing over a wall on A is not part of the building. Layers with nothing painted are absent rather than stored as planes of zeroes.

objectGroundAt

static source
Reactor3D.objectGroundAt(mapData, x, y, layer)

Whether a painted cell is the object's footing rather than its height.

Details

Whether a painted cell is the object's footing rather than its height.

Standing a drawing up turns its map rows into courses, so a building painted across seven rows becomes seven tiles tall. Some of those rows are usually the ground it stands on — the skirt of an archway, the pavement in front of a shop — and marking them says so. Without it the whole thing is height, and the object plants itself on its southernmost row instead of in the middle of its own footprint.

deriveElevation

static source
Reactor3D.deriveElevation(mapData, flags, options)

A starting elevation derived from the map's own passability.

Details

A starting elevation derived from the map's own passability.

An existing 2D map carries no height data, and asking an author to paint a whole city by hand before seeing anything in 3D is a poor first experience. Impassable cells are overwhelmingly walls, buildings and cliffs, so raising them recovers a recognisable massing from a map that was never authored for 3D — the starting point an author then edits, not a final answer.

Passability is read the way Game_Map.checkPassage reads it: the planes are walked top-down and the first tile with a decisive flag wins, with [*] tiles skipped because they say nothing about passage.

Viewport

static source
Reactor3D.Viewport()

Viewport.

samplesForScale

static source
Reactor3D.samplesForScale(scale)

MSAA for a given scale: a half-size target has nothing left to smooth.

adaptScale

static source
Reactor3D.adaptScale(stats, current, ceiling, floor)

Adapt scale.

sharedContextAvailable

static source
Reactor3D.sharedContextAvailable()

Whether the running PIXI can lend three its context and sample the result.

watchContextRestore

static source
Reactor3D.watchContextRestore(canvas)

Watch context restore.

noteDrawnTriangles

static source
Reactor3D.noteDrawnTriangles(renderer, scene, reduced)

What a scene's draw cost, measured at full detail where levels were not in use (GeometryDetail.wanted).

adoptGlTexture

static source
Reactor3D.adoptGlTexture(renderer, source, handle)

Point a PIXI texture source at a GL texture PIXI did not create.

Details

Point a PIXI texture source at a GL texture PIXI did not create. Seeding the source's GPU record is what stops PIXI allocating its own; with no upload method the source has nothing to send, and update() is disarmed so nothing can ask it to.

classification

static source
Reactor3D.classification()

Classification.

classKey

static source
Reactor3D.classKey(tileId)

The id a class is stored under.

Details

The id a class is stored under.

Autotiles occupy 48 consecutive ids — one per shape — but a shape is a corner arrangement, not a different kind of thing: a wall is a wall whichever of its corners are joined. So a kind is classified once, at its base id, and every shape reads that entry. (Flags are an MZ format and are still mirrored across all 48; this file is ours, and keeping one entry per kind holds it to a few hundred lines instead of tens of thousands.)

tileClass

static source
Reactor3D.tileClass(tilesetId, tileId)

How a tile behaves in 3D: explicit if classified, otherwise AUTO.

topFaceFor

static source
Reactor3D.topFaceFor(tilesetId, tileId)

The tile whose art covers the top of a raised wall.

Details

The tile whose art covers the top of a raised wall.

A wall autotile is a picture of a wall face: it has no top, so a wall raised into a mass was capped with its own side art, which reads as a building wearing its front as a hat. The roof is named in the classification file where an author has said so, and derived from the sheet layout where A4 guarantees the pairing. Returns 0 when neither applies, and the caller then leaves the tile alone rather than inventing one.

standInFor

static source
Reactor3D.standInFor(tilesetId, tileId)

The tile a foliage cut-out takes its picture from.

Details

The tile a foliage cut-out takes its picture from.

An autotile answers for itself — shape 46 of its own kind. Anything else has to be pointed at its lone variant, because a B-E sheet has no rule about where one sits relative to the tiling art; standIns in the classification file records that, and a tile with no entry stands its own art up, which is at least the tile the author painted.

sheetCell

static source
Reactor3D.sheetCell(tileId)

Where a B-E tile sits on its sheet, in whole tiles.

objectAt

static source
Reactor3D.objectAt(tilesetId, tileId)

The declared object a tile belongs to, and where it sits inside it.

Details

The declared object a tile belongs to, and where it sits inside it.

Returns { object, dc, dr, role } or null. Autotiles never match: their id encodes a corner arrangement rather than a position in a drawing.

tileRole

static source
Reactor3D.tileRole(tilesetId, tileId)

How a tile behaves inside its object; standing for anything unattached.

foliagePredicate

static source
Reactor3D.foliagePredicate(tilesetId)

Tiles that draw as a cut-out per cell over ground that stays flat.

panelPredicate

static source
Reactor3D.panelPredicate(tilesetId)

Tiles that stand still and face a direction.

abovePredicate

static source
Reactor3D.abovePredicate(flags)

Tiles the 2D tilemap draws above characters — the star flag.

Details

Tiles the 2D tilemap draws above characters — the star flag.

In 2D this is what lets a character walk behind a tree or through a doorway: the tilemap draws those tiles in its upper layer, over the sprites. In 3D the ground is one picture behind every sprite, so nothing could ever be in front of anyone and a character walked over the front of everything.

Bit 0x10 is the flag, read the way the tilemap reads it.

uprightPredicate

static source
Reactor3D.uprightPredicate(tilesetId, flags, options)

Upright predicate.

sceneryPredicate

static source
Reactor3D.sceneryPredicate(tilesetId)

Tiles that stand on their own cell rather than joining a facade.

Details

Tiles that stand on their own cell rather than joining a facade.

Never guessed: there is nothing in the 2D flags that distinguishes a forest from a shopfront, which is the whole reason classification is authored.

pointOf

static source
Reactor3D.pointOf(camera, x, stand, out)

The world point a standing place actually resolves to.

Details

The world point a standing place actually resolves to.

The lift runs along the billboard's up axis, not the world's, because that is how the courses of a cut-out are stacked. Anything that wants to sit against the art has to travel the same way to get there.

footward

static source
Reactor3D.footward(camera, out)

Half a cell towards the camera, along the ground.

Details

Half a cell towards the camera, along the ground.

The same step the billboard shader takes, and for the same reason: a thing standing on a cell fills it front to back, and what the eye reads as "where it stands" is the near edge of that circle rather than its centre. Kept horizontal, so it moves a sprite nearer without lifting it.

billboardUp

static source
Reactor3D.billboardUp(camera)

The up axis a cut-out is built on: world up, leaned by the tilt.

standingPlaceFor

static source
Reactor3D.standingPlaceFor(character, out)

Where in the world a character is standing, for drawing purposes.

Details

Where in the world a character is standing, for drawing purposes.

Normally the southern edge of its own cell at ground level — screenY in 2D is scrolledY * tileHeight + tileHeight, so a character's feet are on the bottom edge of the tile it stands on, and props are planted the same way.

But a cell whose art was stood into a wall is no longer where the map says it is: its picture has moved onto a vertical plane at the wall's footing, some courses up. A sign hanging on that wall has to move with it. Left on the ground it sat at the wrong height and the wrong depth, and the depth is what made it slide against its own wall as the camera panned — two surfaces at different distances do not move together.

Only things that stay put are put on the wall. A character crossing in front of a building is standing on the street, whatever the cell behind it was turned into.

facadeAt

static source
Reactor3D.facadeAt(x, y)

Where a cell's art was stood up, if it was.

Details

Where a cell's art was stood up, if it was.

Returns { z, height } — the depth of the wall plane and how far up it the cell sits — or null for a cell that stayed on the ground. Anything drawn over the scene at a cell has to ask this, because the art it is standing against may no longer be where the map says the cell is.

facadeIn

static source
Reactor3D.facadeIn(facade, x, y)

The same question against a particular table.

Details

The same question against a particular table.

The running game has one map and keeps its facade on Reactor3D, but the editor holds a scene of its own and has to ask about that one — its 3D view has to stand an event against the same wall the game will.

surfaceHeightAt

static source
Reactor3D.surfaceHeightAt(mapData, x, y)

The height of the surface a character standing on this cell rests on.

Details

The height of the surface a character standing on this cell rests on.

Elevation says how high the ground is; it says nothing about a shop with a raised roof, a plinth, or a rise of scenery. An event standing on a shop's roof was therefore projected at street level while its roof was drawn three tiles up, and because a perspective camera moves a raised point differently from a ground one, the sign did not merely sit low — it slid sideways and vertically against its own roof as the view moved.

The build records what every cell's surface came out at; this reads it back. Falls through to plain elevation before a scene exists, and for a flat cell the two are the same number, so ordinary ground is untouched.

probeEvent

static source
Reactor3D.probeEvent(eventId)

Everything about where one event is being drawn, in one line of console.

Details

Everything about where one event is being drawn, in one line of console.

Placing a flat sprite over a 3D world has several independent ways of going subtly wrong — the cell it reads, the height it projects at, the camera it projects through, the scale it lands at, whether the tile under it was built as geometry — and from a screenshot they all look identical: the thing is in the wrong place. This reports all of them together so the wrong one can be picked out rather than guessed at.

Call Reactor3D.probeEvent(12) in the console, or Reactor3D.probeEvent() for the player.

eventTiles

static source
Reactor3D.eventTiles(mapData)

The tiles that events put on the map.

Details

The tiles that events put on the map.

A door, a sign, a chest, a barrel — an enormous amount of what an author actually stands up is placed as an event with a tile graphic rather than painted into a layer. The scene is built from mapData.data, which those tiles are not in, so they stayed resolutely flat while the identical tile painted one cell over stood up properly. That is the whole of the "3D objects work but doors and signs look 2D" split: it was never about sprites.

Read from the map data rather than $gameMap, because the scene is built before the interpreter is set up and $gameMap has nothing to say yet. The first page carrying a tile is the one taken, which is right for the static props this is for and is why moving events are left out below.

eventShapeFromNote

static source
Reactor3D.eventShapeFromNote(note)

How an event with a character-sheet graphic should stand in 3D.

Details

How an event with a character-sheet graphic should stand in 3D.

An event whose graphic is a tile already inherits that tile's 3D class — mapWithEventTiles writes it into the map before any geometry is built, so a shopfront placed as an event is a shopfront. An event drawn from a character sheet has no tile to inherit from and no way to say what it is, so it says so in its own note, beside the <3d> that makes a map 3D at all:

<3d panel> a plane that stands still and faces the default view <3d panel east> a plane facing the direction named <3d upright> a cut-out that does not turn with the camera <3d flat> lying on the ground

No note means what it has always meant: a cut-out that turns to face the camera, which is right for anything a character-shaped, and wrong for an animated piece of a city that ought to sit in the world with the painted buildings beside it.

Returns null when the note asks for nothing, so a caller can tell "no opinion" from "explicitly a billboard".

eventStaysOnGround

static source
Reactor3D.eventStaysOnGround(note)

Whether an event refuses to join whatever is built at its cell.

Details

Whether an event refuses to join whatever is built at its cell.

<3d ground> stand on the ground, never on the object at this cell <no 3d object> the same thing said the other way round

Painting a group on the map takes everything standing on those cells and makes it one object, which is exactly right for the things that are the building: an animated sign, a lit window, a swinging shop door. They ride the building's plane, so they hold still against it as the camera comes round, which is the whole reason grouping exists.

It is wrong for anything merely passing through. A character walking behind a shop crosses its cells, and the moment they stop walking they are pinned to the shopfront and carried up it — because "is this part of the building?" and "is this standing on the building's square?" are the same question to everything except the author.

So the author answers it. Only for the exceptions: a townsperson who walks is already excluded by having left home, and the tag is for the ones that stand still somewhere a building was painted.

facingRotation

static source
Reactor3D.facingRotation(facing)

The turn about the vertical axis that points a plane the named way.

mapWithEventTiles

static source
Reactor3D.mapWithEventTiles(mapData, tilesetId)

Map with event tiles.

MapScene

static source
Reactor3D.MapScene()

Map scene.

parallaxIsGround

static source
Reactor3D.parallaxIsGround(mapData)

A parallax-mapped map's picture, laid flat as the ground it is.

Details

A parallax-mapped map's picture, laid flat as the ground it is.

On a parallax map the art is the parallax and the tile layers are scaffolding: a blank tile for passability, a handful of real tiles for the things that stand up. Reactor's 3D view read only the tiles, so a room drawn as a 3,504 x 1,392 painting came out as whatever its filler tile happened to be — on Freelancers' maps, one opaque black autotile across the entire floor, which is a map that renders perfectly and shows nothing but the seams where the few real tiles sit.

Only a zero parallax is laid down, which is what the ! prefix means: Game_Map.parallaxOx returns a plain multiple of the tile size for those, so the image is pinned to the map at one image pixel per map pixel and the placement is exact. A looping or scrolling parallax is a moving backdrop rather than a floor and is left alone — it is not ground and pretending otherwise would nail the sky to the map.

parallaxGroundLayers

static source
Reactor3D.parallaxGroundLayers(mapData)

Every parallax that is ground on this map, in the order they stack.

Details

Every parallax that is ground on this map, in the order they stack.

The map's own is one of them. A parallax plugin can declare more, and MultiParallax's are readable here because it takes them from the map note — <MultiParallax> blocks with an image: line, the same ! prefix deciding whether each is pinned to the map or a moving backdrop.

Layers the author adds with a plugin command are deliberately absent. They do not exist until an event runs, so there is nothing to read at the moment a map is built; the running game gains them when the command executes and the editor cannot know about them at all.

noteParallaxLayers

static source
Reactor3D.noteParallaxLayers(mapData)

<MultiParallax> blocks in a map note, as plain records.

parallaxNameOf

static source
Reactor3D.parallaxNameOf(bitmap)

Which parallax a bitmap came from, by name.

Details

Which parallax a bitmap came from, by name.

A sprite holds a Bitmap and a Bitmap remembers the URL it was loaded from, which is the only thread back to the name an author wrote. The path is URL-encoded — ! survives, but a space or an accent does not — so it is decoded before the basename is taken.

defaultParallaxLoader

static source
Reactor3D.defaultParallaxLoader(name)

Load a parallax by name.

Details

Load a parallax by name.

The running game has ImageManager; the editor draws this same scene with no game loaded and hands in its own loader instead. Either way the answer is something with a width, a height and an image or canvas to read pixels from — which is all textureFor asks of it.

materialFileExists

static source
Reactor3D.materialFileExists(name)

Whether img/materials holds name (plain or encrypted), by disk or a web build's file index; false when unknown.

roomFor

static source
Reactor3D.roomFor(mapData)

The map's room, or null when no piece of one has an image.

skyFor

static source
Reactor3D.skyFor(mapData)

The sky a 3D map stands under: the room's own, else the map's parallax when that parallax is a backdrop rather than a ground (no !

Details

The sky a 3D map stands under: the room's own, else the map's parallax when that parallax is a backdrop rather than a ground (no ! prefix). A 2D map draws such a parallax as a scrolling wallpaper behind everything; in 3D the same image is wrapped around the camera instead, so turning the view turns the sky, and its scroll speeds drift it. Null: no sky.

roomImageNames

static source
Reactor3D.roomImageNames(mapData)

Every parallax name the room and its sky use, once each, for a loader to fetch.

cliffBand

static source
Reactor3D.cliffBand(slope, target)

Where rock starts and where it is whole, as steepness (1 - n.y): at slope degrees and 14 degrees on.

cliffTint

static source
Reactor3D.cliffTint(tint, target)

A cliff's tint as a rock piece's: the colour's own numbers, multiplied in; white for none.

groundSlopeMaterial

static source
Reactor3D.groundSlopeMaterial(material, tilesW, tilesH, cliff, slope, tint, detail, ground, frame)

Ground slope material.

billboardTiltFor

static source
Reactor3D.billboardTiltFor(mapData)

Billboard tilt for.

straightenBillboardDepth

static source
Reactor3D.straightenBillboardDepth(material)

Write a leaned billboard's depth as if it stood bolt upright at its anchor.

Details

Write a leaned billboard's depth as if it stood bolt upright at its anchor.

The lean is a drawing device: the art tips towards the camera so it is not foreshortened to a sliver. But the GPU depth-tests the leaned geometry, whose upper half physically enters the space of whatever stands on the tiles behind it — a sprite in front of a 3D car lost its head to the car's body. Rays cross a vertical plane at the anchor in true near/far order against every other surface, so the vertex shader keeps the leaned clip position for x/y and takes z from the same vertex un-leaned. In front, touching, and behind then settle per pixel with no sorting rules.

For meshes posed on the CPU (character billboards) the vertical twin is rebuilt from the model matrix: column 0 is the scaled right axis, column 1's length is the height, column 3 the anchor.

billboardMaterial

static source
Reactor3D.billboardMaterial(texture, edgeHinged)

Billboard material.

roundLightTexture

static source
Reactor3D.roundLightTexture()

The soft disc every light is stamped with.

Details

The soft disc every light is stamped with.

Built once, in code, so a project ships no extra art: white fading to nothing, which each light tints for itself. The falloff is squared rather than linear because a linear ramp reads as a flat plate with a hard rim instead of a pool of light.

roundLightCanvas

static source
Reactor3D.roundLightCanvas()

The falloff picture itself, shared with the flat renderer's sprites.

flatConeLightCanvas

static source
Reactor3D.flatConeLightCanvas()

A flat sprite is rectangular, so its texture must supply the cone shape.

flatLightOpacity

static source
Reactor3D.flatLightOpacity(light)

Keep flat haze translucent, using the volume renderer's body strengths.

coneLightTexture

static source
Reactor3D.coneLightTexture()

The same, for a cone.

Details

The same, for a cone.

Drawn for one fixed spread and stretched to whatever a light actually asks for: the quad is sized independently across and along, so the angle is a property of the quad rather than of the picture. The source is the middle of the bottom edge, which is where the thing holding the torch stands.

coneLightCanvas

static source
Reactor3D.coneLightCanvas()

The cone's falloff picture, shared with the flat renderer's sprites.

beamLightCanvas

static source
Reactor3D.beamLightCanvas()

A beam's falloff picture: a bar of constant width with a bright core and soft shoulders, fading only gently along its length.

Details

A beam's falloff picture: a bar of constant width with a bright core and soft shoulders, fading only gently along its length. Painted on a quad 2 * width across and radius along, source at the middle of the bottom edge like the cone's.

mirrorFinishKept

static source
Reactor3D.mirrorFinishKept(object, frame)

Mirror finish kept.

mirrorOf

static source
Reactor3D.mirrorOf(object)

How strongly a model mirrors: its shiniest lit material's reflection (0 for none), worked out once it has meshes.

colourOnly

static source
Reactor3D.colourOnly(renderer, target)

A target that draws into target's colour and nothing else: the same GL texture, attached to a framebuffer of its own with no depth.

Details

A target that draws into target's colour and nothing else: the same GL texture, attached to a framebuffer of its own with no depth. A full-screen pass can then write the colour while reading the target's depth texture, which WebGL refuses as a feedback loop while that depth is attached (HalfLight's combine, HalfHaze's composite). One per target, rebuilt when the target's texture is; null before the target is set up.

sphereBodyGeometry

static source
Reactor3D.sphereBodyGeometry()

A unit sphere, scaled per light.

beamBodyGeometry

static source
Reactor3D.beamBodyGeometry()

A unit cylinder starting at the origin and running along -Y; scaled to a beam's width and length.

coneBodyGeometry

static source
Reactor3D.coneBodyGeometry()

A unit cone with its apex at the origin, opening along -Y; scaled and aimed per light.

lightBodyMaterial

static source
Reactor3D.lightBodyMaterial()

The haze of a light's body: brightest where its surface faces the eye and fading to nothing at the silhouette, so a sphere reads as a soft ball and a cone as a beam rather than a solid; a cone also fades along its length, squared, like the falloff of the light it shows.

Details

The haze of a light's body: brightest where its surface faces the eye and fading to nothing at the silhouette, so a sphere reads as a soft ball and a cone as a beam rather than a solid; a cone also fades along its length, squared, like the falloff of the light it shows. One material per body, since each carries its own colour.

beamBodyMaterial

static source
Reactor3D.beamBodyMaterial()

The body of a beam. The sphere and cone material fades to nothing at the silhouette, which reads as a soft ball or a glow cone — and makes a long thin cylinder vanish whenever it is seen along its length, since every side normal is then square to the eye.

Details

The body of a beam. The sphere and cone material fades to nothing at the silhouette, which reads as a soft ball or a glow cone — and makes a long thin cylinder vanish whenever it is seen along its length, since every side normal is then square to the eye. A laser keeps a floor of brightness at any angle, softens only mildly at its edge, and fades linearly along its length like the light it shows.

groundTileFromRay

static source
Reactor3D.groundTileFromRay(map, origin, direction)

Pick the nearest horizontal ground surface, including elevated tiles.

screenToGroundTile

static source
Reactor3D.screenToGroundTile(map, camera, x, y)

Screen to ground tile.

defaultCameraDistance

static source
Reactor3D.defaultCameraDistance(camera)

How far back the camera sits when a map does not say.

Details

How far back the camera sits when a map does not say.

Not a constant. It is the distance at which a tile under the focus covers the same pixels it would on a flat map, so the 3D view frames about as much world as the 2D one and a character is drawn at about the size its art was painted at. A fixed 12 was roughly half that: the map arrived at twice its flat size, which showed a quarter of the world, upscaled every sprite, and made every light look twice as big as its author drew it.

Derived rather than tuned, so it stays right on a project with a different tile size, resolution or field of view. distance in the map's sidecar overrides it for a map that wants a closer or wider look.

aimCamera

static source
Reactor3D.aimCamera(camera, focus, settings)

Point camera at a grid position.

Details

Point camera at a grid position.

Pitch is measured from the horizon, so 90 is straight down and the shallow angles HD-2D uses sit around 50-60. Yaw rotates about the focus, which keeps a rotated camera looking at the same cell.

projectToScreen

static source
Reactor3D.projectToScreen(camera, x, y, z, out)

Where a world position lands on the game canvas.

Details

Where a world position lands on the game canvas.

Characters stay ordinary PIXI sprites drawn over the 3D ground — which is the HD-2D look, and keeps every plugin that touches Sprite_Character working — so their screen positions come from projecting through the same camera rather than from the 2D scroll.

standScaleAt

static source
Reactor3D.standScaleAt(camera, x, y, z, wide, tall, out)

How a sprite has to be scaled to stand on the same plane a 3D object does.

Details

How a sprite has to be scaled to stand on the same plane a 3D object does.

A declared 3D object is a billboard, and billboardMaterial builds its quad on two specific axes: the camera's right axis, and — since BILLBOARD_TILT is 0 — world up. It turns to face you as you orbit, but it stays upright.

A sprite standing in for one has to occupy exactly that quad, so the two are measured the same way rather than derived separately: project the anchor, the point one unit along each of those axes, and read the screen distances off. The two factors are not the same number — a camera pitched over foreshortens the vertical axis and not the horizontal — which is why a single uniform scale could never make a sprite line up with the standing art beside it. It was drawn at full height against art squashed to about six tenths, and the gap moved as the view moved.

Returns null where the question does not apply, leaving the sprite alone.

screenScaleAt

static source
Reactor3D.screenScaleAt(camera, x, y, z)

Screen scale at.

characterHiddenByCamera

static source
Reactor3D.characterHiddenByCamera(character, model)

Character hidden by camera.