Model loading · function

reachableTextures

Drop the images no material samples, and renumber the ones that stay.

Explained in Importing models.

function reachableTextures(refs: readonly AssetReference[], materials: readonly DrftMaterial[] | undefined):
import { reachableTextures } from '@driftengine/assets';

Parameters

ParameterTypeDescription
refsreadonly AssetReference[]
materialsreadonly DrftMaterial[] | undefined

In depth

A reader keeps every image the file declared, on purpose: gltf.ts indexes by texture rather than by image so a material's index means what the file said it meant, and readModel leaves a reference that resolved to nothing in the list for the same reason. That invariant is about the read. By the time a .drft is written the four ordinals in MATL are the only things that can reach TEXS at all, so an entry nothing points at is bytes a browser downloads and never decodes.

It was measured at a whole model: a car written in glTF's archived specular-glossiness model imported with 20 textures embedded and none of them bound, the largest a 10 MB body map. The reader now binds them, and the ones that stay unreachable — a specular-glossiness map, whose channels no rearrangement fits into an ORM one — are what this drops.

Renumbering is the whole difficulty and the reason this is one function. Compacting the list without rewriting the ordinals repaints the model, which is exactly why both the embedding and readModel refuse to drop an entry on their own; the two halves have to happen together or neither may happen.

What it gives up: an image no material samples is no longer in the asset, so TextureSet.get cannot return it and a consumer holding a name for one gets the throw that lookup exists to give. That is the documented behaviour — HANDBOOK §3 had promised only images a material actually reaches are embedded for longer than it had been true — and the alternative is every asset carrying its source's whole texture folder. What would make it wrong: a consumer that wants an unsampled image out of the container for its own use, which would need a way to say so rather than the accident of it having been left in.

An ordinal already past the end of the list is left exactly where it is. It is a broken import either way and readDrft refuses it by name; renumbering it would turn that refusal into a silently wrong texture.