ClearColor

View source

ExtendsColor

Provides the color that the WebGL renderer uses to clear its color buffer.

ClearColor is a world resource built on Color. Registering WebglRendererPlugin adds this world resource and initializes it as opaque black with { r: 0, g: 0, b: 0, a: 1 }. The renderer reads the resource before drawing, so changing its color changes the background used by subsequent WebGL frames.

Examples

import { ClearColor } from '@wimaengine/render-webgl'

// WebglRendererPlugin must be registered so the resource exists.
function setBackground(world) {
  const clearColor = world.getResource(ClearColor)
  clearColor.set(0.08, 0.12, 0.2, 1)
}

Constructor


Methods


staticserialize(value: ClearColor): ColorLike

View source

Converts a ClearColor into plain serializable color data.

The returned ColorLike object contains the r, g, b, and a channels without changing the source resource. Use ClearColor.deserialize to restore the returned data to a clear-color resource.

Parameters

NameDescriptionDefault
value

ClearColor to serialize.

—

Returns

Plain serialized color channels.

staticdeserialize(value: ColorLike, out?: ClearColor): ClearColor

View source

Restores serialized color channels in a ClearColor resource.

When out is supplied, its r, g, b, and a channels are replaced and the same resource is returned. When it is omitted, a new ClearColor is created before its channels are restored. Use ClearColor.serialize to produce the corresponding plain color data.

Parameters

NameDescriptionDefault
value

Serialized ColorLike channel data.

—
out?

ClearColor resource to populate.

...

Returns

The populated ClearColor resource.