Diorama

Made for a big screen.

This site is one 3D scene, built for a computer: a wide window and a mouse. Open dioramajs.dev on a desktop or a laptop to see it.This site is one 3D scene, built for a wide window. Make this one wider, or open dioramajs.dev on a larger screen.

GitHub

DioramaDocs

EffectContext interface

Methods are bound, so `setup({ surface, u, place })` works.

View as Markdown
import type { EffectContext } from '@dioramajs/diorama'
interface EffectContext<P extends ParamSpec = ParamSpec>

Members

NameTypeDescription
readonly appEffectApp

Kernel scope of the instance: services, listeners and systems that die with it.

readonly elementElement

The element the instance runs on.

readonly inputEffectInput

Same object as layer.input.

readonly layerLayer

The element's layer, shared by its effects.

readonly mapTexture

The <img> or <video> as a texture, shared by all effects on the element. Needs media: true.

readonly namestring

The effect's name, the token in data-dio.

readonly overlayGroup

Like viewport (centre 0,0, world px, ignores pose, hides with the layer), but drawn after every copy and above level, with depth test and depth write off. Grain, trails, cursors.

readonly paramsReadonly<ParamsOf<P>>

Live resolved values. Read them in update, a read in setup is a snapshot.

readonly qualityQualityTier

The tier from @dioramajs/quality, 'high' without it. A read outside update re-runs setup on a change.

readonly renderRenderApi

The renderer, scene and camera.

readonly signalAbortSignal

Aborted on dispose.

readonly surfaceSurface

The shared GL copy of the element, created on first access.

readonly uUniforms<P>

Input uniforms and one uniform per live param, for TSL graphs.

readonly viewportGroup

Group pinned to the viewport (centre 0,0, world px). It does not scroll with the element, ignores pose and hides while the layer is off screen. Use place(g, { fit: 'none' }) to follow the box instead.

attach
attach<Q extends ParamSpec>(
  target: string | Element,
  use: Effect<Q> | EffectUse<Q>,
): EffectHandle<Q>

Attaches an effect owned by this instance. A selector resolves inside the element.

compile
compile(object: Object3D): Promise<void>

Compiles the materials of object before it is first drawn, on the runtime's queue with every other compile. Use it instead of renderer.compileAsync: three keeps one precompilation state per renderer, and two compiles at once fail. Rejects with the shader error; does nothing once the phase is gone.

coverUV
coverUV(uv?: Node<'vec2'>): Node<'vec2'>

Maps box UV to texture UV with the element's object-fit and object-position. Defaults to uv().

fit
fit(texture: Texture, options?: FitOptions): Fit

CSS object-fit and object-position for any texture, e.g. the images of children.

invalidate
invalidate(): void

Requests one frame if the layer is visible: from an event handler or a loaded resource. State that moves on over several frames asks from the update by returning true.

layers
layers(selector: string): readonly Layer[]

Live layers of matching descendants in document order. The array updates in place.

mask
mask(uv?: Node<'vec2'>): Node<'float'>

0..1 alpha mask at box UV for own materials: contain bars, radius, overflow clip, opacity.

model
model(url: string, options?: ModelOptions): Promise<Object3D<Object3DEventMap>>

A glTF instance from the assets cache, clips in .animations. Starts the environment lease. Needs assets.

onDispose
onDispose(cleanup: Cleanup): Off

Runs cleanup when the instance is disposed or rebuilt.

place
place<T extends Object3D<Object3DEventMap>>(
  object: T,
  options?: PlaceOptions,
): T

Glues an object to the box so it follows layout and pose. Disposed with the instance.

pose
pose(layer: Layer, target: PoseTarget, weight: number): void

Blends a layer from its layout towards target by weight for this frame. Call from update. A taken copy wins: with a box only the pose's above applies, and the copy's own radius, clip and non-zero above beat the pose's.

raise
raise(): Off

Lifts the canvas above every element of the page, into the browser's top layer, until the returned Off runs or the phase closes. Calls are counted: the canvas comes down with the last Off. For full-screen views over sticky headers and chat widgets; a modal <dialog> shown after it stays above the canvas. Without the Popover API the canvas takes the highest z-index instead, which elements with that same value still beat.

section
section(): Anchor

The scroll section the element plays in: the closest [data-dio-section] ancestor, else the parent of the closest position: sticky ancestor, else the element itself. Its pin runs while a sticky stage is held. Shared, updated every frame and released with the phase: never dispose it. Looked up again when the element re-measures, so call it where you read it.

set
set(values: Partial<ParamsOf<P>>): void

Writes params the way instance.set does in site code: the write beats attributes and shows in handle.params. For an effect whose own interaction moves a param, like a gallery's index.

showDom
showDom(show: boolean): void

true hands the picture to the DOM: this phase's replace object and its surface share stop counting as the element's copy, and drawn drops if no other copy is left. false takes it back from the next drawn frame. Default false.

texture
texture(
  url: string,
  options?: TextureOptions,
): Promise<Texture<unknown, TextureEventMap>>

A texture from the assets cache: shared, never dispose it. The lease dies with the phase. Needs assets.

Also exported from @dioramajs/diorama/auto, @dioramajs/diorama/effects, @dioramajs/effects.

Defined in packages/effects/src/types.ts.