Skip to main content

InstancedMesh

Struct InstancedMesh 

Source
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: Mesh

The Mesh half: geometry, material and morph state.

§count: usize

InstancedMesh.count — the number of instances the renderer draws.

§instance_matrix: InstancedBufferAttribute

InstancedMesh.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

Source

pub fn new( geometry: Rc<BufferGeometry>, material: MeshBasicNodeMaterial, count: usize, ) -> ObjectRef

new InstancedMesh( geometry, material, count ), as a scene-graph ObjectRef.

Source

pub fn matrix_at(&self, index: usize) -> Matrix4

InstancedMesh.getMatrixAt( index, matrix ) — matrix.fromArray( this.instanceMatrix.array, index * 16 ).

Source

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.

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Clone for InstancedMesh

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.