setInstanceAttribute method
Sets one declared per-instance attribute on the instance at index.
name must name an attribute in the bound material's
instance_attributes list, and value must match its declared type: a
num for float, or the matching Vector2 / Vector3 / Vector4.
An instance whose attributes are never set draws with zeros.
Implementation
void setInstanceAttribute(int index, String name, Object value) {
RangeError.checkValidIndex(index, _instances, 'index');
final schema = _requireSchema(name);
final slot = schema.slot(name);
if (slot == null) {
throw ArgumentError('Unknown instance attribute "$name".');
}
final offset = index * schema.floatCount + slot.floatOffset;
switch ((slot.type, value)) {
case (FmatType.float_, final num v):
_attributeData[offset] = v.toDouble();
case (FmatType.vec2, final Vector2 v):
_attributeData.setAll(offset, v.storage);
case (FmatType.vec3, final Vector3 v):
_attributeData.setAll(offset, v.storage);
case (FmatType.vec4, final Vector4 v):
_attributeData.setAll(offset, v.storage);
default:
throw ArgumentError(
'Instance attribute "$name" is ${slot.type.glslType}; cannot assign '
'a ${value.runtimeType}.',
);
}
_revision++;
}