Skip to content

Commit 161a0ed

Browse files
committed
move more methods to BufferAttribute; fix initial occlusion implementation; address certain tasks; etc.
1 parent 3241903 commit 161a0ed

14 files changed

+557
-553
lines changed

doc/H3DU.BufferHelper.md

Lines changed: 0 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,12 @@ A helper class for accessing and setting data in vertex attributes.
1010
### Methods
1111

1212
* [copy](#H3DU.BufferHelper_copy)<br>Copies the values of a vertex attribute into a new vertex attribute object.
13-
* [get](#H3DU.BufferHelper_get)<br>Gets the first element of the attribute value with the given vertex index.
14-
* [getVec](#H3DU.BufferHelper_getVec)<br>Gets the elements of a vertex attribute value.
1513
* [makeIndices](#H3DU.BufferHelper_makeIndices)<br>Generates an array of increasing vertex indices
1614
* [merge](#H3DU.BufferHelper_merge)<br>Merges two vertex attributes, whose vertices can be indexed differently, into one
1715
combined vertex attribute.
1816
* [resolveSemantic](#H3DU.BufferHelper_resolveSemantic)<br>Resolves an attribute semantic and semantic index, which
1917
may optionally be given as a string instead, into two numbers giving
2018
the semantic and index.
21-
* [set](#H3DU.BufferHelper_set)<br>Sets the first element of the attribute value with the given vertex index.
22-
* [setVec](#H3DU.BufferHelper_setVec)<br>Sets the elements of a vertex attribute value.
2319

2420
<a name='H3DU.BufferHelper_copy'></a>
2521
### H3DU.BufferHelper#copy(attr)
@@ -34,41 +30,6 @@ Copies the values of a vertex attribute into a new vertex attribute object.
3430

3531
A copy of the vertex attribute object. (Type: <a href="H3DU.BufferAccessor.md">H3DU.BufferAccessor</a>)
3632

37-
<a name='H3DU.BufferHelper_get'></a>
38-
### H3DU.BufferHelper#get(a, index)
39-
40-
Gets the first element of the attribute value with the given vertex index.
41-
42-
Note that currently, this method does no bounds checking beyond the
43-
checking naturally done when accessing the attribute's buffer.
44-
45-
#### Parameters
46-
47-
* `a` (Type: <a href="H3DU.BufferAccessor.md">H3DU.BufferAccessor</a>)<br>A vertex buffer accessor.
48-
* `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.
49-
50-
#### Return Value
51-
52-
The first element of the given attribute value. (Type: number)
53-
54-
<a name='H3DU.BufferHelper_getVec'></a>
55-
### H3DU.BufferHelper#getVec(a, index, vec)
56-
57-
Gets the elements of a vertex attribute value.
58-
59-
Note that currently, this method does no bounds checking beyond the
60-
checking naturally done when accessing the attribute's buffer.
61-
62-
#### Parameters
63-
64-
* `a` (Type: <a href="H3DU.BufferAccessor.md">H3DU.BufferAccessor</a>)<br>A vertex buffer accessor.
65-
* `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.
66-
* `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 <a href="H3DU.BufferAccessor.md#H3DU.BufferAccessor_countPerValue">H3DU.BufferAccessor#countPerValue</a>).
67-
68-
#### Return Value
69-
70-
The parameter "vec". (Type: Array.&lt;number>)
71-
7233
<a name='H3DU.BufferHelper_makeIndices'></a>
7334
### H3DU.BufferHelper#makeIndices(numIndices)
7435

@@ -120,41 +81,4 @@ of the semantic and semantic index, respectively, described in
12081
the "name" and "index" parameters. Returns null if "name" is a string,
12182
but doesn't describe a valid semantic. (Type: Array.&lt;number>)
12283

123-
<a name='H3DU.BufferHelper_set'></a>
124-
### H3DU.BufferHelper#set(a, index, value)
125-
126-
Sets the first element of the attribute value with the given vertex index.
127-
128-
Note that currently, this method does no bounds checking beyond the
129-
checking naturally done when writing to the attribute's buffer.
130-
131-
#### Parameters
132-
133-
* `a` (Type: <a href="H3DU.BufferAccessor.md">H3DU.BufferAccessor</a>)<br>A vertex buffer accessor.
134-
* `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.
135-
* `value` (Type: number)<br>The number to set the first element to.
136-
137-
#### Return Value
138-
139-
This object. (Type: <a href="H3DU.BufferHelper.md">H3DU.BufferHelper</a>)
140-
141-
<a name='H3DU.BufferHelper_setVec'></a>
142-
### H3DU.BufferHelper#setVec(a, index, vec)
143-
144-
Sets the elements of a vertex attribute value.
145-
146-
Note that currently, this method does no bounds checking beyond the
147-
checking naturally done when writing to the attribute's buffer, except
148-
where noted otherwise.
149-
150-
#### Parameters
151-
152-
* `a` (Type: <a href="H3DU.BufferAccessor.md">H3DU.BufferAccessor</a>)<br>A vertex buffer accessor.
153-
* `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.
154-
* `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 <a href="H3DU.BufferAccessor.md#H3DU.BufferAccessor_countPerValue">H3DU.BufferAccessor#countPerValue</a>), whichever is less.
155-
156-
#### Return Value
157-
158-
This object. (Type: BufferHelper)
159-
16084
[Back to documentation index.](index.md)

doc/H3DU.Mesh.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ bitangent vectors for a mesh, use the <a href="H3DU.MeshBuffer.md">H3DU.MeshBuff
8080
and create a buffer attribute with the H3DU.Semantics.BITANGENT
8181
semantic.</b>
8282
* [color3](#H3DU.Mesh_color3)<br>Sets the current color for this mesh.
83-
* [enumPrimitives](#H3DU.Mesh_enumPrimitives)<br>Enumerates the primitives (lines, triangles, and points) included
84-
in this mesh.
83+
* [enumPrimitives](#H3DU.Mesh_enumPrimitives)<br><b>Deprecated: For a replacement of this method,
84+
see the example given in <a href="H3DU.MeshBuffer.md#H3DU.MeshBuffer_getAttribute">H3DU.MeshBuffer#getAttribute</a>.</b>
8585
* [getBoundingBox](#H3DU.Mesh_getBoundingBox)<br><b>Deprecated: Use <code>(this).toMeshBuffer().getBounds()</code> instead.</b>
8686
* [getVertex](#H3DU.Mesh_getVertex)<br>Gets the position of the vertex with the given
8787
index in this mesh.
@@ -306,6 +306,9 @@ This object. (Type: <a href="H3DU.Mesh.md">H3DU.Mesh</a>)
306306
<a name='H3DU.Mesh_enumPrimitives'></a>
307307
### H3DU.Mesh#enumPrimitives(func)
308308

309+
<b>Deprecated: For a replacement of this method,
310+
see the example given in <a href="H3DU.MeshBuffer.md#H3DU.MeshBuffer_getAttribute">H3DU.MeshBuffer#getAttribute</a>.</b>
311+
309312
Enumerates the primitives (lines, triangles, and points) included
310313
in this mesh.
311314

doc/H3DU.MeshBuffer.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,40 @@ Gets a vertex attribute included in this mesh buffer.
6767
A vertex buffer accessor, or null
6868
if the attribute doesn't exist. (Type: <a href="H3DU.BufferAccessor.md">H3DU.BufferAccessor</a>)
6969

70+
#### Example
71+
72+
The following function gets the positions,
73+
normals, texture coordinates, and colors of each primitive
74+
(line, text, or point) in the mesh buffer. A point will have one
75+
vertex per primitive, a line two vertices and a triangle three.
76+
The attributes, if present, will be stored in the "position",
77+
"normal", "uv", and "color" properties of each vertex.
78+
79+
function getPrimitives(mesh) {
80+
var p=mesh.getAttribute("POSITION")
81+
var n=mesh.getAttribute("NORMAL")
82+
var t=mesh.getAttribute("TEXCOORD_0")
83+
var c=mesh.getAttribute("COLOR")
84+
var ind=mesh.getIndices()
85+
var primSize = 3;
86+
if(mesh.primitiveType() === Mesh.LINES)primSize = 2;
87+
if(mesh.primitiveType() === Mesh.POINTS)primSize = 1;
88+
var ret=[]
89+
for(var i=0;i<ind.length;i+=primSize) {
90+
var prim=[]
91+
var index=ind[i]
92+
for(var j=0;j<primSize;j++) {
93+
var info={}
94+
if(p)info.position=p.getVec(index,[])
95+
if(n)info.normal=n.getVec(index,[])
96+
if(t)info.uv=t.getVec(index,[])
97+
if(c)info.color=c.getVec(index,[])
98+
}
99+
ret.push(prim)
100+
}
101+
return ret
102+
}
103+
70104
<a name='H3DU.MeshBuffer_getBounds'></a>
71105
### H3DU.MeshBuffer#getBounds()
72106

doc/H3DU.Semantic.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ Attribute semantic for a bitangent vector.
3636
### H3DU.Semantic.COLOR (constant)
3737

3838
Attribute semantic for a color.
39+
The default shader uses 3-component colors.
3940

4041
<a name='H3DU.Semantic.CUSTOM'></a>
4142
### H3DU.Semantic.CUSTOM (constant)

dochtml/H3DU.BufferHelper.html

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
11
<!DOCTYPE html><html><head><meta charset=utf-8><title>H3DU.BufferHelper</title></head><body><h1> H3DU.BufferHelper</h1><p><a href='index.html'>Back to documentation index.</a></p><a name='H3DU.BufferHelper'></a>
2-
<h3> H3DU.BufferHelper()</h3>A helper class for accessing and setting data in vertex attributes.<p><h3> Methods</h3><ul><li><a href='#H3DU.BufferHelper_copy'>copy</a><br>Copies the values of a vertex attribute into a new vertex attribute object.<li><a href='#H3DU.BufferHelper_get'>get</a><br>Gets the first element of the attribute value with the given vertex index.<li><a href='#H3DU.BufferHelper_getVec'>getVec</a><br>Gets the elements of a vertex attribute value.<li><a href='#H3DU.BufferHelper_makeIndices'>makeIndices</a><br>Generates an array of increasing vertex indices<li><a href='#H3DU.BufferHelper_merge'>merge</a><br>Merges two vertex attributes, whose vertices can be indexed differently, into one
2+
<h3> H3DU.BufferHelper()</h3>A helper class for accessing and setting data in vertex attributes.<p><h3> Methods</h3><ul><li><a href='#H3DU.BufferHelper_copy'>copy</a><br>Copies the values of a vertex attribute into a new vertex attribute object.<li><a href='#H3DU.BufferHelper_makeIndices'>makeIndices</a><br>Generates an array of increasing vertex indices<li><a href='#H3DU.BufferHelper_merge'>merge</a><br>Merges two vertex attributes, whose vertices can be indexed differently, into one
33
combined vertex attribute.<li><a href='#H3DU.BufferHelper_resolveSemantic'>resolveSemantic</a><br>Resolves an attribute semantic and semantic index, which
44
may optionally be given as a string instead, into two numbers giving
5-
the semantic and index.<li><a href='#H3DU.BufferHelper_set'>set</a><br>Sets the first element of the attribute value with the given vertex index.<li><a href='#H3DU.BufferHelper_setVec'>setVec</a><br>Sets the elements of a vertex attribute value.</ul><a name='H3DU.BufferHelper_copy'></a>
6-
<h3> H3DU.BufferHelper#copy(attr)</h3>Copies the values of a vertex attribute into a new vertex attribute object.<h4> Parameters</h4><ul><li><code>attr</code> (Type: <a href="H3DU.BufferAccessor.html">H3DU.BufferAccessor</a>)<br>A vertex buffer accessor.</ul><h4> Return Value</h4>A copy of the vertex attribute object. (Type: <a href="H3DU.BufferAccessor.html">H3DU.BufferAccessor</a>)<a name='H3DU.BufferHelper_get'></a>
7-
<h3> H3DU.BufferHelper#get(a, index)</h3>Gets the first element of the attribute value with the given vertex index.
8-
<p>Note that currently, this method does no bounds checking beyond the
9-
checking naturally done when accessing the attribute's buffer.<h4> Parameters</h4><ul><li><code>a</code> (Type: <a href="H3DU.BufferAccessor.html">H3DU.BufferAccessor</a>)<br>A vertex buffer accessor.<li><code>index</code> (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.</ul><h4> Return Value</h4>The first element of the given attribute value. (Type: number)<a name='H3DU.BufferHelper_getVec'></a>
10-
<h3> H3DU.BufferHelper#getVec(a, index, vec)</h3>Gets the elements of a vertex attribute value.<p>
11-
Note that currently, this method does no bounds checking beyond the
12-
checking naturally done when accessing the attribute's buffer.<h4> Parameters</h4><ul><li><code>a</code> (Type: <a href="H3DU.BufferAccessor.html">H3DU.BufferAccessor</a>)<br>A vertex buffer accessor.<li><code>index</code> (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.<li><code>vec</code> (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 <a href="H3DU.BufferAccessor.html#H3DU.BufferAccessor_countPerValue">H3DU.BufferAccessor#countPerValue</a>).</ul><h4> Return Value</h4>The parameter "vec". (Type: Array.&lt;number>)<a name='H3DU.BufferHelper_makeIndices'></a>
5+
the semantic and index.</ul><a name='H3DU.BufferHelper_copy'></a>
6+
<h3> H3DU.BufferHelper#copy(attr)</h3>Copies the values of a vertex attribute into a new vertex attribute object.<h4> Parameters</h4><ul><li><code>attr</code> (Type: <a href="H3DU.BufferAccessor.html">H3DU.BufferAccessor</a>)<br>A vertex buffer accessor.</ul><h4> Return Value</h4>A copy of the vertex attribute object. (Type: <a href="H3DU.BufferAccessor.html">H3DU.BufferAccessor</a>)<a name='H3DU.BufferHelper_makeIndices'></a>
137
<h3> H3DU.BufferHelper#makeIndices(numIndices)</h3>Generates an array of increasing vertex indices<h4> Parameters</h4><ul><li><code>numIndices</code> (Type: number)<br>The number of vertex indices to generate. The array will range from 0 to the number of vertex indices minus 1.</ul><h4> Return Value</h4>An array of vertex indices. (Type: Uint16Array | Uint32Array)<a name='H3DU.BufferHelper_merge'></a>
148
<h3> H3DU.BufferHelper#merge(attr1, indices1, attr2, indices2)</h3>Merges two vertex attributes, whose vertices can be indexed differently, into one
159
combined vertex attribute.<h4> Parameters</h4><ul><li><code>attr1</code> (Type: <a href="H3DU.BufferAccessor.html">H3DU.BufferAccessor</a>)<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.<li><code>indices1</code> (Type: Array.&lt;number> | Uint16Array | Uint8Array | Uint32Array)<br>An array of vertex indices associated with the first vertex attribute.<li><code>attr2</code> (Type: <a href="H3DU.BufferAccessor.html">H3DU.BufferAccessor</a>)<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.<li><code>indices2</code> (Type: Array.&lt;number> | Uint16Array | Uint8Array | Uint32Array)<br>An array of vertex indices associated with the second vertex attribute.</ul><h4> Return Value</h4>The merged attribute, where the vertices from the first vertex
@@ -20,11 +14,4 @@ <h3> H3DU.BufferHelper#resolveSemantic(name, [index])</h3>Resolves an attribute
2014
the semantic and index.<h4> Parameters</h4><ul><li><code>name</code> (Type: number | string)<br>An attribute semantic, such as <a href="H3DU.Semantic.html#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.<li><code>index</code> (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. Otherwise, if this value is null, undefined, or omitted, the default is 0.</ul><h4> Return Value</h4>A two-element array consisting
2115
of the semantic and semantic index, respectively, described in
2216
the "name" and "index" parameters. Returns null if "name" is a string,
23-
but doesn't describe a valid semantic. (Type: Array.&lt;number>)<a name='H3DU.BufferHelper_set'></a>
24-
<h3> H3DU.BufferHelper#set(a, index, value)</h3>Sets the first element of the attribute value with the given vertex index.
25-
<p>Note that currently, this method does no bounds checking beyond the
26-
checking naturally done when writing to the attribute's buffer.<h4> Parameters</h4><ul><li><code>a</code> (Type: <a href="H3DU.BufferAccessor.html">H3DU.BufferAccessor</a>)<br>A vertex buffer accessor.<li><code>index</code> (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.<li><code>value</code> (Type: number)<br>The number to set the first element to.</ul><h4> Return Value</h4>This object. (Type: <a href="H3DU.BufferHelper.html">H3DU.BufferHelper</a>)<a name='H3DU.BufferHelper_setVec'></a>
27-
<h3> H3DU.BufferHelper#setVec(a, index, vec)</h3>Sets the elements of a vertex attribute value.<p>
28-
Note that currently, this method does no bounds checking beyond the
29-
checking naturally done when writing to the attribute's buffer, except
30-
where noted otherwise.<h4> Parameters</h4><ul><li><code>a</code> (Type: <a href="H3DU.BufferAccessor.html">H3DU.BufferAccessor</a>)<br>A vertex buffer accessor.<li><code>index</code> (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.<li><code>vec</code> (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 <a href="H3DU.BufferAccessor.html#H3DU.BufferAccessor_countPerValue">H3DU.BufferAccessor#countPerValue</a>), whichever is less.</ul><h4> Return Value</h4>This object. (Type: BufferHelper)<p><a href='index.html'>Back to documentation index.</a></p></body></html>
17+
but doesn't describe a valid semantic. (Type: Array.&lt;number>)<p><a href='index.html'>Back to documentation index.</a></p></body></html>

0 commit comments

Comments
 (0)