setCustomAttribute method
Attaches a custom per-vertex attribute stream named name, matching a
material's attributes entry (and the generated shader's in <name>).
data is a tightly packed run of components-component float vectors,
one per vertex (so its length is vertexCount * components). The stream
is uploaded to its own buffer and bound after the geometry's built-in
attributes in the color pass; the depth-style passes fetch only position,
so an attribute-driven vertex displacement is not reflected in shadows.
Re-attaching the same name replaces it. Custom attributes require the
described-layout (unskinned) geometry path.
Implementation
void setCustomAttribute(
String name,
Float32List data, {
required int components,
}) {
if (components < 1 || components > 4) {
throw ArgumentError.value(
components,
'components',
'must be between 1 and 4',
);
}
final bytes = ByteData.sublistView(data);
final buffer = gpu.gpuContext.createDeviceBuffer(
gpu.StorageMode.hostVisible,
bytes.lengthInBytes,
);
buffer.overwrite(bytes);
_customAttributes[name] = (
format: _vertexFormatForComponents(components),
view: gpu.BufferView(
buffer,
offsetInBytes: 0,
lengthInBytes: bytes.lengthInBytes,
),
data: data,
components: components,
);
}