Texture
A GPU texture for 3D materials, decoded natively by the 3D engine. Not interchangeable with
Texture2D — that one feeds the 2D sprite engine; this one feeds
Material uniforms. Load the same image into both types if a project uses it in
both worlds.
At a glance
const tex = await Texture.load(asset('./crate.jpg'))
const crate = Mesh.box({ material: Material.lit({ map: tex }) })
scene.add(crate)Loading
Texture.load(source: string | FetchResponse | File): Promise<Texture>Accepts an asset/remote URL string, an already-fetched FetchResponse, or a File (e.g. from
openFilePicker). URL loads reject on HTTP errors (status ≥ 400) and on decode failure.
Texture.fromCanvas(canvas: Canvas): TextureBakes a Canvas surface into a texture — synchronous, no decode. The texture
is cached on the canvas, so repeated calls (or several materials) share one GPU texture, and
canvas.update() re-uploads it. You rarely call this yourself: assigning a Canvas to
material.map does it for you.
Properties
tex.width, tex.height // pixel dimensions (read-only)
tex.wrapS = 1 // horizontal (U) wrap mode
tex.wrapT = 1 // vertical (V) wrap modewrapS / wrapT are applied when the texture is assigned to a material uniform — set them
before material.set('baseColorMap', tex).
there is no dispose() on Texture — a loaded texture cannot be freed explicitly and
lives until the 3D engine is torn down. Load big textures once and reuse them.
Video textures
A texture can't be created from a video file directly — play it with a VideoPlayer and sample
its texture:
const player = new VideoPlayer(asset('./clip.mp4'))
const screen = Mesh.plane({ material: Material.video(player.texture) })player.texture reports width/height of 0 (the video's size isn't known at texture-creation
time). See Media and Material.video.
Pitfalls
// ✗ feeding a 3D Texture to a Sprite (or a Texture2D to a Material)
new Sprite({ texture: await Texture.load(url) }) // wrong engine — use Texture2D.load
// ✓ each engine loads its own type
new Sprite({ texture: await Texture2D.load(url) })