selectVariant method
Dresses every part in its material for the variant called name, or
in its default material when name is null.
A part the variant does not mention wears its default, which is what
KHR_materials_variants says. Returns false, changing nothing, when no
variant has that name.
Switching changes which material each mesh node points at, never the materials themselves, so two instances sharing the asset's materials can still wear two variants at once.
Implementation
bool selectVariant(String? name) {
final index = name == null ? -1 : variants.indexOf(name);
if (name != null && index < 0) return false;
for (final (mesh, part) in _drawn) {
mesh.material = _materialFor(
part.variantMaterials[index] ?? part.material,
);
}
_variant = name;
return true;
}