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
impl Mesh
Sourcepub fn new(
geometry: Rc<BufferGeometry>,
material: impl Into<Option<MeshBasicNodeMaterial>>,
) -> ObjectRef
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.
Sourcepub fn with_materials(
geometry: Rc<BufferGeometry>,
materials: Vec<MeshBasicNodeMaterial>,
) -> ObjectRef
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.
Sourcepub fn of(
geometry: Rc<BufferGeometry>,
material: Option<MeshBasicNodeMaterial>,
) -> Self
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.
Sourcepub fn get_vertex_position(&self, index: usize) -> Vector3
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.
Sourcepub fn raycast(
&self,
matrix_world: &Matrix4,
object: &ObjectRef,
raycaster: &Raycaster,
intersects: &mut Vec<Intersection>,
)
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.