Namespace in reactor_3d.js

Reactor3D.Viewport

44 functions in 5 groups · hide internal

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

Quick Reference

Setup & Creation 4

initialize() Two ways to get the 3D picture into the game.
_initializeShared() Initialize shared.
createTarget() A render target PIXI can sample as if it were an uploaded canvas.
_initializeCanvas() Initialize canvas.

Checks (True / False) 1

isShared() Whether it is shared.

Actions 7

setRenderScale() Change the pass resolution; the targets and their sprites rebuild.
_disposeTargets() final: the view is going (torn down, destroyed, its context lost) and will not draw again, so the old passes…
_resetPixi() PIXI's caches after three has driven the context.
setScene() Sets the scene.
releaseSlot() A slot's targets and the textures that show them, let go two refreshes from now (a sprite may draw them once…
runOwedWork() Work an earlier update left for spare refreshes, done now (a new update came first, or the view is torn down).
setVisible() Sets the visible.

Updating & Drawing 7

renderInto() Render into.
renderer() The three.js renderer, for anything that has to upload a texture on the spot.
render() scene and camera: a guest's (a battle room on this view's context, renderGuest), drawn into slot as the map's…
renderGuest() A scene that is not the map's (a battle room's), from its own camera, through the map's pipeline: the view's…
_renderUpscaled() Drawn small, then enlarged into what PIXI shows by the sharpening upscale (Reactor3D.SharpUpscale).
renderPass() Draw one pass on its own, over a cleared canvas.
drawnAt() The update (Graphics.frameCount) a pass's target was last drawn on; undefined when never.

Other 25

_teardownShared() Teardown shared.
scale() The resolution the passes render at, relative to the screen.
targetSize() Target pixel size for the passes at the current scale.
upscaled() Whether the passes are drawn smaller and enlarged by the sharpening upscale (Reactor3D.SharpUpscale).
passPixelRatio() Backing pixels per game pixel the passes draw at: the canvas's, capped by maxPassPixelRatio.
passEnlarged() Whether the passes are drawn smaller than the canvas and enlarged into it.
_trackFrame() Once per game frame: measure the interval since the last frame and let the controller move the scale.
generation() Bumps whenever the pass textures are replaced (a resize); sprites holding an older one rebuild.
_reapOwed() Once a game frame the view draws in: the passes a change of scale or size replaced, two such frames ago, are…
_target() Target.
_workTarget() The smaller target an upscaled pass is drawn into.
pixi() Pixi.
targetHandle() The GL texture three renders target into, once it has been allocated.
passTexture() The PIXI texture that shows one pass.
_pixiTexture() The PIXI texture over the target make() returns, kept under key for this generation; flip mirrors it so a spr…
passSprite() What PIXI shows one pass with: a sprite of its target, or, for a pass drawn smaller and enlarged (upscaled),…
enlargedInComposite() Whether slot's small target is enlarged by PIXI's composite, so its draw stops there.
resize() Match the game canvas's backing size and on-screen placement.
scene() Scene.
camera() Camera.
probe() What is actually on the 3D canvas, and where that canvas actually is.
shadowsFollowRefresh() Shadows follow refresh.
spreadsUpdateWork() Spreads update work.
detachFromPage() Stop showing the 3D canvas on its own and let PIXI draw it instead.
canvas() The canvas the 3D pass draws on, for diagnostics.

Setup & Creation

initialize

method source
Reactor3D.Viewport.prototype.initialize()

Two ways to get the 3D picture into the game.

Details

Two ways to get the 3D picture into the game.

Shared context (the default): three renders with PIXI's own WebGL context into render targets, and PIXI samples those textures directly. Nothing is copied and nothing is uploaded; a frame costs the draws and no more.

Canvas copy (the fallback, and the old way): three owns a second canvas, and every pass is copied through a 2D canvas and uploaded to PIXI as a full-screen texture, up to three times a frame. It stays for PIXI builds without a WebGL2 context, and as a kill switch: ?r3dcopy on the URL or Reactor3D.useSharedContext = false before the first map.

_initializeShared

method internal source
Reactor3D.Viewport.prototype._initializeShared()

Initialize shared.

createTarget

method source
Reactor3D.Viewport.prototype.createTarget(width, height, scale, options)

A render target PIXI can sample as if it were an uploaded canvas.

_initializeCanvas

method internal source
Reactor3D.Viewport.prototype._initializeCanvas()

Initialize canvas.

Checks (True / False)

isShared

method source
Reactor3D.Viewport.prototype.isShared()

Whether it is shared.

Actions

setRenderScale

method source
Reactor3D.Viewport.prototype.setRenderScale(scale)

Change the pass resolution; the targets and their sprites rebuild.

_disposeTargets

method internal source
Reactor3D.Viewport.prototype._disposeTargets(final)

final: the view is going (torn down, destroyed, its context lost) and will not draw again, so the old passes go two refreshes from now.

Details

final: the view is going (torn down, destroyed, its context lost) and will not draw again, so the old passes go two refreshes from now. Otherwise (a new render scale, a resize) they go once the view has drawn in two more game frames (_reapOwed, from _trackFrame): the pass sprites take the new textures when the map is next drawn, and refreshes can pass before that with the old ones still composited (a fast screen between updates, a game held still). Counted in refreshes, a scale changed while nothing drew destroyed a texture the composite's mesh still held, and PIXI stopped the game on it ("Cannot read properties of null (reading 'alphaMode')", 2026-11-10, a probe that froze the updates and changed the scale).

_resetPixi

method internal source
Reactor3D.Viewport.prototype._resetPixi()

PIXI's caches after three has driven the context.

setScene

method source
Reactor3D.Viewport.prototype.setScene(scene, camera)

Sets the scene.

releaseSlot

method source
Reactor3D.Viewport.prototype.releaseSlot(slot)

A slot's targets and the textures that show them, let go two refreshes from now (a sprite may draw them once more).

runOwedWork

method source
Reactor3D.Viewport.prototype.runOwedWork(mapScene)

Work an earlier update left for spare refreshes, done now (a new update came first, or the view is torn down).

setVisible

method source
Reactor3D.Viewport.prototype.setVisible(visible)

Sets the visible.

Updating & Drawing

renderInto

method source
Reactor3D.Viewport.prototype.renderInto(target, scene, camera)

Render into.

renderer

method source
Reactor3D.Viewport.prototype.renderer()

The three.js renderer, for anything that has to upload a texture on the spot.

render

method source
Reactor3D.Viewport.prototype.render(slot, scene = this._scene, camera = this._camera)

scene and camera: a guest's (a battle room on this view's context, renderGuest), drawn into slot as the map's own scene is: at the view's scale, enlarged and sharpened, its frames counted for the scale's controller.

Details

scene and camera: a guest's (a battle room on this view's context, renderGuest), drawn into slot as the map's own scene is: at the view's scale, enlarged and sharpened, its frames counted for the scale's controller.

renderGuest

method source
Reactor3D.Viewport.prototype.renderGuest(scene, camera)

A scene that is not the map's (a battle room's), from its own camera, through the map's pipeline: the view's work target at its scale (Auto quality's level), the sharpening enlargement, the colour draw's culling, detail levels and shader warm-up (renderInto, Reactor3D.renderScene), the texture bias, and the frame counted for the scale's controller.

Details

A scene that is not the map's (a battle room's), from its own camera, through the map's pipeline: the view's work target at its scale (Auto quality's level), the sharpening enlargement, the colour draw's culling, detail levels and shader warm-up (renderInto, Reactor3D.renderScene), the texture bias, and the frame counted for the scale's controller. Only on the shared context. The guest shows passSprite(Reactor3D.GUEST_SLOT), made again when generation() changes, and lets the slot go when it is done (releaseSlot). The guest's shadow rows and reflections are its own to prepare first (Reactor3D.prepareWorldFrame).

_renderUpscaled

method internal source
Reactor3D.Viewport.prototype._renderUpscaled(slot, scene = this._scene, camera = this._camera)

Drawn small, then enlarged into what PIXI shows by the sharpening upscale (Reactor3D.SharpUpscale).

Details

Drawn small, then enlarged into what PIXI shows by the sharpening upscale (Reactor3D.SharpUpscale). An empty pass stays empty (EmptyPass).

renderPass

method source
Reactor3D.Viewport.prototype.renderPass(mapScene, which, slot)

Draw one pass on its own, over a cleared canvas.

Details

Draw one pass on its own, over a cleared canvas.

The two passes sandwich the character sprites: the ground goes down, PIXI draws the characters, and then the star-flagged tiles go over them. Both come off the same canvas, one after the other, so this costs a second draw and a second upload rather than a second WebGL context.

drawnAt

method source
Reactor3D.Viewport.prototype.drawnAt(slot)

The update (Graphics.frameCount) a pass's target was last drawn on; undefined when never.

Other

_teardownShared

method internal source
Reactor3D.Viewport.prototype._teardownShared()

Teardown shared.

scale

method source
Reactor3D.Viewport.prototype.scale()

The resolution the passes render at, relative to the screen.

targetSize

method source
Reactor3D.Viewport.prototype.targetSize(scale = this._scale)

Target pixel size for the passes at the current scale.

Details

Target pixel size for the passes at the current scale. The canvas pixel ratio rides along so an enlarged game (fullscreen) renders its 3D at the pixels actually on screen instead of upscaling a game-sized pass.

upscaled

method source
Reactor3D.Viewport.prototype.upscaled()

Whether the passes are drawn smaller and enlarged by the sharpening upscale (Reactor3D.SharpUpscale).

passPixelRatio

method source
Reactor3D.Viewport.prototype.passPixelRatio()

Backing pixels per game pixel the passes draw at: the canvas's, capped by maxPassPixelRatio.

Details

Backing pixels per game pixel the passes draw at: the canvas's, capped by maxPassPixelRatio. The cap holds at every enlargement, whole-number or not: at 1.5x nearest-neighbour doubles every other pixel, and the owner judged that sharper and better on a model than any smoothed enlargement - "just like resizing an image in Photoshop".

passEnlarged

method source
Reactor3D.Viewport.prototype.passEnlarged()

Whether the passes are drawn smaller than the canvas and enlarged into it.

_trackFrame

method internal source
Reactor3D.Viewport.prototype._trackFrame()

Once per game frame: measure the interval since the last frame and let the controller move the scale.

Details

Once per game frame: measure the interval since the last frame and let the controller move the scale. A manual scale (controller off) is applied here too, so a script can set Reactor3D.renderScale at any time.

generation

method source
Reactor3D.Viewport.prototype.generation()

Bumps whenever the pass textures are replaced (a resize); sprites holding an older one rebuild.

_reapOwed

method internal source
Reactor3D.Viewport.prototype._reapOwed()

Once a game frame the view draws in: the passes a change of scale or size replaced, two such frames ago, are let go.

_target

method internal source
Reactor3D.Viewport.prototype._target(slot)

Target.

_workTarget

method internal source
Reactor3D.Viewport.prototype._workTarget(slot)

The smaller target an upscaled pass is drawn into.

pixi

method source
Reactor3D.Viewport.prototype.pixi()

Pixi.

targetHandle

method source
Reactor3D.Viewport.prototype.targetHandle(target)

The GL texture three renders target into, once it has been allocated.

passTexture

method source
Reactor3D.Viewport.prototype.passTexture(slot)

The PIXI texture that shows one pass.

Details

The PIXI texture that shows one pass. PIXI's texture system is handed the GL texture three renders into; it binds it like any other and never uploads to it. Flipped vertically: a framebuffer's first row is its bottom.

_pixiTexture

method internal source
Reactor3D.Viewport.prototype._pixiTexture(key, make, flip)

The PIXI texture over the target make() returns, kept under key for this generation; flip mirrors it so a sprite shows it upright.

Details

The PIXI texture over the target make() returns, kept under key for this generation; flip mirrors it so a sprite shows it upright.

passSprite

method source
Reactor3D.Viewport.prototype.passSprite(slot)

What PIXI shows one pass with: a sprite of its target, or, for a pass drawn smaller and enlarged (upscaled), the small target itself drawn through the sharpening filter as PIXI composites it (SharpUpscale.mesh): the full-size target, written and read again every frame, is not made.

Details

What PIXI shows one pass with: a sprite of its target, or, for a pass drawn smaller and enlarged (upscaled), the small target itself drawn through the sharpening filter as PIXI composites it (SharpUpscale.mesh): the full-size target, written and read again every frame, is not made. Not on a canvas enlarged past the passes' pixel ratio (passEnlarged): there the full-size target is itself enlarged, and the filter must run at its pixels. The way a slot is shown is fixed for the generation its object was made in (_shownWith), so SharpUpscale.inComposite takes effect at the next rebuild of the passes (a resize, a new scale).

enlargedInComposite

method source
Reactor3D.Viewport.prototype.enlargedInComposite(slot)

Whether slot's small target is enlarged by PIXI's composite, so its draw stops there.

resize

method source
Reactor3D.Viewport.prototype.resize()

Match the game canvas's backing size and on-screen placement.

scene

method source
Reactor3D.Viewport.prototype.scene()

Scene.

camera

method source
Reactor3D.Viewport.prototype.camera()

Camera.

probe

method source
Reactor3D.Viewport.prototype.probe()

What is actually on the 3D canvas, and where that canvas actually is.

Details

What is actually on the 3D canvas, and where that canvas actually is.

An empty 3D view has survived every check that can be made from the outside — meshes, textures, camera, canvas size, visibility — so this reads the drawing buffer itself. Non-black pixels mean three is drawing and the problem is compositing; all black means it is not, whatever the scene says.

shadowsFollowRefresh

method source
Reactor3D.Viewport.prototype.shadowsFollowRefresh()

Shadows follow refresh.

spreadsUpdateWork

method source
Reactor3D.Viewport.prototype.spreadsUpdateWork()

Spreads update work.

detachFromPage

method source
Reactor3D.Viewport.prototype.detachFromPage()

Stop showing the 3D canvas on its own and let PIXI draw it instead.

Details

Stop showing the 3D canvas on its own and let PIXI draw it instead.

Stacked canvases put the 3D ground outside the PIXI scene, and everything a game draws over the map assumes the map is in that scene: a fog or a lighting overlay set to MULTIPLY has nothing to multiply against, so it composites as a flat wash — which is why fog reads heavier in 3D than in 2D — and the screen tone, which is a filter on the spriteset, never reaches the ground at all.

Rendering is unaffected by the canvas being hidden: a WebGL context draws into its buffer whether or not the element is laid out.

canvas

method source
Reactor3D.Viewport.prototype.canvas()

The canvas the 3D pass draws on, for diagnostics.