BasicMaterial

View source

ExtendsMaterial

Represents a basic color material asset for rendering geometry.

Examples

import { BasicMaterial, BasicMaterialAssets } from '@wimaengine/render-core'
import { Color } from '@wimaengine/color'

// RenderCorePlugin must be registered before this resource is used.
const material = new BasicMaterial({
  color: new Color(0.2, 0.6, 1, 1)
})
const handle = world.getResource(BasicMaterialAssets).add(material)

Constructor


constructor(options?: BasicMaterialOptions)

View source

Creates a basic material with an optional Color.

If color is omitted, the constructor creates a new default Color. A supplied color is stored as-is.

Parameters

NameDescriptionDefault
options?

Constructor options.

{}

Properties


color: Color

View source

Color value stored by this material.

The constructor stores a supplied Color reference as-is. When no color is supplied, it creates a new default Color. Mutate this value before calling BasicMaterial#asUniformBind to include its current channels in the returned uniform buffer.

Default: ...

Methods


asUniformBind(): ArrayBuffer

View source

Returns the current color as RGBA uniform data.

The method spreads the color’s iterable channels in RGBA order into a new Float32Array and returns that array’s ArrayBuffer. Each call creates a new buffer, so later mutations to BasicMaterial#color do not change an existing result and separate calls do not share storage.

Returns

A new buffer containing the color’s four RGBA values.

staticdefault(): BasicMaterial

View source

Creates the base material’s default asset value.

The base implementation returns a new Material. Concrete material classes should override this method when their default asset needs subtype-specific state.

Returns

A new base material.

staticserialize(value: BasicMaterial): BasicMaterialSerial

View source

Converts a material to the base class’s serialized representation.

The base implementation ignores _value and returns a new empty object; it does not mutate the material. Concrete material classes can override this method with fields for their own asset data.

Parameters

NameDescriptionDefault
value

Material to serialize.

—

Returns

An empty serialized representation.

staticdeserialize(value: BasicMaterialSerial, out?: BasicMaterial): BasicMaterial

View source

Restores a material from the base class’s serialized representation.

The base implementation ignores _value. When out is provided, it returns that same object without changing it; otherwise it returns a new Material. Concrete material classes can override this method to populate their own fields.

Parameters

NameDescriptionDefault
value

Serialized material color.

—
out?

Material to populate.

...

Returns

out, or a new base material when out is omitted.

staticvalidateSerial(value: unknown): value is BasicMaterialSerial

View source

Checks whether a value has the serialized basic-material shape.

The value must be an object with a color property accepted by Color.validateSerial. This checks that the color channels are numbers, but does not construct a material, enforce channel ranges, or reject non-finite numbers.

Parameters

NameDescriptionDefault
value——