Skip to content

Commit a28eaa5

Browse files
committed
change attribute accessor format; create BufferAccessor class
1 parent 8c7190c commit a28eaa5

16 files changed

+497
-646
lines changed

demos/quatlerp.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
// Move the camera back 40 units.
3636
.setLookAt([0, 0, 40]);
3737
// Create a box mesh 10 units in size
38-
var mesh = H3DU.Meshes.createBox(10, 20, 20).toWireFrame();
38+
var mesh = H3DU.Meshes.createBox(10, 20, 20).wireFrame();
3939
// Create a shape based on the mesh and give it a red color
4040
var shape = new H3DU.Shape(mesh).setMaterial(H3DU.Material.fromBasic("red"));
4141
var shape2 = new H3DU.Shape(mesh).setMaterial(H3DU.Material.fromBasic("blue"));

doc/H3DU.BufferHelper.md

Lines changed: 9 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -7,40 +7,17 @@
77

88
A helper class for accessing and setting data in vertex attributes.
99

10-
A <b>vertex attribute object</b> includes the following:<ul>
11-
<li>A semantic, such as <a href="H3DU.Semantic.md#H3DU.Semantic.POSITION">H3DU.Semantic.POSITION</a>, which describes
12-
the kind of data each value holds.
13-
<li>A semantic index, which distinguishes attributes with the same semantic
14-
in the same mesh buffer object.
15-
<li>A <i>buffer</i> of arbitrary size. This buffer
16-
is made up of <i>values</i>, one for each vertex, and each value
17-
is takes up one or more <i>elements</i> in the buffer, which are numbers such
18-
as X coordinates or red components, depending on the attribute's semantic.
19-
Each value has the same number of elements.
20-
<li>An offset, which identifies the index, starting from 0, of the first value
21-
of the attribute within the given buffer.
22-
<li>A count of the number of elements each value has. For example, 3-dimensional
23-
positions will have 3 elements, one for each coordinate.
24-
<li>A stride, which gives the number of elements from the start of one
25-
value to the start of the next. A "packed" buffer will have a stride
26-
equal to the number of elements per value.</ul>
27-
2810
### Methods
2911

3012
* [copy](#H3DU.BufferHelper_copy)<br>Copies the values of a vertex attribute into a new vertex attribute object.
31-
* [count](#H3DU.BufferHelper_count)<br>Gets the number of values defined for a vertex attribute.
32-
* [countPerValue](#H3DU.BufferHelper_countPerValue)<br>Gets the number of elements (numbers) that each value of a vertex attribute uses.
3313
* [get](#H3DU.BufferHelper_get)<br>Gets the first element of the attribute value with the given vertex index.
34-
* [getBuffer](#H3DU.BufferHelper_getBuffer)<br>Gets a reference to the buffer used in the given vertex attribute object.
3514
* [getVec](#H3DU.BufferHelper_getVec)<br>Gets the elements of a vertex attribute value.
36-
* [makeBlank](#H3DU.BufferHelper_makeBlank)<br>Creates a <a href="H3DU.BufferHelper.md">vertex attribute object</a>.
3715
* [makeIndices](#H3DU.BufferHelper_makeIndices)<br>Generates an array of increasing vertex indices
3816
* [merge](#H3DU.BufferHelper_merge)<br>Merges two vertex attributes, whose vertices can be indexed differently, into one
3917
combined vertex attribute.
4018
* [resolveSemantic](#H3DU.BufferHelper_resolveSemantic)<br>Resolves an attribute semantic and semantic index, which
4119
may optionally be given as a string instead, into two numbers giving
4220
the semantic and index.
43-
* [sameSemantic](#H3DU.BufferHelper_sameSemantic)<br>TODO: Not documented yet.
4421
* [set](#H3DU.BufferHelper_set)<br>Sets the first element of the attribute value with the given vertex index.
4522
* [setVec](#H3DU.BufferHelper_setVec)<br>Sets the elements of a vertex attribute value.
4623

@@ -51,39 +28,12 @@ Copies the values of a vertex attribute into a new vertex attribute object.
5128

5229
#### Parameters
5330

54-
* `attr` (Type: Array.&lt;Object>)<br>A <a href="H3DU.BufferHelper.md">vertex attribute object</a>.
31+
* `attr` (Type: Array.&lt;Object>)<br>A vertex buffer accessor.
5532

5633
#### Return Value
5734

5835
A copy of the vertex attribute object. (Type: Array.&lt;Object>)
5936

60-
<a name='H3DU.BufferHelper_count'></a>
61-
### H3DU.BufferHelper#count(a)
62-
63-
Gets the number of values defined for a vertex attribute.
64-
65-
#### Parameters
66-
67-
* `a` (Type: Array.&lt;Object>)<br>A <a href="H3DU.BufferHelper.md">vertex attribute object</a>.
68-
69-
#### Return Value
70-
71-
The number of values defined in the attribute object's buffer. (Type: number)
72-
73-
<a name='H3DU.BufferHelper_countPerValue'></a>
74-
### H3DU.BufferHelper#countPerValue(a)
75-
76-
Gets the number of elements (numbers) that each value of a vertex attribute uses.
77-
78-
#### Parameters
79-
80-
* `a` (Type: Array.&lt;Object>)<br>A <a href="H3DU.BufferHelper.md">vertex attribute object</a>. Can be null.
81-
82-
#### Return Value
83-
84-
The number of elements per value of the vertex attribute, or 0 if "a" is null,
85-
undefined, or omitted. (Type: number)
86-
8737
<a name='H3DU.BufferHelper_get'></a>
8838
### H3DU.BufferHelper#get(a, index)
8939

@@ -94,27 +44,13 @@ checking naturally done when accessing the attribute's buffer.
9444

9545
#### Parameters
9646

97-
* `a` (Type: Array.&lt;Object>)<br>A <a href="H3DU.BufferHelper.md">vertex attribute object</a>.
47+
* `a` (Type: H3DU.BufferAccessor)<br>A vertex buffer accessor.
9848
* `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.
9949

10050
#### Return Value
10151

10252
Return value. (Type: *)
10353

104-
<a name='H3DU.BufferHelper_getBuffer'></a>
105-
### H3DU.BufferHelper#getBuffer(a)
106-
107-
Gets a reference to the buffer used in the given vertex attribute object.
108-
109-
#### Parameters
110-
111-
* `a` (Type: Array.&lt;Object>)<br>A <a href="H3DU.BufferHelper.md">vertex attribute object</a>.
112-
113-
#### Return Value
114-
115-
A reference to the buffer used in the vertex attribute
116-
object, or null if "a" is null, undefined, or omitted. (Type: Float32Array)
117-
11854
<a name='H3DU.BufferHelper_getVec'></a>
11955
### H3DU.BufferHelper#getVec(a, index, vec)
12056

@@ -125,31 +61,14 @@ checking naturally done when accessing the attribute's buffer.
12561

12662
#### Parameters
12763

128-
* `a` (Type: Array.&lt;Object>)<br>A <a href="H3DU.BufferHelper.md">vertex attribute object</a>.
64+
* `a` (Type: H3DU.BufferAccessor)<br>A vertex buffer accessor.
12965
* `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.
13066
* `vec` (Type: Array.&lt;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 H3DU.BufferHelper.countPerValue).
13167

13268
#### Return Value
13369

13470
The parameter "vec". (Type: Array.&lt;number>)
13571

136-
<a name='H3DU.BufferHelper_makeBlank'></a>
137-
### H3DU.BufferHelper#makeBlank(semantic, semanticIndex, count, countPerValue)
138-
139-
Creates a <a href="H3DU.BufferHelper.md">vertex attribute object</a>.
140-
Each value in the attribute will be initialized to all zeros.
141-
142-
#### Parameters
143-
144-
* `semantic` (Type: number | string)<br>An attribute semantic, such as <a href="H3DU.Semantic.md#H3DU.Semantic.POSITION">H3DU.Semantic.POSITION</a>, "POSITION", or "TEXCOORD_0". Throws an error if this value is a string and the string is invalid.
145-
* `semanticIndex` (Type: number)<br>The set index of the attribute for the given semantic. 0 is the first index of the attribute, 1 is the second, and so on. This is ignored if "semantic" is a string.
146-
* `count` (Type: number)<br>Number of values. Each value describes the attribute's value for the corresponding vertex.
147-
* `countPerValue` (Type: number)<br>Number of elements (numbers) for each value.
148-
149-
#### Return Value
150-
151-
A new vertex attribute with blank values. (Type: Array.&lt;Object>)
152-
15372
<a name='H3DU.BufferHelper_makeIndices'></a>
15473
### H3DU.BufferHelper#makeIndices(numIndices)
15574

@@ -167,23 +86,20 @@ An array of vertex indices. (Type: Uint16Array | Uint32Array)
16786
### H3DU.BufferHelper#merge(attr1, indices1, attr2, indices2)
16887

16988
Merges two vertex attributes, whose vertices can be indexed differently, into one
170-
combined vertex attribute. The two attributes must have the same semantic and semantic
171-
index, for example, semantic POSITION and semantic index 0.
89+
combined vertex attribute.
17290

17391
#### Parameters
17492

175-
* `attr1` (Type: Array.&lt;Object>)<br>A <a href="H3DU.BufferHelper.md">vertex attribute object</a> for the first vertex attribute. Can be null, in which case it is assumed that the attribute contains as many values as indices and all the values are zeros.
93+
* `attr1` (Type: H3DU.BufferAccessor)<br>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 indices and all the values are zeros.
17694
* `indices1` (Type: Array.&lt;number> | Uint16Array | Uint8Array | Uint32Array)<br>An array of vertex indices associated with the first vertex attribute.
177-
* `attr2` (Type: Array.&lt;Object>)<br>A <a href="H3DU.BufferHelper.md">vertex attribute object</a> for the second vertex attribute. Can be null, in which case it is assumed that the attribute contains as many values as indices and all the values are zeros.
95+
* `attr2` (Type: H3DU.BufferAccessor)<br>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 indices and all the values are zeros.
17896
* `indices2` (Type: Array.&lt;number> | Uint16Array | Uint8Array | Uint32Array)<br>An array of vertex indices associated with the second vertex attribute.
17997

18098
#### Return Value
18199

182100
The merged attribute, where the vertices from the first vertex
183101
attribute come before those from the second. The merged attribute will have as many
184-
values as the sum of the lengths of "indices1" and "indices2".
185-
Returns null if the two objects have different semantics
186-
or semantic indices. (Type: Array.&lt;Object>)
102+
values as the sum of the lengths of "indices1" and "indices2". (Type: H3DU.BufferAccessor)
187103

188104
<a name='H3DU.BufferHelper_resolveSemantic'></a>
189105
### H3DU.BufferHelper#resolveSemantic(name, [index])
@@ -204,20 +120,6 @@ of the semantic and semantic index, respectively, described in
204120
the "name" and "index" parameters. Returns null if "name" is a string,
205121
but doesn't describe a valid semantic. (Type: Array.&lt;number>)
206122

207-
<a name='H3DU.BufferHelper_sameSemantic'></a>
208-
### H3DU.BufferHelper#sameSemantic(a1, a2)
209-
210-
TODO: Not documented yet.
211-
212-
#### Parameters
213-
214-
* `a1` (Type: *)
215-
* `a2` (Type: *)
216-
217-
#### Return Value
218-
219-
Return value. (Type: *)
220-
221123
<a name='H3DU.BufferHelper_set'></a>
222124
### H3DU.BufferHelper#set(a, index, value)
223125

@@ -228,7 +130,7 @@ checking naturally done when writing to the attribute's buffer.
228130

229131
#### Parameters
230132

231-
* `a` (Type: Array.&lt;Object>)<br>A <a href="H3DU.BufferHelper.md">vertex attribute object</a>.
133+
* `a` (Type: H3DU.BufferAccessor)<br>A vertex buffer accessor.
232134
* `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.
233135
* `value` (Type: number)<br>The number to set the first element to.
234136

@@ -247,7 +149,7 @@ where noted otherwise.
247149

248150
#### Parameters
249151

250-
* `a` (Type: Array.&lt;Object>)<br>A <a href="H3DU.BufferHelper.md">vertex attribute object</a>.
152+
* `a` (Type: H3DU.BufferAccessor)<br>A vertex buffer accessor.
251153
* `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.
252154
* `vec` (Type: Array.&lt;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 H3DU.BufferHelper.countPerValue), whichever is less.
253155

doc/H3DU.CurveBuilder.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ Sets the parametric curve used to generate vertex attribute values.
3131

3232
* `curve` (Type: Object)<br>A <a href="H3DU.Curve.md">curve evaluator object</a> that describes the parametric curve used to generate attribute.
3333
* `semantic` (Type: number | string)<br>An attribute semantic, such as <a href="H3DU.Semantic.md#H3DU.Semantic.POSITION">H3DU.Semantic.POSITION</a>, "POSITION", or "TEXCOORD_0". Throws an error if this value is a string and the string is invalid.
34-
* `semanticIndex` (Type: number)<br>The set index of the attribute for the given semantic. 0 is the first index of the attribute, 1 is the second, and so on. This is ignored if "name" is a string.
35-
* `size` (Type: number) (optional)<br>The number of elements in each position value. For example, if the attribute is 3-dimensional, this parameter is 3. If null, undefined, or omitted, the default is 3.
34+
* `semanticIndex` (Type: number)<br>The set index of the attribute for the given semantic. 0 is the first index of the attribute, 1 is the second, and so on. This is ignored if "name" is a string. If null or undefined, this value is 0.
35+
* `size` (Type: number) (optional)<br>The number of elements in each position value. For example, if the attribute is 3-dimensional, this parameter is 3. If null, undefined, or omitted, the default is 3. Throws an error if this value is 0 or less.
3636

3737
#### Return Value
3838

@@ -91,7 +91,7 @@ Sets the parametric curve used to generate vertex positions.
9191
#### Parameters
9292

9393
* `curve` (Type: Object)<br>A <a href="H3DU.Curve.md">curve evaluator object</a> that describes the parametric curve used to generate positions.
94-
* `size` (Type: number) (optional)<br>The number of elements in each position value. For example, if the attribute is 3-dimensional, this parameter is 3. If null, undefined, or omitted, the default is 3.
94+
* `size` (Type: number) (optional)<br>The number of elements in each position value. For example, if the attribute is 3-dimensional, this parameter is 3. If null, undefined, or omitted, the default is 3. Throws an error if this value is 0 or less.
9595

9696
#### Return Value
9797

doc/H3DU.MeshBuffer.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ Gets a vertex attribute included in this mesh buffer.
6464

6565
#### Return Value
6666

67-
A <a href="H3DU.BufferHelper.md">vertex attribute object</a>, or null
68-
if the attribute doesn't exist. (Type: Array.&lt;Object>)
67+
A vertex buffer accessor, or null
68+
if the attribute doesn't exist. (Type: H3DU.BufferAccessor)
6969

7070
<a name='H3DU.MeshBuffer_getBounds'></a>
7171
### H3DU.MeshBuffer#getBounds()
@@ -252,8 +252,8 @@ stored in a vertex buffer.
252252
* `index` (Type: number)<br>The set index of the attribute for the given semantic. 0 is the first index of the attribute, 1 is the second, and so on. This is ignored if "name" is a string.
253253
* `buffer` (Type: Float32Array | Array)<br>The buffer where the per-vertex data is stored.
254254
* `startIndex` (Type: number)<br>The index into the array (starting from 0) where the first per-vertex item starts.
255-
* `countPerVertex` (Type: number)<br>The number of elements in each per-vertex item. For example, if each vertex is a 3-element vector, this value is 3.
256-
* `stride` (Type: number) (optional)<br>The number of elements from the start of one per-vertex item to the start of the next. If null, undefined, or omitted, this value is the same as "countPerVertex".
255+
* `countPerVertex` (Type: number)<br>The number of elements in each per-vertex item. For example, if each vertex is a 3-element vector, this value is 3. Throws an error if this value is 0 or less.
256+
* `stride` (Type: number) (optional)<br>The number of elements from the start of one per-vertex item to the start of the next. If null, undefined, or omitted, this value is the same as "countPerVertex". Throws an error if this value is 0 or less.
257257

258258
#### Return Value
259259

doc/H3DU.SurfaceBuilder.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ Sets the parametric surface used to generate vertex attribute values.
3939

4040
* `surface` (Type: Object)<br>A <a href="H3DU.Surface.md">surface evaluator object</a> that describes the parametric surface used to generate attribute's values.
4141
* `semantic` (Type: number | string)<br>An attribute semantic, such as <a href="H3DU.Semantic.md#H3DU.Semantic.POSITION">H3DU.Semantic.POSITION</a>, "POSITION", or "TEXCOORD_0". Throws an error if this value is a string and the string is invalid.
42-
* `semanticIndex` (Type: number) (optional)<br>The set index of the attribute for the given semantic. 0 is the first index of the attribute, 1 is the second, and so on. This is ignored if "name" is a string.
43-
* `size` (Type: number) (optional)<br>The number of elements in each position and normal. For example, if the attribute is 3-dimensional, this parameter is 3. If null, undefined, or omitted, the default is 3.
42+
* `semanticIndex` (Type: number) (optional)<br>The set index of the attribute for the given semantic. 0 is the first index of the attribute, 1 is the second, and so on. This is ignored if "name" is a string. If null or undefined, this value is 0.
43+
* `size` (Type: number) (optional)<br>The number of elements in each position and normal. For example, if the attribute is 3-dimensional, this parameter is 3. If null, undefined, or omitted, the default is 3. Throws an error if this value is 0 or less.
4444

4545
#### Return Value
4646

@@ -93,7 +93,7 @@ TODO: Not documented yet.
9393
#### Parameters
9494

9595
* `surface` (Type: Object)<br>A <a href="H3DU.Surface.md">surface evaluator object</a> that describes the parametric surface used to generate position values.
96-
* `size` (Type: number) (optional)<br>The number of elements in each position value. For example, if the attribute is 3-dimensional, this parameter is 3. If null, undefined, or omitted, the default is 3.
96+
* `size` (Type: number) (optional)<br>The number of elements in each position value. For example, if the attribute is 3-dimensional, this parameter is 3. If null, undefined, or omitted, the default is 3. Throws an error if this value is 0 or less.
9797

9898
#### Return Value
9999

@@ -107,7 +107,7 @@ Sets the parametric surface used to generate vertex positions and normals.
107107
#### Parameters
108108

109109
* `surface` (Type: Object)<br>A <a href="H3DU.Surface.md">surface evaluator object</a> that describes the parametric surface used to generate positions.
110-
* `size` (Type: number) (optional)<br>The number of elements in each position and normal. For example, if the attribute is 3-dimensional, this parameter is 3. If null, undefined, or omitted, the default is 3.
110+
* `size` (Type: number) (optional)<br>The number of elements in each position and normal. For example, if the attribute is 3-dimensional, this parameter is 3. If null, undefined, or omitted, the default is 3. Throws an error if this value is 0 or less.
111111

112112
#### Return Value
113113

@@ -139,7 +139,7 @@ from (0,1) along the U and V axes of the surface.
139139
#### Parameters
140140

141141
* `surface` (Type: Object)<br>A <a href="H3DU.Surface.md">surface evaluator object</a> that describes the parametric surface used to generate positions.
142-
* `size` (Type: number) (optional)<br>The number of elements in each position. For example, if the attribute is 3-dimensional, this parameter is 3. If null, undefined, or omitted, the default is 3. The texture coordinates will be 2-dimensional.
142+
* `size` (Type: number) (optional)<br>The number of elements in each position. For example, if the attribute is 3-dimensional, this parameter is 3. If null, undefined, or omitted, the default is 3. The texture coordinates will be 2-dimensional. Throws an error if this value is 0 or less.
143143

144144
#### Return Value
145145

0 commit comments

Comments
 (0)