MaterialsVariantsComponent class Materials

Switches an imported model between its named material variants (KHR_materials_variants).

The importer attaches this to the root of a model whose source declares variants. Read variants for the declared names and call select to swap every affected primitive's material in place; select(null) restores the source's default materials. Selection is cheap (material reassignment, no reload), so it is suitable for interactive switching, for example a product configurator.

final variants = MaterialsVariantsComponent.of(model);
variants?.select('beach');
Inheritance

Properties

enabled bool
Whether this component's update hook runs each frame.
getter/setter pairinherited
hashCode int
The hash code for this object.
no setterinherited
isAttached bool
Whether this component is currently attached to a node.
no setterinherited
isLoaded bool
Whether onLoad has completed.
no setterinherited
isMounted bool
Whether the owning node is part of a live scene graph.
no setterinherited
node Node
The node this component is attached to.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
selected String?
The currently selected variant name, or null when the defaults are active.
no setter
variants List<String>
The variant names declared by the source, in declaration order.
final

Methods

cloneFor(Node cloneOwner) Component?
Returns a copy of this component for cloneOwner, the Node.clone counterpart of the owning node, or null to not carry the component to clones (the default).
inherited
fixedUpdate(double fixedDt) → void
Called once per fixed physics step while the component is mounted, enabled, and loaded. fixedDt is the fixed timestep of the surrounding PhysicsWorld, not the frame interval.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
onAttach() → void
Called when this component is added to a node.
inherited
onDetach() → void
Called when this component is removed from a node.
inherited
onLoad() Future<void>
Optional asynchronous setup, such as loading an asset.
inherited
onMount() → void
Called when the owning node enters a live scene graph.
inherited
onUnmount() → void
Called when the owning node leaves a live scene graph.
inherited
select(String? name) → void
Applies the named variant to every mapped primitive.
toString() String
A string representation of this object.
inherited
update(double deltaSeconds) → void
Called once per frame while the component is mounted, enabled, and loaded. deltaSeconds is the elapsed time since the previous tick.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Methods

allOf(Node root) List<MaterialsVariantsComponent>
Every variants component on root and its subtree, in breadth-first order. Select on each to switch a multi-root model completely.
of(Node root) MaterialsVariantsComponent?
Finds the first variants component for a loaded model.