|
| 1 | +# H3DU.BufferAccessor |
| 2 | + |
| 3 | +[Back to documentation index.](index.md) |
| 4 | + |
| 5 | +<a name='H3DU.BufferAccessor'></a> |
| 6 | +### H3DU.BufferAccessor(buffer, offset, countPerValue, [stride]) |
| 7 | + |
| 8 | +A <b>vertex attribute object</b>. |
| 9 | + |
| 10 | +#### Parameters |
| 11 | + |
| 12 | +* `buffer` (Type: Float32Array)<br>A buffer to store vertex attribute data; see <a href="H3DU.BufferAccessor.md#H3DU.BufferAccessor_buffer">H3DU.BufferAccessor#buffer</a>. |
| 13 | +* `offset` (Type: number)<br>Offset to the first value; see <a href="H3DU.BufferAccessor.md#H3DU.BufferAccessor_offset">H3DU.BufferAccessor#offset</a>. Throws an error if less than 0. |
| 14 | +* `countPerValue` (Type: number)<br>Number of elements per value; see <a href="H3DU.BufferAccessor.md#H3DU.BufferAccessor_countPerValue">H3DU.BufferAccessor#countPerValue</a>. Throws an error if 0 or less. |
| 15 | +* `stride` (Type: number) (optional)<br>Number of elements from the start of one value to the start of the next; see <a href="H3DU.BufferAccessor.md#H3DU.BufferAccessor_stride">H3DU.BufferAccessor#stride</a>. If null, undefined, or omitted, has the same value as "countPerValue". Throws an error if 0 or less. |
| 16 | + |
| 17 | +### Members |
| 18 | + |
| 19 | +* [buffer](#H3DU.BufferAccessor_buffer)<br>A <i>buffer</i> of arbitrary size. |
| 20 | +* [countPerValue](#H3DU.BufferAccessor_countPerValue)<br>A count of the number of elements each value has. |
| 21 | +* [offset](#H3DU.BufferAccessor_offset)<br>An offset, which identifies the index, starting from 0, of the first value |
| 22 | +of the attribute within the buffer. |
| 23 | +* [stride](#H3DU.BufferAccessor_stride)<br>A stride, which gives the number of elements from the start of one |
| 24 | +value to the start of the next. |
| 25 | + |
| 26 | +### Methods |
| 27 | + |
| 28 | +* [copy](#H3DU.BufferAccessor_copy)<br>Copies the values of this accessor into a new vertex attribute object. |
| 29 | +* [count](#H3DU.BufferAccessor_count)<br>Gets the number of <a href="H3DU.BufferAccessor.md#H3DU.BufferAccessor_buffer">values</a> defined for this accessor. |
| 30 | +* [get](#H3DU.BufferAccessor_get)<br>Gets the first element of the attribute value with the given vertex index. |
| 31 | +* [getVec](#H3DU.BufferAccessor_getVec)<br>Gets the elements of a vertex attribute value. |
| 32 | +* [makeBlank](#H3DU.BufferAccessor.makeBlank)<br>Generates a vertex attribute buffer, with each value set to all zeros. |
| 33 | +* [set](#H3DU.BufferAccessor_set)<br>Sets the first element of the attribute value with the given vertex index. |
| 34 | +* [setVec](#H3DU.BufferAccessor_setVec)<br>Sets the elements of a vertex attribute value. |
| 35 | + |
| 36 | +<a name='H3DU.BufferAccessor_buffer'></a> |
| 37 | +### H3DU.BufferAccessor#buffer |
| 38 | + |
| 39 | +A <i>buffer</i> of arbitrary size. This buffer |
| 40 | +is made up of <i>values</i>, one for each vertex, and each value |
| 41 | +is takes up one or more <i>elements</i> in the buffer, which are numbers such |
| 42 | +as X coordinates or red components, depending on the attribute's semantic. |
| 43 | +Each value has the same number of elements. An example of a <i>value</i> |
| 44 | +is (10, 20, 5), which can take up three consecutive <i>elements</i> |
| 45 | +in a <code>Float32Array</code> buffer such as the one given in this |
| 46 | +property. |
| 47 | + |
| 48 | +Type: Float32Array |
| 49 | + |
| 50 | +<a name='H3DU.BufferAccessor_countPerValue'></a> |
| 51 | +### H3DU.BufferAccessor#countPerValue |
| 52 | + |
| 53 | +A count of the number of elements each value has. For example, 3-dimensional |
| 54 | +positions will have 3 elements, one for each coordinate. |
| 55 | + |
| 56 | +Type: number |
| 57 | + |
| 58 | +<a name='H3DU.BufferAccessor_offset'></a> |
| 59 | +### H3DU.BufferAccessor#offset |
| 60 | + |
| 61 | +An offset, which identifies the index, starting from 0, of the first value |
| 62 | +of the attribute within the buffer. The offset counts the number of |
| 63 | +elements in the buffer to the first value. For example, if this value is 6, |
| 64 | +then the first element of the first value in the buffer is found at |
| 65 | +<code>acc.buffer[acc.offset]</code> (assuming the buffer is |
| 66 | +more than 6 elements long). |
| 67 | + |
| 68 | +Type: number |
| 69 | + |
| 70 | +<a name='H3DU.BufferAccessor_stride'></a> |
| 71 | +### H3DU.BufferAccessor#stride |
| 72 | + |
| 73 | +A stride, which gives the number of elements from the start of one |
| 74 | +value to the start of the next. A "packed" buffer will have a stride |
| 75 | +equal to the <a href="H3DU.BufferAccessor.md#H3DU.BufferAccessor_countPerValue">count per value</a>. |
| 76 | + |
| 77 | +Type: number |
| 78 | + |
| 79 | +<a name='H3DU.BufferAccessor_copy'></a> |
| 80 | +### H3DU.BufferAccessor#copy() |
| 81 | + |
| 82 | +Copies the values of this accessor into a new vertex attribute object. |
| 83 | + |
| 84 | +#### Return Value |
| 85 | + |
| 86 | +A copy of the vertex attribute object. (Type: <a href="H3DU.BufferAccessor.md">H3DU.BufferAccessor</a>) |
| 87 | + |
| 88 | +<a name='H3DU.BufferAccessor_count'></a> |
| 89 | +### H3DU.BufferAccessor#count() |
| 90 | + |
| 91 | +Gets the number of <a href="H3DU.BufferAccessor.md#H3DU.BufferAccessor_buffer">values</a> defined for this accessor. |
| 92 | + |
| 93 | +#### Return Value |
| 94 | + |
| 95 | +The number of values defined in this accessor's buffer. (Type: number) |
| 96 | + |
| 97 | +<a name='H3DU.BufferAccessor_get'></a> |
| 98 | +### H3DU.BufferAccessor#get(index) |
| 99 | + |
| 100 | +Gets the first element of the attribute value with the given vertex index. |
| 101 | + |
| 102 | +Note that currently, this method does no bounds checking beyond the |
| 103 | +checking naturally done when accessing the attribute's buffer. |
| 104 | + |
| 105 | +#### Parameters |
| 106 | + |
| 107 | +* `index` (Type: number)<br>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. |
| 108 | + |
| 109 | +#### Return Value |
| 110 | + |
| 111 | +The first element of the given attribute value. (Type: number) |
| 112 | + |
| 113 | +<a name='H3DU.BufferAccessor_getVec'></a> |
| 114 | +### H3DU.BufferAccessor#getVec(index, vec) |
| 115 | + |
| 116 | +Gets the elements of a vertex attribute value. |
| 117 | + |
| 118 | +Note that currently, this method does no bounds checking beyond the |
| 119 | +checking naturally done when accessing the attribute's buffer. |
| 120 | + |
| 121 | +#### Parameters |
| 122 | + |
| 123 | +* `index` (Type: number)<br>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. |
| 124 | +* `vec` (Type: Array.<number>)<br>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 <a href="H3DU.BufferAccessor.md#H3DU.BufferAccessor_countPerValue">H3DU.BufferAccessor#countPerValue</a>). |
| 125 | + |
| 126 | +#### Return Value |
| 127 | + |
| 128 | +The parameter "vec". (Type: Array.<number>) |
| 129 | + |
| 130 | +<a name='H3DU.BufferAccessor.makeBlank'></a> |
| 131 | +### (static) H3DU.BufferAccessor.makeBlank(count, countPerValue) |
| 132 | + |
| 133 | +Generates a vertex attribute buffer, with each value set to all zeros. |
| 134 | + |
| 135 | +#### Parameters |
| 136 | + |
| 137 | +* `count` (Type: number)<br>The number of <a href="H3DU.BufferAccessor.md#H3DU.BufferAccessor_buffer">values</a> the buffer will hold. For example, (10, 20, 5) is a 3-element value. |
| 138 | +* `countPerValue` (Type: number)<br>The number of elements each value will take in the buffer. |
| 139 | + |
| 140 | +#### Return Value |
| 141 | + |
| 142 | +A blank vertex attribute buffer. (Type: <a href="H3DU.BufferAccessor.md">H3DU.BufferAccessor</a>) |
| 143 | + |
| 144 | +<a name='H3DU.BufferAccessor_set'></a> |
| 145 | +### H3DU.BufferAccessor#set(index, value) |
| 146 | + |
| 147 | +Sets the first element of the attribute value with the given vertex index. |
| 148 | + |
| 149 | +Note that currently, this method does no bounds checking beyond the |
| 150 | +checking naturally done when writing to the attribute's buffer. |
| 151 | + |
| 152 | +#### Parameters |
| 153 | + |
| 154 | +* `index` (Type: number)<br>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. |
| 155 | +* `value` (Type: number)<br>The number to set the first element to. |
| 156 | + |
| 157 | +#### Return Value |
| 158 | + |
| 159 | +This object. (Type: <a href="H3DU.BufferAccessor.md">H3DU.BufferAccessor</a>) |
| 160 | + |
| 161 | +<a name='H3DU.BufferAccessor_setVec'></a> |
| 162 | +### H3DU.BufferAccessor#setVec(index, vec) |
| 163 | + |
| 164 | +Sets the elements of a vertex attribute value. |
| 165 | + |
| 166 | +Note that currently, this method does no bounds checking beyond the |
| 167 | +checking naturally done when writing to the attribute's buffer, except |
| 168 | +where noted otherwise. |
| 169 | + |
| 170 | +#### Parameters |
| 171 | + |
| 172 | +* `index` (Type: number)<br>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. |
| 173 | +* `vec` (Type: Array.<number>)<br>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 <a href="H3DU.BufferAccessor.md#H3DU.BufferAccessor_countPerValue">H3DU.BufferAccessor#countPerValue</a>), whichever is less. |
| 174 | + |
| 175 | +#### Return Value |
| 176 | + |
| 177 | +This object. (Type: <a href="H3DU.BufferAccessor.md">H3DU.BufferAccessor</a>) |
| 178 | + |
| 179 | +[Back to documentation index.](index.md) |
0 commit comments