Skip to content

Scientific geometry

Volumes ​

scenes/volumes
const volume = plot.uploadVolume(field(n, 10, blobs));
plot.showVolume(volume, defaultVolumeOpacity());
plot.frameScene();
return { readout: `${n} cubed, ${((n * n * n) / 1e6).toFixed(1)}M samples` };

Calls

4 in the code above, in the order it makes them

plot.uploadVolume(field: Field): VolumeHandle

Upload a scalar field as a 3D texture for ray-marching.

plot.showVolume(handle: VolumeHandle, opacity?: number): void

Draw the volume handle names, ray-marched through the whole field.

opacity multiplies how much each sample along the ray contributes. How solid a field should look depends on what it is, so there is no right value to bake in; the default is one a typical field is visible at.

defaultVolumeOpacity(): number

An opacity a typical field is visible at, as a starting point.

plot.frameScene(): void

Point the camera at the middle of everything uploaded, far enough back to see it.

Call after uploading. A scene measured in grid cells or in millimetres is nowhere near where a camera starts, and without this the first thing a caller sees is an empty canvas.