Model loading · interface

ObjectSdf

What an object's distance field is, and why it is baked rather than computed.

Explained in Importing models.

interface ObjectSdf
import type { ObjectSdf } from '@driftengine/assets';

In depth

Indirect light needs to ask what is in a direction, and a triangle list cannot answer that cheaply. A ray against a mesh is a traversal; a ray against a distance field is a march that steps by the field's own value and converges in a handful of steps, because the value is a safe step. That is the whole of sphere tracing, and the one property it rests on is that the field is a distance — gradient of unit length — rather than merely something with the right sign. sdf.test.ts measures that property rather than assuming it.

Per object rather than per world, because the world moves: globalField.ts composes these into a field around the camera each frame, and an instance that rotates or streams in has to bring its field with it. A world-scale bake would have to be redone whenever anything moved.

Properties

NameTypeDescription
fieldreadonlyFloat32ArrayDistance in metres, negative inside. x fastest, then y, then z.
dimsreadonlyreadonly [number, number, number]Samples on each axis. The spacing is the same on all three; see bakeObjectSdf.
boundsreadonlyFloat32ArrayThe field's own extent, [minX, minY, minZ, maxX, maxY, maxZ]. Padded past the mesh.