pub struct InstancedMesh {
pub mesh: Mesh,
pub count: usize,
pub instance_matrix: InstancedBufferAttribute,
pub instance_color: Option<InstancedBufferAttribute>,
pub bounding_sphere: Option<Sphere>,
}Expand description
InstancedMesh extends Mesh: one geometry and material, drawn count
times with a per-instance transform (and optionally colour).
Fields§
§mesh: MeshThe Mesh half: geometry, material and morph state.
count: usizeInstancedMesh.count — the number of instances the renderer draws.
instance_matrix: InstancedBufferAttributeInstancedMesh.instanceMatrix.
instance_color: Option<InstancedBufferAttribute>InstancedMesh.instanceColor, null until setColorAt() is called.
bounding_sphere: Option<Sphere>InstancedMesh.boundingSphere — the object’s own bounding sphere, in
object space, over all of its instances.
Frustum.intersectsObject prefers it to the geometry’s whenever the
object declares one (object.boundingSphere !== undefined in three.js),
which is the only thing that keeps an instanced draw whose instances are
spread out from being culled as a point at the object’s origin.
None is three.js’ null: nothing has computed it yet, so the
geometry’s sphere is used instead.
Implementations§
Source§impl InstancedMesh
impl InstancedMesh
Sourcepub fn new(
geometry: Rc<BufferGeometry>,
material: MeshBasicNodeMaterial,
count: usize,
) -> ObjectRef
pub fn new( geometry: Rc<BufferGeometry>, material: MeshBasicNodeMaterial, count: usize, ) -> ObjectRef
new InstancedMesh( geometry, material, count ), as a scene-graph ObjectRef.
Sourcepub fn matrix_at(&self, index: usize) -> Matrix4
pub fn matrix_at(&self, index: usize) -> Matrix4
InstancedMesh.getMatrixAt( index, matrix ) —
matrix.fromArray( this.instanceMatrix.array, index * 16 ).
Sourcepub fn compute_bounding_sphere(&mut self)
pub fn compute_bounding_sphere(&mut self)
InstancedMesh.computeBoundingSphere() — the geometry’s sphere pushed
through every instance matrix, unioned. count instances, not the
array’s capacity, exactly as three.js does.
A geometry with no position attribute has no sphere to spread, so this
leaves InstancedMesh::bounding_sphere alone; three.js would throw.
Sourcepub fn raycast(
&mut self,
matrix_world: &Matrix4,
object: &ObjectRef,
raycaster: &Raycaster,
intersects: &mut Vec<Intersection>,
)
pub fn raycast( &mut self, matrix_world: &Matrix4, object: &ObjectRef, raycaster: &Raycaster, intersects: &mut Vec<Intersection>, )
InstancedMesh.raycast( raycaster, intersects ) — the object’s own
bounding sphere first, then Mesh.raycast() once per instance with
matrixWorld × instanceMatrix, each hit tagged with its instanceId.
three.js raycasts each instance through a scratch Mesh that has no
morphTargetInfluences, so morph targets are ignored here too.
Sourcepub fn set_color_at(&mut self, index: usize, color: &Color)
pub fn set_color_at(&mut self, index: usize, color: &Color)
InstancedMesh.setColorAt( index, color ).
The array is allocated on the first call and filled with 1, not 0,
so an instance that is never given a colour keeps the material’s own —
new Float32Array( count * 3 ).fill( 1 ) in three.js.
The colour is stored in the working (linear-sRGB) space the Color
already holds; three.js writes color.toArray(), which is the same.
Bumps instanceColor’s version when the colour differs from the one
there; see InstancedBufferAttribute for why no needsUpdate.
Sourcepub fn set_matrix_at(&mut self, index: usize, matrix: &Matrix4)
pub fn set_matrix_at(&mut self, index: usize, matrix: &Matrix4)
InstancedMesh.setMatrixAt( index, matrix ) —
matrix.toArray( this.instanceMatrix.array, index * 16 ).
Bumps instanceMatrix’s version when the matrix differs from the one
there; see InstancedBufferAttribute for why no needsUpdate.