Skip to content

RenderableObject ​

Abstract base class representing a Layer-renderable object.

Renderables pair a geometry with a shader program, textures, uniform values, and a world transform. Subclasses assign a geometry, select one of the built-in shader programs through programName or provide a new one, bind textures with setTexture, and override getUniforms to feed values to the shader.

ts
class MyRenderable extends RenderableObject {
  constructor(texture: Texture) {
    super();
    this.geometry = new PlaneGeometry(512, 512, 1, 1);
    this.programName = "floatScalarImage";

    this.setTexture(0, texture);
  }

  public get type() {
    return "MyRenderable";
  }

  public override getUniforms() {
    return { u_imageSampler: 0 };
  }
}

Extends Node and inherits all public properties and methods.

Extended by ​

Properties ​

wireframeEnabled ​

Draws the geometry's wireframe on top of the normal pass. Layers use this as a chunk debugging aid. Defaults to false.

ts
wireframeEnabled: boolean = false;

wireframeColor ​

The color of the wireframe overlay. Defaults to Color.WHITE.

ts
wireframeColor: Color = Color.WHITE;

depthTest ​

Whether the object is depth tested when drawn. Objects that opt out are also left out of the depth prepass. Defaults to true.

ts
depthTest: boolean = true;

Accessors ​

geometry Geometry ​

The geometry drawn for this object.

ts
get geometry(): Geometry;
ts
set geometry(geometry): void;
ParameterDescription
geometry: GeometryThe geometry to draw.

wireframeGeometry WireframeGeometry ​

A line-segment version of geometry used for the wireframe overlay. Built lazily on first access and cached until the geometry changes.

ts
get wireframeGeometry(): WireframeGeometry;

textures Texture[] ​

The assigned textures indexed by texture unit.

ts
get textures(): Texture[];

transform TrsTransform ​

The object's world transform as translation, rotation, and scale. Layers position, orient, and size renderables through it.

ts
get transform(): TrsTransform;

programName Shader | null ​

The name of a shader program that draws the object. The renderer skips objects whose program name is null.

ts
get programName(): Shader | null;
ts
set programName(programName): void;
ParameterDescription
programName: ShaderThe shader program name.

depthProgramName Shader | null ​

The name of the shader program used in the depth prepass or null to stay out of it. Objects without one never occlude other layers.

ts
get depthProgramName(): Shader | null;

Selects the shader program for the depth prepass. Subclasses set this so the object writes depth and occludes content in other layers.

ts
set depthProgramName(programName): void;
ParameterDescription
programName: ShaderThe shader program name.

boundingBox Box3 ​

The geometry's bounding box transformed to world space. The renderer culls objects whose box falls outside the view frustum.

ts
get boundingBox(): Box3;

cullFaceMode CullingMode ​

Which triangle faces are culled when drawing. Defaults to "none".

ts
get cullFaceMode(): CullingMode;
ts
set cullFaceMode(mode): void;
ParameterDescription
mode: CullingModeThe culling mode to apply.

Methods ​

setTexture() void ​

Assigns a texture to the given texture unit. The renderer binds each entry of textures to its matching unit before drawing.

ts
setTexture(index, texture): void;
ParameterDescription
index: numberThe texture unit to bind to.
texture: TextureThe texture to assign.

clearTextures() void ​

Removes all assigned textures.

ts
protected clearTextures(): void;

markStaleTexture() void ​

Queues a replaced texture for GPU disposal. Subclasses call this when swapping out a texture they own. The renderer drains the queue through popStaleTextures before the next draw. Passing undefined is a no-op.

ts
protected markStaleTexture(texture): void;
ParameterDescription
texture: Texture | undefinedThe texture that is no longer in use.

popStaleTextures() Texture[] ​

Drains the queue of textures marked stale. Called automatically by the renderer, which disposes the GPU resources of each returned texture.

ts
popStaleTextures(): Texture[];

getUniforms() Record<string, unknown> ​

Returns the uniform values to upload before drawing. Override in subclasses that need custom uniforms. Values are matched to shader uniforms by name and take precedence over the owning layer's uniforms.

ts
getUniforms(): Record<string, unknown>;

Released under the MIT License