pub struct BufferAttribute {
pub id: AttributeId,
pub item_size: usize,
pub normalized: bool,
/* private fields */
}Expand description
three.js’ BufferAttribute, its typed subclasses (Uint8BufferAttribute,
…, Float16BufferAttribute), InstancedBufferAttribute and
InterleavedBufferAttribute: one named vertex attribute, item_size
values per vertex. See the module docs for the shape.
Fields§
§id: AttributeIdBufferAttribute.id. Read-only in spirit; see AttributeId.
item_size: usizeBufferAttribute.itemSize — the number of values per vertex.
normalized: boolBufferAttribute.normalized — integer data read as 0..1 (or
-1..1) floats, by the GPU and by the get_*/set_* accessors.
Implementations§
Source§impl BufferAttribute
impl BufferAttribute
Sourcepub fn new(array: Vec<f32>, item_size: usize) -> Self
pub fn new(array: Vec<f32>, item_size: usize) -> Self
new BufferAttribute( array, itemSize ) over a Float32Array —
Float32BufferAttribute, three’s default.
Sourcepub fn from_typed(array: TypedArray, item_size: usize, normalized: bool) -> Self
pub fn from_typed(array: TypedArray, item_size: usize, normalized: bool) -> Self
new BufferAttribute( array, itemSize, normalized ) — the base
constructor every typed one calls.
Sourcepub fn int8(array: Vec<i8>, item_size: usize, normalized: bool) -> Self
pub fn int8(array: Vec<i8>, item_size: usize, normalized: bool) -> Self
new Int8BufferAttribute( array, itemSize, normalized ).
Sourcepub fn uint8(array: Vec<u8>, item_size: usize, normalized: bool) -> Self
pub fn uint8(array: Vec<u8>, item_size: usize, normalized: bool) -> Self
new Uint8BufferAttribute( array, itemSize, normalized ).
Sourcepub fn uint8_clamped(array: Vec<u8>, item_size: usize, normalized: bool) -> Self
pub fn uint8_clamped(array: Vec<u8>, item_size: usize, normalized: bool) -> Self
new Uint8ClampedBufferAttribute( array, itemSize, normalized ).
Sourcepub fn int16(array: Vec<i16>, item_size: usize, normalized: bool) -> Self
pub fn int16(array: Vec<i16>, item_size: usize, normalized: bool) -> Self
new Int16BufferAttribute( array, itemSize, normalized ).
Sourcepub fn uint16(array: Vec<u16>, item_size: usize, normalized: bool) -> Self
pub fn uint16(array: Vec<u16>, item_size: usize, normalized: bool) -> Self
new Uint16BufferAttribute( array, itemSize, normalized ).
Sourcepub fn int32(array: Vec<i32>, item_size: usize, normalized: bool) -> Self
pub fn int32(array: Vec<i32>, item_size: usize, normalized: bool) -> Self
new Int32BufferAttribute( array, itemSize, normalized ).
Sourcepub fn uint32(array: Vec<u32>, item_size: usize, normalized: bool) -> Self
pub fn uint32(array: Vec<u32>, item_size: usize, normalized: bool) -> Self
new Uint32BufferAttribute( array, itemSize, normalized ).
Sourcepub fn float16(array: Vec<u16>, item_size: usize, normalized: bool) -> Self
pub fn float16(array: Vec<u16>, item_size: usize, normalized: bool) -> Self
new Float16BufferAttribute( array, itemSize, normalized ) — array
is binary16 bits, as three’s Uint16Array is. Build it from floats
with to_half_float, or with set_x and friends,
which convert.
Sourcepub fn new_instanced(array: Vec<f32>, item_size: usize) -> Self
pub fn new_instanced(array: Vec<f32>, item_size: usize) -> Self
new InstancedBufferAttribute( array, itemSize ) — one element per
instance. See is_instanced.
Sourcepub fn from_typed_instanced(
array: TypedArray,
item_size: usize,
normalized: bool,
) -> Self
pub fn from_typed_instanced( array: TypedArray, item_size: usize, normalized: bool, ) -> Self
new InstancedBufferAttribute( array, itemSize, normalized ) over any
typed array.
Sourcepub fn interleaved(
data: Rc<InterleavedBuffer>,
item_size: usize,
offset: usize,
normalized: bool,
) -> Self
pub fn interleaved( data: Rc<InterleavedBuffer>, item_size: usize, offset: usize, normalized: bool, ) -> Self
new InterleavedBufferAttribute( interleavedBuffer, itemSize, offset, normalized ) — a view of item_size elements, offset elements into
each of data’s strides.
Sourcepub fn is_instanced(&self) -> bool
pub fn is_instanced(&self) -> bool
attribute.isInstancedBufferAttribute, or for an interleaved view
attribute.data.isInstancedInterleavedBuffer.
Sourcepub fn is_interleaved(&self) -> bool
pub fn is_interleaved(&self) -> bool
attribute.isInterleavedBufferAttribute.
Sourcepub fn data_buffer(&self) -> Option<&Rc<InterleavedBuffer>>
pub fn data_buffer(&self) -> Option<&Rc<InterleavedBuffer>>
InterleavedBufferAttribute.data — None for an attribute with its
own array.
Sourcepub fn offset(&self) -> usize
pub fn offset(&self) -> usize
InterleavedBufferAttribute.offset, in elements (0 for an attribute
with its own array).
Sourcepub fn array(&self) -> Ref<'_, Vec<f32>>
pub fn array(&self) -> Ref<'_, Vec<f32>>
attribute.array as the Float32Array it usually is, for reading. A
Ref, so the borrow has to be held for as long as the slice is used.
On an interleaved view it is the whole shared array, as three’s
InterleavedBufferAttribute.array getter returns.
§Panics
If the array is another kind (Uint8Array, …); read it with
data.
Sourcepub fn array_mut(&self) -> RefMut<'_, Vec<f32>>
pub fn array_mut(&self) -> RefMut<'_, Vec<f32>>
attribute.array, for writing — through a shared &self, so it works
on an attribute of a geometry already handed to a mesh as an Rc.
Writing alone changes nothing on screen: follow it with
set_needs_update, exactly as three.js needs
attribute.needsUpdate = true.
§Panics
As array.
Sourcepub fn data(&self) -> Ref<'_, TypedArray>
pub fn data(&self) -> Ref<'_, TypedArray>
attribute.array, whatever its kind.
Sourcepub fn data_mut(&self) -> RefMut<'_, TypedArray>
pub fn data_mut(&self) -> RefMut<'_, TypedArray>
data, for writing.
Sourcepub fn set_needs_update(&self)
pub fn set_needs_update(&self)
attribute.needsUpdate = true — version ++. The next render that
sees this geometry re-writes this attribute’s GPU buffer (an
interleaved view’s buffer, shared by all its views), and only it.
Sourcepub fn count(&self) -> usize
pub fn count(&self) -> usize
BufferAttribute.count — the number of vertices, array.length / item_size (data.count for an interleaved view).
Sourcepub fn get_component(&self, index: usize, component: usize) -> f64
pub fn get_component(&self, index: usize, component: usize) -> f64
BufferAttribute.getComponent( index, component ) and the shared body
of getX..getW: the element widened to f64, fromHalfFloat on a
Float16BufferAttribute, denormalized when normalized.
Sourcepub fn set_component(
&mut self,
index: usize,
component: usize,
value: f64,
) -> &mut Self
pub fn set_component( &mut self, index: usize, component: usize, value: f64, ) -> &mut Self
BufferAttribute.setComponent( index, component, value ) and the
shared body of setX..setXYZW: normalized when normalized,
toHalfFloat on a Float16BufferAttribute, then stored with the
typed array’s conversion.
Sourcepub fn set_xyz(&mut self, index: usize, x: f64, y: f64, z: f64)
pub fn set_xyz(&mut self, index: usize, x: f64, y: f64, z: f64)
BufferAttribute.setXYZ() — narrows on the way in, which is where
three.js loses precision too.
Sourcepub fn set_xyzw(
&mut self,
index: usize,
x: f64,
y: f64,
z: f64,
w: f64,
) -> &mut Self
pub fn set_xyzw( &mut self, index: usize, x: f64, y: f64, z: f64, w: f64, ) -> &mut Self
BufferAttribute.setXYZW().
Sourcepub fn copy_at(
&mut self,
index1: usize,
attribute: &Self,
index2: usize,
) -> &mut Self
pub fn copy_at( &mut self, index1: usize, attribute: &Self, index2: usize, ) -> &mut Self
BufferAttribute.copyAt() — copies one item’s raw elements from
attribute (no normalization; the store’s conversion if the kinds
differ).
Sourcepub fn copy_array(&mut self, array: &[f32]) -> &mut Self
pub fn copy_array(&mut self, array: &[f32]) -> &mut Self
BufferAttribute.copyArray() — this.array.set( array ): array
over the start of the attribute’s array, element by element with the
store’s conversion. A shorter array leaves the rest as it was.
§Panics
If array is longer than the attribute’s array — TypedArray.set()’s
RangeError.
Sourcepub fn set(&mut self, value: &[f32], offset: usize) -> &mut Self
pub fn set(&mut self, value: &[f32], offset: usize) -> &mut Self
BufferAttribute.set( value, offset ) — raw elements, with the store’s
conversion (so on a Float16BufferAttribute the values are bits, as in
three).
Sourcepub fn copy(&mut self, source: &BufferAttribute) -> &mut Self
pub fn copy(&mut self, source: &BufferAttribute) -> &mut Self
BufferAttribute.copy( source ) — array (copied), item size and
normalized; not the id, not the version. An interleaved view copies
its buffer reference and offset (InterleavedBufferAttribute has no
copy, so this is what BufferAttribute.copy would leave it).
Sourcepub fn get_vector3(&self, index: usize) -> Vector3
pub fn get_vector3(&self, index: usize) -> Vector3
Vector3.fromBufferAttribute( attribute, index ).
Sourcepub fn apply_matrix4(&mut self, m: &Matrix4)
pub fn apply_matrix4(&mut self, m: &Matrix4)
BufferAttribute.applyMatrix4().
Sourcepub fn apply_normal_matrix(&mut self, m: &Matrix3)
pub fn apply_normal_matrix(&mut self, m: &Matrix3)
BufferAttribute.applyNormalMatrix().
Trait Implementations§
Source§impl Clone for BufferAttribute
BufferAttribute.clone() — new this.constructor( this.array, this.itemSize ).copy( this ): a fresh id, version 0, a copy of the array.
impl Clone for BufferAttribute
BufferAttribute.clone() — new this.constructor( this.array, this.itemSize ).copy( this ): a fresh id, version 0, a copy of the array.
An interleaved view is three’s InterleavedBufferAttribute.clone() with no
data argument, which de-interleaves: the clone is a plain attribute
of the same kind holding just this view’s items (three logs a warning; so
does nothing here). Clone a whole geometry to keep the interleaving — see
BufferGeometry’s Clone. A storage attribute’s clone is a new storage
attribute (a new GPU buffer) with a copy of the initial contents.