Namespace in reactor_3d.js

Reactor3D.Geometry

22 functions in 3 groups · hide internal

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

Quick Reference

Setup & Creation 1

build() Build ground and wall geometry, grouped by sheet.

Checks (True / False) 1

isWallAutotile() Whether a tile id is one of the sixteen-shape wall autotiles.

Other 20

bands() Bands.
sheetRectFor() Where a tile's pixels live: which sheet, and the rectangle within it.
autotileBase() The base id of a tile's autotile kind — its shape 0.
wallFaceShape() The shape a wall face should use, from which of its own edges are exposed.
roofForWall() The roof a wall kind is drawn with, where the sheet layout guarantees one.
uvRect() Uv rect.
panelFacing() Which way a panel faces, from what is solid around it.
floorShapeFrom() The 48-shape a floor autotile takes, from which of its eight neighbours carry the same thing.
autotileTables() The shape tables to build with.
autotileQuads() Cut an autotile into the four quadrants its shape selects.
topTileAt() Top tile at.
nearestGround() The floor a facade is standing on.
groundLayersAt() Ground layers at.
groundStackAt() Ground stack at.
uprightTilesAt() Every standing tile in one cell, lowest layer first.
uprightTileAt() The topmost standing tile in a cell, for the questions that want just one.
sheetCellOf() Where a B-E tile sits on its sheet, in whole tiles.
tileIdAtSheetCell() Inverse of sheetCellOf for plain A5/B-G declared-object cells.
samePicture() Whether two neighbouring cells hold neighbouring pieces of one drawing.
uprightRuns() Upright runs.

Setup & Creation

build

static source
Reactor3D.Geometry.build(mapData, options)

Build ground and wall geometry, grouped by sheet.

Details

Build ground and wall geometry, grouped by sheet.

One group per sheet means one draw call per sheet — at most eleven for a whole map, however large — without needing instancing or a custom shader. Geometry is rebuilt only when the map changes, so the cost is paid on map load rather than per frame.

Walls are emitted only where a neighbour is lower, so a flat map produces no side faces at all and interior cliff faces are never built.

Checks (True / False)

isWallAutotile

static source
Reactor3D.Geometry.isWallAutotile(tileId)

Whether a tile id is one of the sixteen-shape wall autotiles.

Details

Whether a tile id is one of the sixteen-shape wall autotiles.

A3 is walls throughout. A4 alternates roof rows and wall rows, eight kinds to a row, odd rows being walls. Mirrors MapEditor.isWallAutotile; a test pins the two together.

Other

bands

static source
Reactor3D.Geometry.bands()

Bands.

sheetRectFor

static source
Reactor3D.Geometry.sheetRectFor(tileId, tileSize)

Where a tile's pixels live: which sheet, and the rectangle within it.

Details

Where a tile's pixels live: which sheet, and the rectangle within it.

Returns null for an empty or out-of-range id. Autotiles resolve to their whole-tile source rect here; autotileQuads splits them into the four quadrants the shape table actually selects.

autotileBase

static source
Reactor3D.Geometry.autotileBase(tileId)

The base id of a tile's autotile kind — its shape 0.

wallFaceShape

static source
Reactor3D.Geometry.wallFaceShape(edges)

The shape a wall face should use, from which of its own edges are exposed.

Details

The shape a wall face should use, from which of its own edges are exposed.

The shape stored in the map answers a two-dimensional question — which cells beside this one hold the same wall — and a face in three dimensions is asking a different one: where does this side of the mass end. Reusing the stored shape put a wall's left-hand end cap on its north face as well, because in plan those are the same edge.

roofForWall

static source
Reactor3D.Geometry.roofForWall(tileId)

The roof a wall kind is drawn with, where the sheet layout guarantees one.

Details

The roof a wall kind is drawn with, where the sheet layout guarantees one.

A4 alternates roof rows and wall rows, eight kinds to a row, so the roof for a wall is the kind directly above it — one row, eight kinds, back. That pairing is a property of the format rather than of any particular tileset, so it needs no authoring. A3 is walls throughout and has no roof to pair with; those have to be named in the classification file.

Returns 0 when there is nothing derivable.

uvRect

static source
Reactor3D.Geometry.uvRect(rect, size)

Uv rect.

panelFacing

static source
Reactor3D.Geometry.panelFacing(solidAt)

Which way a panel faces, from what is solid around it.

Details

Which way a panel faces, from what is solid around it.

Nothing is authored here. A gate set into a wall faces the way the wall faces, and a wall is solid ground on both sides of the opening — so a gap in an east-west run faces south, and a gap in a north-south run faces east. A panel with solid on one side only turns its back to it. With nothing to go on it faces south, which is the direction RPG Maker art is drawn from.

solidAt(dx, dy) says whether a neighbour is built up.

floorShapeFrom

static source
Reactor3D.Geometry.floorShapeFrom(same)

The 48-shape a floor autotile takes, from which of its eight neighbours carry the same thing.

Details

The 48-shape a floor autotile takes, from which of its eight neighbours carry the same thing.

same(dx, dy) answers for one neighbour. This mirrors MapEditor.calculateAutotileShape exactly — a test drives both over every neighbourhood and compares — because a roof laid on top of a mass has to choose its corners the way the same roof painted flat would, or the two disagree wherever a building meets its own roof.

autotileTables

static source
Reactor3D.Geometry.autotileTables(options)

The shape tables to build with.

Details

The shape tables to build with.

A running game's Tilemap wins, so a plugin that replaces the tables still governs what the 3D view draws; otherwise the copy above is used. Returning null here is what produced the corner-blit bug, so it no longer can.

autotileQuads

static source
Reactor3D.Geometry.autotileQuads(tileId, tileSize, tables)

Cut an autotile into the four quadrants its shape selects.

Details

Cut an autotile into the four quadrants its shape selects.

An autotile is not one picture: its 48 shapes each pick four 24x24 corners out of the sheet, which is how a single kind renders every combination of neighbours. Drawing the whole-tile rect instead gives the unmistakable look of a map where every grass tile is the same wrong patch, so the ground takes four half-size quads per cell here rather than one.

qx/qy place each quadrant within the cell: 0 is west/north, 1 is east/south, matching the 2D renderer's i % 2 and floor(i / 2).

A1 water sits on animation frame 0. Scrolling water and waterfalls need the frame swapped per tick, which is a later concern than getting the shape right.

topTileAt

static source
Reactor3D.Geometry.topTileAt(mapData, x, y, isUpright)

Top tile at.

nearestGround

static source
Reactor3D.Geometry.nearestGround(mapData, run, isUpright)

The floor a facade is standing on.

Details

The floor a facade is standing on.

Walks south from the run — the direction the building faces, so the first floor found is the street in front of it — then north if the whole southern column is built up, then along the run's own row. A dense city block can be buildings all the way to the map edge in one direction, and any of those misses left the footprint as a hole through to the sky.

groundLayersAt

static source
Reactor3D.Geometry.groundLayersAt(mapData, x, y, isUpright)

Ground layers at.

groundStackAt

static source
Reactor3D.Geometry.groundStackAt(mapData, x, y, isUpright)

Ground stack at.

uprightTilesAt

static source
Reactor3D.Geometry.uprightTilesAt(mapData, x, y, isUpright)

Every standing tile in one cell, lowest layer first.

Details

Every standing tile in one cell, lowest layer first.

A cell holds four tile planes and more than one of them can be standing art: a plate set down on a column occupies the same square as the column, exactly as it does in 2D, where both are drawn one over the other. Taking only the topmost — which is what asking for the upright tile does — silently threw the other away, so a column with anything resting on it disappeared from the 3D view entirely while looking perfectly ordinary in 2D.

Lowest first, so drawing them in order layers them the way the 2D tilemap layers its planes.

uprightTileAt

static source
Reactor3D.Geometry.uprightTileAt(mapData, x, y, isUpright)

The topmost standing tile in a cell, for the questions that want just one.

sheetCellOf

static source
Reactor3D.Geometry.sheetCellOf(tileId)

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

tileIdAtSheetCell

static source
Reactor3D.Geometry.tileIdAtSheetCell(setNumber, col, row)

Inverse of sheetCellOf for plain A5/B-G declared-object cells.

samePicture

static source
Reactor3D.Geometry.samePicture(tileA, tileB, dx, dy)

Whether two neighbouring cells hold neighbouring pieces of one drawing.

Details

Whether two neighbouring cells hold neighbouring pieces of one drawing.

The map offset and the sheet offset have to agree: a tile one cell east must also be one cell east on the sheet. That is what makes a stamped picture a picture rather than two props that happen to be side by side.

Autotiles are excluded. Their id encodes a corner arrangement, not a position in a drawing, so the test means nothing for them — and a wall is not a picture in this sense anyway.

uprightRuns

static source
Reactor3D.Geometry.uprightRuns(mapData, isUpright, maxHeight, isAuthored, taken)

Upright runs.