ImageImporter

View source

ExtendsImporter

Converts browser image responses into Image assets.

RenderCorePlugin registers this importer for Image. It reports the exact png and jpeg extension labels, so API users can load those image paths through AssetServer.

Examples

import { AssetServer } from '@wimaengine/asset'
import { Image, ImageAssets } from '@wimaengine/render-core'

// RenderCorePlugin and AssetServerPlugin are registered and started.
const server = world.getResource(AssetServer)
const handle = server.load(Image, '/textures/player.png')

// The request is queued; `image` is available after loading completes.
const image = world.getResource(ImageAssets).get(handle)
// `image` is undefined until the load has completed.

Constructor


constructor()

View source

Associates this importer with the Image asset constructor.

  • @inheritDoc

Methods


getExtensions(): string[]

View source

Lists the path extensions handled by this importer.

AssetServer indexes each returned label with the importer’s asset constructor. Labels must omit the leading dot and match the extension extracted from a load path exactly, including case. Return one label for each supported response format.

The base implementation always throws an Error because it does not know which formats the concrete importer supports. The empty array below is only an unreachable fallback after that error.

Throws

The base implementation always throws an error.

Returns

Supported extension labels, such as ['json'].

deserialize(response: Response, _typeRegistry: TypeRegistry): Promise<Image>

View source

Converts a fetched response into the typed asset value.

Override this method to read the response body, parse its contents, and resolve a T. Use the TypeRegistry argument when the format stores reflected or nested values; a self-contained response can ignore it. A concrete importer should resolve an asset value that can be stored for the requested asset.

The base implementation always rejects with an Error because it has no response format to parse. The undefined return below is only an unreachable fallback after that error.

Parameters

NameDescriptionDefault
response

Response containing the image bytes.

—
_typeRegistry

Importer type registry, unused for this image format.

—

Throws

The base implementation always rejects with an error.

Returns

A concrete importer should resolve the imported asset. The base implementation always rejects before resolving.