Skip to main content

Mesh

Struct Mesh 

Source
pub struct Mesh {
    pub geometry: Rc<BufferGeometry>,
    pub material: Option<MeshBasicNodeMaterial>,
    pub materials: Vec<MeshBasicNodeMaterial>,
    pub morph_target_influences: Vec<f64>,
    pub line_segments: Option<LineSegments2State>,
    pub count: Option<usize>,
}
Expand description

The state Mesh adds to Object3D. It lives in a node’s Payload rather than wrapping an Object3D, because the renderer finds meshes by walking the tree — see docs/scene-graph.md.

Fields§

§geometry: Rc<BufferGeometry>

Mesh.geometry.

§material: Option<MeshBasicNodeMaterial>

Mesh.material when it is a single material.

§materials: Vec<MeshBasicNodeMaterial>

Mesh.material when it is an array — Array.isArray( material ).

three.js has one property that holds either a material or an array of them; the port keeps the array form here, beside material, and a mesh built with Mesh::with_materials has material: None and a non-empty materials. Renderer._projectObject() then pushes one render item per entry of geometry.groups, drawn with materials[ group.materialIndex ] over the group’s index (or vertex) range — see docs/nodes.md §51.

§morph_target_influences: Vec<f64>

Mesh.morphTargetInfluences — one weight per morphAttributes.position entry, filled in by updateMorphTargets() from the constructor.

§line_segments: Option<LineSegments2State>

Some when this mesh is a LineSegments2: the object’s own state (its _resolution), which also routes raycast() to the fat-line version. The segments themselves are on the geometry, as instanceStart / instanceEnd interleaved views.

§count: Option<usize>

mesh.count, which is not a Mesh property in three.js: a page sets it ad hoc (webgpu_instance_path‘s mesh.count = 1000, webgpu_particles’ smokeInstancedSprite.count = 2000) and RenderObject.getInstanceCount() (RenderObject.js:617-631) reads it as object.count !== undefined ? max( 0, object.count ) : 1, so a plain mesh — one whose geometry is not an InstancedBufferGeometry — draws that many instances, and a node tells them apart through instanceIndex or an instancedBufferAttribute. None is undefined. Points::count is the same thing on Points.

Implementations§

Source§

impl Mesh

Source

pub fn new( geometry: Rc<BufferGeometry>, material: impl Into<Option<MeshBasicNodeMaterial>>, ) -> ObjectRef

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

The material is impl Into<Option<MeshBasicNodeMaterial>>, so a call passes the material by value as Line::new and InstancedMesh::new do, or None where three.js leaves material undefined and the renderer falls back to a default white MeshBasicMaterial — which is what webgpu_postprocessing_masking and webgpu_depth_texture rely on, together with scene.overrideMaterial.

Source

pub fn with_materials( geometry: Rc<BufferGeometry>, materials: Vec<MeshBasicNodeMaterial>, ) -> ObjectRef

new Mesh( geometry, materials ) with an array of materials: each of geometry.groups is drawn with materials[ group.materialIndex ]. A group whose index has no material is skipped, as three.js’ if ( groupMaterial && groupMaterial.visible ) skips it.

Source

pub fn of( geometry: Rc<BufferGeometry>, material: Option<MeshBasicNodeMaterial>, ) -> Self

The Mesh state alone, for a caller that already has the ObjectRef to install it on — GLTFLoader, whose tree node exists before the primitive that turns it into a mesh, the way SkinnedMesh::of serves the skinned half.

Source

pub fn get_vertex_position(&self, index: usize) -> Vector3

Mesh.getVertexPosition( index, target ) — the vertex’s position with the morph targets applied, as the vertex shader would place it before skinning.

Source

pub fn raycast( &self, matrix_world: &Matrix4, object: &ObjectRef, raycaster: &Raycaster, intersects: &mut Vec<Intersection>, )

Mesh.raycast( raycaster, intersects ), for the node object whose matrixWorld is matrix_world.

three.js returns early when material === undefined; a port mesh with no material draws with the renderer’s default MeshBasicMaterial (FrontSide), which is what three’s constructor would have given it, so it raycasts as front-sided instead.

Trait Implementations§

Source§

impl Clone for Mesh

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§

§

impl !RefUnwindSafe for Mesh

§

impl !Send for Mesh

§

impl !Sync for Mesh

§

impl !UnwindSafe for Mesh

§

impl Freeze for Mesh

§

impl Unpin for Mesh

§

impl UnsafeUnpin for Mesh

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.