H3DU.BufferAccessor
### new H3DU.BufferAccessor(buffer, countPerValue, [offset], [stride])
A vertex attribute object.
Parameters
buffer
(Type: Float32Array)
A buffer to store vertex attribute data; see BufferAccessor#buffer.countPerValue
(Type: number)
Number of elements per value; see BufferAccessor#countPerValue. Throws an error if 0 or less.offset
(Type: number) (optional)
Offset to the first value; see BufferAccessor#offset. If null, undefined, or omitted, the default is 0. Throws an error if less than 0.stride
(Type: number) (optional)
Number of elements from the start of one value to the start of the next; see BufferAccessor#stride. If null, undefined, or omitted, has the same value as “countPerValue”. Throws an error if 0 or less.
Members
- buffer
A buffer of arbitrary size. - countPerValue
A count of the number of elements each value has. - offset
An offset, which identifies the index, starting from 0, of the first value of the attribute within the buffer. - stride
A stride, which gives the number of elements from the start of one value to the start of the next.
Methods
- copy
Copies the values of this accessor into a new vertex attribute object. - count
Gets the number of values defined for this accessor. - get
Gets the first element of the attribute value with the given vertex index. - getVec
Gets the elements of a vertex attribute value. - makeBlank
Generates a vertex attribute buffer, with each value set to all zeros. - makeIndices
Generates an array of increasing vertex indices. - merge
Merges two vertex attributes, whose vertices can be indexed differently, into one combined vertex attribute. - set
Sets the first element of the attribute value with the given vertex index. - setVec
Sets the elements of a vertex attribute value.
### H3DU.BufferAccessor#buffer
A buffer of arbitrary size. This buffer
is made up of values, one for each vertex, and each value
takes up one or more elements in the buffer, which are numbers such
as X coordinates or red components, depending on the attribute’s semantic.
Each value has the same number of elements. An example of a value
is (10, 20, 5), which can take up three consecutive elements
in a Float32Array
buffer such as the one given in this
property.
Type: Float32Array
### H3DU.BufferAccessor#countPerValue
A count of the number of elements each value has. For example, 3-dimensional positions will have 3 elements, one for each coordinate.
Type: number
### H3DU.BufferAccessor#offset
An offset, which identifies the index, starting from 0, of the first value
of the attribute within the buffer. The offset counts the number of
elements in the buffer to the first value. For example, if this property is 6,
then the first element of the first value in the buffer is found at
acc.buffer[acc.offset]
(assuming the buffer is
more than 6 elements long).
Type: number
### H3DU.BufferAccessor#stride
A stride, which gives the number of elements from the start of one value to the start of the next. A “packed” buffer will have a stride equal to the count per value.
Type: number
### H3DU.BufferAccessor#copy()
Copies the values of this accessor into a new vertex attribute object.
Return Value
A copy of the vertex attribute object. (Type: BufferAccessor)
### H3DU.BufferAccessor#count()
Gets the number of values defined for this accessor.
Return Value
The number of values defined in this accessor’s buffer. (Type: number)
### H3DU.BufferAccessor#get(index)
Gets the first element of the attribute value with the given vertex index.
Note that currently, this method does no bounds checking beyond the checking naturally done when accessing the attribute’s buffer.
Parameters
index
(Type: number)
A numeric index, starting from 0, that identifies a value stored in the attribute’s buffer. For example, 0 identifies the first value, 1 identifies the second, and so on.
Return Value
The first element of the given attribute value. (Type: number)
### H3DU.BufferAccessor#getVec(index, vec)
Gets the elements of a vertex attribute value.
Note that currently, this method does no bounds checking beyond the checking naturally done when accessing the attribute’s buffer.
Parameters
index
(Type: number)
A numeric index, starting from 0, that identifies a value stored in the attribute’s buffer. For example, 0 identifies the first value, 1 identifies the second, and so on.vec
(Type: Array.<number>)
An array whose elements will be set to those of the value at the given index. The number of elements copied to this array is the attribute’s count per value (see BufferAccessor#countPerValue).
Return Value
The parameter “vec”. (Type: Array.<number>)
### (static) H3DU.BufferAccessor.makeBlank(count, countPerValue)
Generates a vertex attribute buffer, with each value set to all zeros.
Parameters
count
(Type: number)
The number of values the buffer will hold. For example, (10, 20, 5) is a 3-element value.countPerValue
(Type: number)
The number of elements each value will take in the buffer.
Return Value
A blank vertex attribute buffer. (Type: BufferAccessor)
### (static) H3DU.BufferAccessor.makeIndices(numIndices)
Generates an array of increasing vertex indices.
Parameters
numIndices
(Type: number)
The number of vertex indices to generate. The array will range from 0 to the number of vertex indices minus 1.
Return Value
An array of vertex indices. (Type: Uint16Array | Uint32Array) |
### (static) H3DU.BufferAccessor.merge(attr1, indices1, attr2, indices2)
Merges two vertex attributes, whose vertices can be indexed differently, into one combined vertex attribute.
Parameters
attr1
(Type: BufferAccessor)
A vertex buffer accessor for the first vertex attribute. Can be null, in which case it is assumed that the attribute contains as many values as the length of “indices1” and all the values are zeros.-
indices1
(Type: Array.<number>Uint16Array Uint8Array Uint32Array)
An array of vertex indices associated with the first vertex attribute. attr2
(Type: BufferAccessor)
A vertex buffer accessor for the second vertex attribute. Can be null, in which case it is assumed that the attribute contains as many values as the length of “indices2” and all the values are zeros.-
indices2
(Type: Array.<number>Uint16Array Uint8Array Uint32Array)
An array of vertex indices associated with the second vertex attribute.
Return Value
The merged attribute, where the vertices from the first vertex attribute come before those from the second. The merged attribute will have as many values as the sum of the lengths of “indices1” and “indices2”. (Type: BufferAccessor)
### H3DU.BufferAccessor#set(index, value)
Sets the first element of the attribute value with the given vertex index.
Note that currently, this method does no bounds checking beyond the checking naturally done when writing to the attribute’s buffer.
Parameters
index
(Type: number)
A numeric index, starting from 0, that identifies a value stored in the attribute’s buffer. For example, 0 identifies the first value, 1 identifies the second, and so on.value
(Type: number)
The number to set the first element to.
Return Value
This object. (Type: BufferAccessor)
### H3DU.BufferAccessor#setVec(index, vec)
Sets the elements of a vertex attribute value.
Note that currently, this method does no bounds checking beyond the checking naturally done when writing to the attribute’s buffer, except where noted otherwise.
Parameters
index
(Type: number)
A numeric index, starting from 0, that identifies a value stored in the attribute’s buffer. For example, 0 identifies the first value, 1 identifies the second, and so on.vec
(Type: Array.<number>)
An array containing the elements to copy to the value at the given index. The number of elements copied is this array’s length or the attribute’s count per value (see BufferAccessor#countPerValue), whichever is less.
Return Value
This object. (Type: BufferAccessor)