Skip to main content

BufferGeometry

Struct BufferGeometry 

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

BufferGeometry.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: bool

BufferGeometry.morphTargetsRelative.

§groups: Vec<Group>

BufferGeometry.groups.

§draw_range: DrawRange

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

Source

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.

Source

pub fn new() -> Self

new BufferGeometry().

Source

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.

Source

pub fn indirect(&self) -> Option<&IndirectStorageBufferAttribute>

geometry.indirect.

Source

pub fn id(&self) -> usize

BufferGeometry.id — the renderer’s cache key for this geometry’s uploaded buffers.

Source

pub fn get_attribute(&self, name: &str) -> Option<&BufferAttribute>

BufferGeometry.getAttribute( name ).

Source

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.

Source

pub fn set_attribute( &mut self, name: &str, attribute: BufferAttribute, ) -> &mut Self

BufferGeometry.setAttribute( name, attribute ).

Source

pub fn delete_attribute(&mut self, name: &str) -> &mut Self

BufferGeometry.deleteAttribute( name ).

Source

pub fn has_attribute(&self, name: &str) -> bool

BufferGeometry.hasAttribute( name ).

Source

pub fn attributes(&self) -> impl Iterator<Item = (&str, &BufferAttribute)>

for ( const name in geometry.attributes ), in insertion order.

Source

pub fn position(&self) -> Option<&BufferAttribute>

geometry.attributes.position.

Source

pub fn normal(&self) -> Option<&BufferAttribute>

geometry.attributes.normal.

Source

pub fn uv(&self) -> Option<&BufferAttribute>

geometry.attributes.uv.

Source

pub fn get_morph_attribute(&self, name: &str) -> Option<&[BufferAttribute]>

geometry.morphAttributes[ name ].

Source

pub fn set_morph_attribute( &mut self, name: &str, attributes: Vec<BufferAttribute>, ) -> &mut Self

geometry.morphAttributes[ name ] = attributes.

Source

pub fn morph_attributes( &self, ) -> impl Iterator<Item = (&str, &[BufferAttribute])>

for ( const name in geometry.morphAttributes ), in insertion order.

Source

pub fn add_group(&mut self, start: usize, count: usize, material_index: usize)

BufferGeometry.addGroup( start, count, materialIndex ).

Source

pub fn clear_groups(&mut self)

BufferGeometry.clearGroups().

Source

pub fn set_draw_range(&mut self, start: usize, count: usize)

BufferGeometry.setDrawRange( start, count ).

Source

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.

Source

pub fn set_index(&mut self, indices: &[u32])

BufferGeometry.setIndex( array ) — picks Uint16 when it fits, the same rule three.js uses.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn normalize_normals(&mut self)

BufferGeometry.normalizeNormals().

Source

pub fn apply_matrix4(&mut self, matrix: &Matrix4) -> &mut Self

BufferGeometry.applyMatrix4().

Source

pub fn scale(&mut self, x: f64, y: f64, z: f64) -> &mut Self

BufferGeometry.scale().

Source

pub fn apply_quaternion(&mut self, q: &Quaternion) -> &mut Self

BufferGeometry.applyQuaternion().

Source

pub fn rotate_x(&mut self, angle: f64) -> &mut Self

BufferGeometry.rotateX() — rotates the geometry about the world x-axis.

Source

pub fn rotate_y(&mut self, angle: f64) -> &mut Self

BufferGeometry.rotateY().

Source

pub fn rotate_z(&mut self, angle: f64) -> &mut Self

BufferGeometry.rotateZ().

Source

pub fn translate(&mut self, x: f64, y: f64, z: f64) -> &mut Self

BufferGeometry.translate().

Source

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.

Source

pub fn center(&mut self) -> &mut Self

BufferGeometry.center().

Source

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.

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
Source§

impl Debug for BufferGeometry

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for BufferGeometry

Source§

fn default() -> Self

Returns the “default value” for a type. 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.