Skip to content

geometry#values

Summary

geometry#values keeps optional per-vertex sample data on the CPU. Use valueComponents to interpret its stride. Plot factories can retain scalar color values or complex samples alongside their baked colors.

Syntax

values: Float32Array | null
valueComponents: number
const { values, valueComponents } = geometry;

Returns

Float32Array | null - Packed vertex metadata, with vertex i starting at i * valueComponents. valueComponents is zero without metadata. Colored scalar plots use one value and complex surfaces use two in real, imaginary order. Expanded curve profiles or back faces carry the associated value at each emitted vertex.

Example

const wgpu = await WasmGPU.create(document.querySelector("canvas"));
const plot = wgpu.geometry.cartesianSurface({
    f: (x, z) => x + z, xSegments: 4, zSegments: 4,
    color: { by: "y" }
});
console.log(plot.values?.[0]); // -2
plot.destroy();

Notes

For custom geometry, provide a Float32Array with vertexCount * valueComponents entries. The component count defaults to one and must be an integer from one through four. Invalid metadata is dropped with a console warning. The geometry retains the supplied array reference.

Upload transfers rendered vertex attributes and keeps this CPU metadata. Editing values does not recolor baked vertex colors. A Wasm position refresh that changes the vertex count clears the metadata.

See Also