Model loading · class

TextureSet

Explained in Importing models.

class TextureSet<T>
import { TextureSet } from '@driftengine/assets';

Accessors

NameTypeDescription
sizegetnumberHow many textures were created, which is not the number the file carried.

Methods

fromstatic

static from<T>(textures: readonly DrftTexture[], create: (texture: DrftTexture, at: number) => T | null): TextureSet<T>

Build the lookup as the textures are created, in file order.

ParameterTypeDescription
texturesreadonly DrftTexture[]
create(texture: DrftTexture, at: number) => T | null
More

create returning null means that image could not be decoded, which is survivable: the surface draws untextured and the slot stays addressable, so a later replace can still put something there. Dropping the entry instead would renumber everything after it.

all

all(): readonly T[]

Every created texture, for disposal rather than for addressing.

at

at(index: number): T | null

The texture a material named, by its index in the file, or null.

ParameterTypeDescription
indexnumber

has

has(name: string): boolean

Whether a name resolves, for a caller that wants to ask rather than to handle a throw.

ParameterTypeDescription
namestring

get

get(name: string): T

The texture called this, or a refusal naming every texture the asset does have.

ParameterTypeDescription
namestring
More

Throwing beats returning null. A caller asking by name has a specific image in mind, and a null it forgets to check is the silent-wrong-surface failure that indices already had.