InstancedMesh class Scene graph
Many copies of one Geometry / Material pair, each placed by its own model transform.
Use an InstancedMesh for foliage, crowds, debris, or any scene that
holds many copies of the same mesh. Attach it to a node with an
InstancedMeshComponent; the whole set is then one render item, one
pipeline, and one cull test rather than one node per copy.
Instances with different colors whose faces overlap in one plane flicker against each other (z-fighting); place repeated pieces so they abut.
Constructors
- InstancedMesh({required Geometry geometry, required Material material, bool cullInstances = false, bool sortTransparentInstances = true})
-
Creates an instanced mesh that draws
geometryshaded bymaterial. It starts with no instances; add them with addInstance.
Properties
- cullInstances → bool
-
Whether the renderer culls each instance after the aggregate bounds pass.
final
- drawSelector ↔ MeshDrawSelector?
-
Picks how many leading instances and which index range each draw uses,
or null to draw everything. Order instances so the ones worth keeping
come first. See MeshDrawSelector.
getter/setter pair
- geometry → Geometry
-
The geometry drawn for every instance.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- instanceCount → int
-
The number of instances.
no setter
- material → Material
-
The material every instance is shaded with.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- sortTransparentInstances → bool
-
Whether translucent instances are sorted back to front before drawing.
final
Methods
-
addInstance(
Matrix4 transform, {Vector4? color}) → int -
Adds an instance placed by
transformand returns its index. -
clearInstances(
) → void - Removes every instance.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
removeInstanceAt(
int index) → void -
Removes the instance at
index. Instances after it shift down by one, so their indices change. -
setInstanceAttribute(
int index, String name, Object value) → void Scene graph -
Sets one declared per-instance attribute on the instance at
index. -
setInstanceAttributes(
int index, Float32List packed) → void Scene graph -
Writes every declared per-instance attribute of the instance at
indexfrompacked, in declaration order. -
setInstanceColor(
int index, Vector4 color) → void -
Replaces the color multiplier of the instance at
index. -
setInstanceTransform(
int index, Matrix4 transform) → void -
Replaces the transform of the instance at
index. -
toString(
) → String -
A string representation of this object.
inherited
-
updateInstanceTransforms(
void update(List< Matrix4> transforms), {bool recomputeWinding = true}) → void - Updates every instance transform in place and invalidates the batch once.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited