Skip to content
bg2 engine

SkyCube

The SkyCube class renders a skybox using a cube mesh with inverted normals (back face rendering), providing an environment map background. It’s similar to SkySphere but uses a cube geometry instead of sphere.

constructor(renderer: Renderer)

Creates an uninitialized sky cube. All fields start as null.

Reference to the owning Renderer.

The cube map texture. Set via the texture setter (only after initialization) or during load().

The internal Material with albedo texture linked to the sky cube texture. Created during load().

The active sky cube shader. Set via load() or defaults to SkyCubeShader.

Lazy-initialized polygon list renderer containing a cube geometry (1x1x1). The cull face is set to PolyListCullFace.FRONT for back-face rendering

The render state generated by updateRenderState(). Used internally to draw the sky cube.

load(cubemapTexture: Texture, Shader?, shaderParams?) : Promise<void>

Section titled “load(cubemapTexture: Texture, Shader?, shaderParams?) : Promise<void>”

Initializes the sky cube with a cubemap texture.

await skyCube.load(myCubemapTexture);
await skyCube.load(myCubemapTexture, MyCustomSkyShader, [param1]);

Sets/changes the sky cube texture after initialization. Throws if called before load():

skyCube.texture = newSkyCubemap; // Only after load() completes

updateRenderState({ viewMatrix, projectionMatrix }) : RenderState

Section titled “updateRenderState({ viewMatrix, projectionMatrix }) : RenderState”

Creates or updates the render state with rotated view matrix and specified projection. The rotation is extracted from the view matrix to keep the sky cube aligned with camera orientation:

const rs = skyCube.updateRenderState({
viewMatrix: camera.viewMatrix,
projectionMatrix: camera.projectionMatrix
});

Throws Error: calling base implementation of SkyCube. This method must be overridden by a subclass.

Cleans up all resources: shader, texture, poly list renderer, material.

const skyCube = new SkyCube(renderer);
await skyCube.load(myCubemapTexture);
// Integrate with scene renderer's render loop manually or via subclass