BufferAttribute

This class stores data for an attribute (such as vertex positions, face indices, normals, colors, UVs, and any custom attributes ) associated with a BufferGeometry, which allows for more efficient passing of data to the GPU. See that page for details and a usage example. Data is stored as vectors of any length (defined by itemSize), and in general in the methods outlined below if passing in an index, this is automatically multiplied by the vector length.

Core Class

This class stores data for an attribute (such as vertex positions, face indices, normals, colors, UVs, and any custom attributes ) associated with a BufferGeometry, which allows for more efficient passing of data to the GPU. See that page for details and a usage example.

Data is stored as vectors of any length (defined by itemSize), and in general in the methods outlined below if passing in an index, this is automatically multiplied by the vector length.

Extends

  • ElementEventDispatcher

Extended by

Type Parameters

T

T extends TypedArray = TypedArray

Constructors

Constructor

new BufferAttribute<T>(array, itemSize): BufferAttribute<T>

Parameters

array

T

itemSize

number

Returns

BufferAttribute<T>

Overrides

ElementEventDispatcher.constructor

Properties

_array

_array: T

The geometry attribute data store as TypedArray.


itemSize

itemSize: number

If the buffer is storing a 3-component vector (such as a position, normal, or color), then this will count the number of such vectors stored.


normalized

normalized: boolean

If attribute data is normalized.


count

count: number

Stores the array’s length divided by the itemSize.

If the buffer is storing a 3-component vector (such as a position, normal, or color), then this will count the number of such vectors stored.


dynamic

dynamic: boolean

The data of this buffer always need update.

Deprecated

will not take effect, update attribute.array if need to reupload


updateRange

updateRange: object

Object containing:
offset:Integer - Default is 0. Position at which to start update.
count:Integer - Default is -1, which means don’t use update ranges.

This can be used to only update some components of stored vectors (for example, just the component related to color).

offset

offset: number

count

count: number

Deprecated

will not take effect, update attribute.array instead


isBufferAttribute

isBufferAttribute: boolean

Used to check type of this or extended instance. This value should not be changed by user.


isDataDropped

isDataDropped: boolean

When the data is cleared from memory, this mark will be set true.

Deprecated

never updated, always false.


removeDataAfterUpload

removeDataAfterUpload: boolean

Remove the data after it is uploaded to GPU memory.

Deprecated

will not take effect


version

version: number

A version number, incremented every time the needsUpdate property is set to true.


onUpdateCallback

onUpdateCallback: () => void

A callback function for updating. It will be called after needsUpdate.

Returns

void


onUploadCallback

onUploadCallback: () => void

A callback function for uploading. It will be called after the data uploaded to WebGL.

Returns

void


userData

readonly userData: Record<keyof any, any>

Inherited from

ElementEventDispatcher.userData


_uuid

_uuid: any

Inherited from

ElementEventDispatcher._uuid


uuid

uuid: string

Inherited from

ElementEventDispatcher.uuid


_listeners

_listeners: Map<Symbol, Listener<never>[]>

Inherited from

ElementEventDispatcher._listeners

Accessors

array

Get Signature

get array(): T

The geometry attribute data store as TypedArray.

Returns

T

Set Signature

set array(v): void

Parameters
v

T

Returns

void


needsUpdate

Set Signature

set needsUpdate(value): void

When this attribute is set to true, the version will be change.

Parameters
value

boolean

Returns

void


businessTag

Get Signature

get businessTag(): string

Returns

string

Set Signature

set businessTag(v): void

Parameters
v

string

Returns

void

Inherited from

ElementEventDispatcher.businessTag

Methods

notifyContentChange()

notifyContentChange(): void

Returns

void


setArray()

setArray(array): this

Change the data of array.

Parameters

array

T

Returns

this


setDynamic()

setDynamic(value): this

Change the state of dynamic.

Parameters

value

boolean

Returns

this


copy()

copy(source): this

Copy the data to this object from source.

Parameters

source

BufferAttribute

the data source.

Returns

this


copyAt()

copyAt(index1, attribute, index2): this

Copy the data at specified position. The given index is items’ index, do not need to multiply with item’ size.

Parameters

index1

number

the start position of this array.

attribute

BufferAttribute

the start position of this array.

index2

number

the start position of source array.

Returns

this


copyArray()

copyArray(array): this

Copy the data from given array to this array.

Parameters

array

TypedArray | number[]

the start position of this array.

Returns

this


copyColorArray()

copyColorArray(colors): this

Copy the data from given array to this array.

Parameters

colors

Color[]

the start position of this array.

Returns

this


copyVector2Array()

copyVector2Array(vectors): this

Copy the data which is type of Vector2 from given array to this array.

Parameters

vectors

Vector2[]

the start position of this array.

Returns

this


copyVector3Array()

copyVector3Array(vectors): this

Copy the data which is type of Vector3 from given array to this array.

Parameters

vectors

Vector3[]

the start position of this array.

Returns

this


copyVector4Array()

copyVector4Array(vectors): this

Copy the data which is type of Vector4 from given array to this array.

Parameters

vectors

Vector4[]

the start position of this array.

Returns

this


set()

set(value, offset?): this

Copy the data from given Array or typedArray.

Parameters

value

ArrayLike<number>

an Array or TypedArray from which to copy values.

offset?

number

(optional) index of the array at which to start copying.

Returns

this


getX()

getX(index): number

Return the x component of all items.

Parameters

index

number

Returns

number


setX()

setX(index, x): this

Set the x component of the vector at the given index.

Parameters

index

number

x

number

Returns

this


getY()

getY(index): number

Return the y component of all vectors.

Parameters

index

number

Returns

number


setY()

setY(index, y): this

Set the y component of the vector at the given index.

Parameters

index

number

y

number

Returns

this


getZ()

getZ(index): number

Return the z component of all vectors.

Parameters

index

number

Returns

number


setZ()

setZ(index, z): this

Set the z component of the vector at the given index.

Parameters

index

number

z

number

Returns

this


getW()

getW(index): number

Return the w component of all vectors.

Parameters

index

number

Returns

number


setW()

setW(index, w): this

Set the w component of the vector at the given index.

Parameters

index

number

w

number

Returns

this


setXY()

setXY(index, x, y): this

Set the x and y component of the vector at the given index.

Parameters

index

number

x

number

y

number

Returns

this


setXYZ()

setXYZ(index, x, y, z): this

Set the x , y and z component of the vector at the given index.

Parameters

index

number

x

number

y

number

z

number

Returns

this


setXYZW()

setXYZW(index, x, y, z, w): this

Set all component of the vector at the given index.

Parameters

index

number

x

number

y

number

z

number

w

number

Returns

this


getVector2()

getVector2(index, out?): Vector2

Return the vector2 at specific position.

Parameters

index

number

out?

Vector2

Returns

Vector2


clone()

clone(): BufferAttribute<T>

Return a clone of this object.

Returns

BufferAttribute<T>


destroy()

destroy(): void

Release the memory which is occupied by this instance from CPU and GPU.

Returns

void

Overrides

ElementEventDispatcher.destroy


freeGPU()

freeGPU(): void

Returns

void


markBusinessTag()

markBusinessTag(v): this

Parameters

v

string

Returns

this

Inherited from

ElementEventDispatcher.markBusinessTag


isDestroyed()

isDestroyed(): boolean

Returns

boolean

Inherited from

ElementEventDispatcher.isDestroyed


validate()

validate(): void

Returns

void

Inherited from

ElementEventDispatcher.validate


destroyAllResourcesOwned()

destroyAllResourcesOwned(): void

Returns

void

Inherited from

ElementEventDispatcher.destroyAllResourcesOwned


freeAllGpuResourceOwned()

freeAllGpuResourceOwned(): void

Returns

void

Inherited from

ElementEventDispatcher.freeAllGpuResourceOwned


on()

on<T>(_type, _listener): void

Adds a listener to an event type.

Type Parameters

T

T

Parameters

_type

EventType<T>

_listener

Listener<T>

Returns

void

Inherited from

ElementEventDispatcher.on


once()

once<T>(_type, _listener): void

Only active the listener one times and then off it| it.

Type Parameters

T

T

Parameters

_type

EventType<T>

_listener

Listener<T>

Returns

void

Inherited from

ElementEventDispatcher.once


has()

has<T>(_type, _listener): boolean

Checks if listener is added to an event type.

Type Parameters

T

T

Parameters

_type

EventType<T>

_listener

Listener<T>

Returns

boolean

Inherited from

ElementEventDispatcher.has


off()

off<T>(_type, _listener): void

Removes a listener from listening list.

Type Parameters

T

T

Parameters

_type

EventType<T>

_listener

Listener<T>

Returns

void

Inherited from

ElementEventDispatcher.off


emit()

Call Signature

emit(type): void

Active the event and call the registered listener.

Parameters
type

EventType<never>

Returns

void

Inherited from

ElementEventDispatcher.emit

Call Signature

emit<T>(type, payload): void

Type Parameters
T

T

Parameters
type

EventType<T>

payload

T

Returns

void

Inherited from

ElementEventDispatcher.emit


clearAllListeners()

clearAllListeners(): void

Removes all listeners from listening list.

Returns

void

Inherited from

ElementEventDispatcher.clearAllListeners