Skip to main content

TextureLoader

From-v4.4

A loader for image-based composite textures described by a JSON manifest.

LoaderCharacteristic
File FormatJSON manifest
File Extension.json
File TypeText
Data FormatTexture
Supported APIsload, parse

Usage

import {load} from '@loaders.gl/core';
import {TextureLoader} from '@loaders.gl/textures';

const image = await load('texture.image-texture.json', TextureLoader);

Member images are parsed with ImageLoader by default. If you call load() with a loader array, those additional loaders are also available for manifest members:

import {load} from '@loaders.gl/core';
import {TextureLoader, CompressedTextureLoader, BasisLoader} from '@loaders.gl/textures';

const texture = await load('texture.image-texture.json', [
TextureLoader,
CompressedTextureLoader,
BasisLoader
]);

This allows manifest members to use image formats handled by ImageLoader as well as compressed member formats handled by the additional loaders.

Manifest

Single image:

{
"shape": "image-texture",
"image": "texture.png"
}

Mipmapped image:

{
"shape": "image-texture",
"mipmaps": ["texture-0.png", "texture-1.png", "texture-2.png"]
}

Template-driven mipmapped image:

{
"shape": "image-texture",
"mipLevels": "auto",
"template": "texture-{lod}.png"
}

Template placeholders are validated strictly. Supported placeholders for TextureLoader are {lod} only. Use \\{ and \\} to include literal braces in filenames.

Options

OptionTypeDefaultDescription
core.baseUrlstring-Base URL used to resolve relative member paths when parsing an in-memory manifest.

Output

Returns a Texture with:

  • shape: 'texture'
  • type: '2d'
  • data: one TextureLevel per mip level

For image-backed levels, TextureLevel.imageBitmap is populated when available and TextureLevel.data is an empty Uint8Array.