Skip to main content

BufferAttribute

Struct BufferAttribute 

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

BufferAttribute.id. Read-only in spirit; see AttributeId.

§item_size: usize

BufferAttribute.itemSize — the number of values per vertex.

§normalized: bool

BufferAttribute.normalized — integer data read as 0..1 (or -1..1) floats, by the GPU and by the get_*/set_* accessors.

Implementations§

Source§

impl BufferAttribute

Source

pub fn new(array: Vec<f32>, item_size: usize) -> Self

new BufferAttribute( array, itemSize ) over a Float32Array — Float32BufferAttribute, three’s default.

Source

pub fn from_typed(array: TypedArray, item_size: usize, normalized: bool) -> Self

new BufferAttribute( array, itemSize, normalized ) — the base constructor every typed one calls.

Source

pub fn int8(array: Vec<i8>, item_size: usize, normalized: bool) -> Self

new Int8BufferAttribute( array, itemSize, normalized ).

Source

pub fn uint8(array: Vec<u8>, item_size: usize, normalized: bool) -> Self

new Uint8BufferAttribute( array, itemSize, normalized ).

Source

pub fn uint8_clamped(array: Vec<u8>, item_size: usize, normalized: bool) -> Self

new Uint8ClampedBufferAttribute( array, itemSize, normalized ).

Source

pub fn int16(array: Vec<i16>, item_size: usize, normalized: bool) -> Self

new Int16BufferAttribute( array, itemSize, normalized ).

Source

pub fn uint16(array: Vec<u16>, item_size: usize, normalized: bool) -> Self

new Uint16BufferAttribute( array, itemSize, normalized ).

Source

pub fn int32(array: Vec<i32>, item_size: usize, normalized: bool) -> Self

new Int32BufferAttribute( array, itemSize, normalized ).

Source

pub fn uint32(array: Vec<u32>, item_size: usize, normalized: bool) -> Self

new Uint32BufferAttribute( array, itemSize, normalized ).

Source

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.

Source

pub fn new_instanced(array: Vec<f32>, item_size: usize) -> Self

new InstancedBufferAttribute( array, itemSize ) — one element per instance. See is_instanced.

Source

pub fn from_typed_instanced( array: TypedArray, item_size: usize, normalized: bool, ) -> Self

new InstancedBufferAttribute( array, itemSize, normalized ) over any typed array.

Source

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.

Source

pub fn is_instanced(&self) -> bool

attribute.isInstancedBufferAttribute, or for an interleaved view attribute.data.isInstancedInterleavedBuffer.

Source

pub fn is_interleaved(&self) -> bool

attribute.isInterleavedBufferAttribute.

Source

pub fn data_buffer(&self) -> Option<&Rc<InterleavedBuffer>>

InterleavedBufferAttribute.data — None for an attribute with its own array.

Source

pub fn offset(&self) -> usize

InterleavedBufferAttribute.offset, in elements (0 for an attribute with its own array).

Source

pub fn kind(&self) -> ArrayKind

The element type.

Source

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.

Source

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.

Source

pub fn data(&self) -> Ref<'_, TypedArray>

attribute.array, whatever its kind.

Source

pub fn data_mut(&self) -> RefMut<'_, TypedArray>

data, for writing.

Source

pub fn version(&self) -> u32

BufferAttribute.version (an interleaved view’s is its buffer’s).

Source

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.

Source

pub fn count(&self) -> usize

BufferAttribute.count — the number of vertices, array.length / item_size (data.count for an interleaved view).

Source

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.

Source

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.

Source

pub fn get_x(&self, index: usize) -> f64

BufferAttribute.getX().

Source

pub fn get_y(&self, index: usize) -> f64

BufferAttribute.getY().

Source

pub fn get_z(&self, index: usize) -> f64

BufferAttribute.getZ().

Source

pub fn get_w(&self, index: usize) -> f64

BufferAttribute.getW().

Source

pub fn set_x(&mut self, index: usize, x: f64) -> &mut Self

BufferAttribute.setX().

Source

pub fn set_y(&mut self, index: usize, y: f64) -> &mut Self

BufferAttribute.setY().

Source

pub fn set_z(&mut self, index: usize, z: f64) -> &mut Self

BufferAttribute.setZ().

Source

pub fn set_w(&mut self, index: usize, w: f64) -> &mut Self

BufferAttribute.setW().

Source

pub fn set_xy(&mut self, index: usize, x: f64, y: f64) -> &mut Self

BufferAttribute.setXY().

Source

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.

Source

pub fn set_xyzw( &mut self, index: usize, x: f64, y: f64, z: f64, w: f64, ) -> &mut Self

BufferAttribute.setXYZW().

Source

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

Source

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.

Source

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

Source

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

Source

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

Vector3.fromBufferAttribute( attribute, index ).

Source

pub fn apply_matrix4(&mut self, m: &Matrix4)

BufferAttribute.applyMatrix4().

Source

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.

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.

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 BufferAttribute

Source§

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

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

impl From<StorageBufferAttribute> for BufferAttribute

Source§

fn from(storage: StorageBufferAttribute) -> Self

Converts to this type from the input type.

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.