pub struct BufferGeometry {
pub id: GeometryId,
pub index: Option<Index>,
pub morph_targets_relative: bool,
pub groups: Vec<Group>,
pub draw_range: DrawRange,
pub bounding_sphere: Option<BoundingSphere>,
pub instance_count: Option<usize>,
/* private fields */
}Expand description
Port of BufferGeometry’s state: the named attribute map, the index, morph
attributes, groups and the draw range.
attributes is a Vec of pairs rather than a HashMap because three.js’
attributes is a plain object, and toNonIndexed() and the renderer both
iterate it in insertion order.
Fields§
§id: GeometryIdBufferGeometry.id. Read-only in spirit; see GeometryId for why a
clone gets a new one, and why the renderer keys on it.
index: Option<Index>BufferGeometry.index.
morph_targets_relative: boolBufferGeometry.morphTargetsRelative.
groups: Vec<Group>BufferGeometry.groups.
draw_range: DrawRangeBufferGeometry.drawRange.
bounding_sphere: Option<BoundingSphere>BufferGeometry.boundingSphere when it was computed from something
other than the position attribute, which
compute_bounding_sphere then returns
instead of recomputing.
three.js has this for free: computeBoundingSphere() writes
this.boundingSphere and the renderer reads the field, so a subclass
that overrides the method (LineSegmentsGeometry, which must measure
instanceStart / instanceEnd rather than its fixed ±2 quad) is
automatically what culling sees. The port’s method has no field behind
it, so the override lands here.
instance_count: Option<usize>InstancedBufferGeometry.instanceCount. Some makes this an
InstancedBufferGeometry: RenderObject.getInstanceCount() reads it
ahead of the object’s own count, and its
instanced attributes step per
instance.
Implementations§
Source§impl BufferGeometry
impl BufferGeometry
Sourcepub fn dispose(self: Rc<Self>)
pub fn dispose(self: Rc<Self>)
geometry.dispose() — drops this handle, and nothing more. A mesh
holds its geometry as an Rc, which is what this takes; the renderer
frees the uploaded buffers once every handle is gone, at the top of the
next render (docs/scene-graph.md, “Identity and eviction”). Dropping
the Rc does the same; this exists so three.js code ports line for
line.
Sourcepub fn set_indirect(
&mut self,
indirect: IndirectStorageBufferAttribute,
) -> &mut Self
pub fn set_indirect( &mut self, indirect: IndirectStorageBufferAttribute, ) -> &mut Self
geometry.setIndirect( attribute ): the draw’s arguments come from
this buffer on the GPU — drawIndirect for a non-indexed geometry,
drawIndexedIndirect for an indexed one — so the vertex and instance
counts a kernel wrote are the ones drawn, with no CPU round trip.
Sourcepub fn indirect(&self) -> Option<&IndirectStorageBufferAttribute>
pub fn indirect(&self) -> Option<&IndirectStorageBufferAttribute>
geometry.indirect.
Sourcepub fn id(&self) -> usize
pub fn id(&self) -> usize
BufferGeometry.id — the renderer’s cache key for this geometry’s
uploaded buffers.
Sourcepub fn get_attribute(&self, name: &str) -> Option<&BufferAttribute>
pub fn get_attribute(&self, name: &str) -> Option<&BufferAttribute>
BufferGeometry.getAttribute( name ).
Sourcepub fn get_attribute_mut(&mut self, name: &str) -> Option<&mut BufferAttribute>
pub fn get_attribute_mut(&mut self, name: &str) -> Option<&mut BufferAttribute>
BufferGeometry.getAttribute( name ), mutably.
The &mut setters on BufferAttribute (set_xyz and the rest) do not
bump its version, so handing one out drops the cached bounds.
Sourcepub fn set_attribute(
&mut self,
name: &str,
attribute: BufferAttribute,
) -> &mut Self
pub fn set_attribute( &mut self, name: &str, attribute: BufferAttribute, ) -> &mut Self
BufferGeometry.setAttribute( name, attribute ).
Sourcepub fn delete_attribute(&mut self, name: &str) -> &mut Self
pub fn delete_attribute(&mut self, name: &str) -> &mut Self
BufferGeometry.deleteAttribute( name ).
Sourcepub fn has_attribute(&self, name: &str) -> bool
pub fn has_attribute(&self, name: &str) -> bool
BufferGeometry.hasAttribute( name ).
Sourcepub fn attributes(&self) -> impl Iterator<Item = (&str, &BufferAttribute)>
pub fn attributes(&self) -> impl Iterator<Item = (&str, &BufferAttribute)>
for ( const name in geometry.attributes ), in insertion order.
Sourcepub fn position(&self) -> Option<&BufferAttribute>
pub fn position(&self) -> Option<&BufferAttribute>
geometry.attributes.position.
Sourcepub fn normal(&self) -> Option<&BufferAttribute>
pub fn normal(&self) -> Option<&BufferAttribute>
geometry.attributes.normal.
Sourcepub fn uv(&self) -> Option<&BufferAttribute>
pub fn uv(&self) -> Option<&BufferAttribute>
geometry.attributes.uv.
Sourcepub fn get_morph_attribute(&self, name: &str) -> Option<&[BufferAttribute]>
pub fn get_morph_attribute(&self, name: &str) -> Option<&[BufferAttribute]>
geometry.morphAttributes[ name ].
Sourcepub fn set_morph_attribute(
&mut self,
name: &str,
attributes: Vec<BufferAttribute>,
) -> &mut Self
pub fn set_morph_attribute( &mut self, name: &str, attributes: Vec<BufferAttribute>, ) -> &mut Self
geometry.morphAttributes[ name ] = attributes.
Sourcepub fn morph_attributes(
&self,
) -> impl Iterator<Item = (&str, &[BufferAttribute])>
pub fn morph_attributes( &self, ) -> impl Iterator<Item = (&str, &[BufferAttribute])>
for ( const name in geometry.morphAttributes ), in insertion order.
Sourcepub fn add_group(&mut self, start: usize, count: usize, material_index: usize)
pub fn add_group(&mut self, start: usize, count: usize, material_index: usize)
BufferGeometry.addGroup( start, count, materialIndex ).
Sourcepub fn clear_groups(&mut self)
pub fn clear_groups(&mut self)
BufferGeometry.clearGroups().
Sourcepub fn set_draw_range(&mut self, start: usize, count: usize)
pub fn set_draw_range(&mut self, start: usize, count: usize)
BufferGeometry.setDrawRange( start, count ).
Sourcepub fn set_from_points(&mut self, points: &[Vector3]) -> &mut Self
pub fn set_from_points(&mut self, points: &[Vector3]) -> &mut Self
BufferGeometry.setFromPoints( points ).
three.js overwrites an existing position attribute in place when there
already is one, and only allocates a fresh Float32BufferAttribute when
there is not; the in-place branch keeps the attribute’s own count, so
extra points are dropped and missing ones leave whatever was there.
Sourcepub fn set_index(&mut self, indices: &[u32])
pub fn set_index(&mut self, indices: &[u32])
BufferGeometry.setIndex( array ) — picks Uint16 when it fits, the
same rule three.js uses.
Sourcepub fn set_index_attribute(&mut self, index: Index)
pub fn set_index_attribute(&mut self, index: Index)
BufferGeometry.setIndex( bufferAttribute ) — keeps the array type the
source declared, which is what BufferGeometryLoader.parse() does.
Sourcepub fn compute_bounding_box(&self) -> Option<BoundingBox>
pub fn compute_bounding_box(&self) -> Option<BoundingBox>
BufferGeometry.computeBoundingBox() — Box3.setFromBufferAttribute( position ). None when there is no position attribute (three.js leaves
boundingBox alone in that case).
Cached, together with the sphere; see
compute_bounding_sphere for when the
cache is recomputed.
Sourcepub fn compute_bounding_sphere(&self) -> Option<BoundingSphere>
pub fn compute_bounding_sphere(&self) -> Option<BoundingSphere>
BufferGeometry.computeBoundingSphere(): the bounding box’s centre, then
the largest distance from it to any vertex (which beats the box’s own
sphere by up to sqrt(3)).
The pub bounding_sphere field, when set, is
returned as it is, ahead of anything computed here.
Otherwise the box and the sphere are computed once and cached, keyed on
the position attribute’s id and version, each position morph
target’s id and version, and morph_targets_relative. Culling calls
this for every object every frame, so walking every vertex each time
was most of a frame for a scene of many meshes (issue #133). The cache
is dropped by the &mut methods that replace or hand out an attribute
(set_attribute, delete_attribute, set_morph_attribute,
get_attribute_mut and so everything built on it, apply_matrix4 and
set_from_points included). An edit through
array_mut() is seen only after
set_needs_update(), the same rule
the renderer’s buffer upload follows. That is stricter than three.js,
whose boundingSphere is never invalidated by itself: there a moved
vertex needs computeBoundingSphere() called again by hand.
Sourcepub fn compute_vertex_normals(&mut self)
pub fn compute_vertex_normals(&mut self)
BufferGeometry.computeVertexNormals().
The accumulation runs through the normal attribute itself, so every
partial sum is rounded to f32 before the next triangle adds to it.
An existing normal of the right count is written in place through
its setters, whatever its array kind and interleaved or not, and
marked for re-upload; a missing one (or one of another count) is
replaced by a new Float32Array attribute.
Sourcepub fn normalize_normals(&mut self)
pub fn normalize_normals(&mut self)
BufferGeometry.normalizeNormals().
Sourcepub fn apply_matrix4(&mut self, matrix: &Matrix4) -> &mut Self
pub fn apply_matrix4(&mut self, matrix: &Matrix4) -> &mut Self
BufferGeometry.applyMatrix4().
Sourcepub fn apply_quaternion(&mut self, q: &Quaternion) -> &mut Self
pub fn apply_quaternion(&mut self, q: &Quaternion) -> &mut Self
BufferGeometry.applyQuaternion().
Sourcepub fn rotate_x(&mut self, angle: f64) -> &mut Self
pub fn rotate_x(&mut self, angle: f64) -> &mut Self
BufferGeometry.rotateX() — rotates the geometry about the world x-axis.
Sourcepub fn look_at(&mut self, vector: &Vector3) -> &mut Self
pub fn look_at(&mut self, vector: &Vector3) -> &mut Self
BufferGeometry.lookAt() — rotates the geometry so its +Z points away
from vector, through a scratch Object3D exactly as three.js does.
Sourcepub fn to_non_indexed(&self) -> Self
pub fn to_non_indexed(&self) -> Self
BufferGeometry.toNonIndexed().
Trait Implementations§
Source§impl Clone for BufferGeometry
BufferGeometry.clone() — new this.constructor().copy( this ), whose
copy() clones every attribute and morph attribute through one shared
data object, so views of one InterleavedBuffer still share a single
(cloned) buffer afterwards rather than each de-interleaving. A fresh
GeometryId and fresh attribute ids, as for any clone.
impl Clone for BufferGeometry
BufferGeometry.clone() — new this.constructor().copy( this ), whose
copy() clones every attribute and morph attribute through one shared
data object, so views of one InterleavedBuffer still share a single
(cloned) buffer afterwards rather than each de-interleaving. A fresh
GeometryId and fresh attribute ids, as for any clone.