Skip to content

Commit 32e09c1

Browse files
committed
support "JOINTS" and "WEIGHTS" semantic variants; fix issues with loading and caching texture images; etc.
1 parent 64d2852 commit 32e09c1

16 files changed

+126
-75
lines changed

demos/tris.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@
118118
var scene = new H3DU.Scene3D(document.getElementById("canvas"))
119119
.setClearColor("white");
120120
var sub = new H3DU.Batch3D();
121+
sub.getLights().setBasic();
121122
var tris = new TriangleParticles(sub, 200, scene.getWidth(), scene.getHeight());
122123
// Set up the render loop
123124
H3DU.renderLoop(function(time) {

doc/H3DU.PbrMaterial.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ or 1 minus roughness, and the roughness map is treated as a "glossiness"
3131
map, or an inverted roughness map.
3232
* [metalness](#H3DU.PbrMaterial_metalness)<br>A value indicating whether objects described by this material are metals.
3333
* [metalnessMap](#H3DU.PbrMaterial_metalnessMap)<br>A texture indicating the metalness of each part of the texture,
34-
as specified in the texture's red channel.
34+
as specified in the texture's blue channel.
3535
* [normalMap](#H3DU.PbrMaterial_normalMap)<br>Normal map (bump map) texture.
3636
* [roughness](#H3DU.PbrMaterial_roughness)<br>Describes the roughness of the surface described
3737
by this material.
3838
* [roughnessMap](#H3DU.PbrMaterial_roughnessMap)<br>A texture indicating the roughness of each part of the texture,
39-
as specified in the texture's red channel.
39+
as specified in the texture's green channel.
4040
* [shader](#H3DU.PbrMaterial_shader)<br>Shader program to use when rendering objects with this material.
4141
* [specular](#H3DU.PbrMaterial_specular)<br>Specular reflectivity of this material.
4242
* [specularMap](#H3DU.PbrMaterial_specularMap)<br>A texture where each pixel identifies the "specular" property of that
@@ -163,8 +163,8 @@ Default Value: `0`
163163
### H3DU.PbrMaterial#metalnessMap
164164

165165
A texture indicating the metalness of each part of the texture,
166-
as specified in the texture's red channel.
167-
Each pixel value in the red channel (which ranges from 0-255 in most image
166+
as specified in the texture's blue channel.
167+
Each pixel value in the blue channel (which ranges from 0-255 in most image
168168
formats) is scaled to the range [0, 1].
169169

170170
This value is only used in the <b>metallic workflow</b>.
@@ -228,8 +228,8 @@ Default Value: `0.35`
228228
### H3DU.PbrMaterial#roughnessMap
229229

230230
A texture indicating the roughness of each part of the texture,
231-
as specified in the texture's red channel.
232-
Each pixel value in the red channel (which ranges from 0-255 in most image
231+
as specified in the texture's green channel.
232+
Each pixel value in the green channel (which ranges from 0-255 in most image
233233
formats) is scaled to the range [0, 1].
234234

235235
The inverse of roughness is <i>glossiness</i> or <i>smoothness</i>;

doc/H3DU.Semantic.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,13 @@ Uniform semantic for a model-view-projection matrix.
7171
### H3DU.Semantic.NORMAL (constant)
7272

7373
Attribute semantic for a vertex normal.
74+
The default shader uses 3-dimensional normals.
7475

7576
<a name='H3DU.Semantic.POSITION'></a>
7677
### H3DU.Semantic.POSITION (constant)
7778

7879
Attribute semantic for a vertex position.
80+
The default shader uses 3-dimensional positions.
7981

8082
<a name='H3DU.Semantic.PROJECTION'></a>
8183
### H3DU.Semantic.PROJECTION (constant)
@@ -92,6 +94,15 @@ Attribute semantic for a tangent vector.
9294

9395
Attribute semantic for a texture coordinate.
9496

97+
Note that the default shader supports only 2-dimensional
98+
texture coordinates. For such texturing tasks as mapping
99+
a square to a trapezoid, 3-dimensional texture coordinates
100+
are useful to ensure the texturing is perspective-correct.
101+
In this case, the 3-D texture coordinates are converted
102+
to 2-D by dividing the X and Y components by the Z component.
103+
In a fragment shader, this can look like the following
104+
code: <code>texCoord.xy/texCoord.z</code>.
105+
95106
<a name='H3DU.Semantic.VIEW'></a>
96107
### H3DU.Semantic.VIEW (constant)
97108

doc/H3DU.TextureLoader.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Gets an already loaded texture by name from this texture loader.
4141
#### Return Value
4242

4343
The texture with the given name, or null
44-
if it doesn't exist. (Type: <a href="H3DU.Texture.md">H3DU.Texture</a>)
44+
if it isn't fully loaded or doesn't exist. (Type: <a href="H3DU.Texture.md">H3DU.Texture</a>)
4545

4646
<a name='H3DU.TextureLoader_loadAndMapTexture'></a>
4747
### H3DU.TextureLoader#loadAndMapTexture(texture, context)

dochtml/H3DU.PbrMaterial.html

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ <h3> H3DU.PbrMaterial([params])</h3>A material for physically-based rendering. S
88
in the red, green, blue, and alpha channels.<li><a href='#H3DU.PbrMaterial_emission'>emission</a><br>Additive color emitted by objects with this material.<li><a href='#H3DU.PbrMaterial_emissionMap'>emissionMap</a><br>Emission map texture.<li><a href='#H3DU.PbrMaterial_invertRoughness'>invertRoughness</a><br>If true, the roughness property is treated as a "glossiness" property,
99
or 1 minus roughness, and the roughness map is treated as a "glossiness"
1010
map, or an inverted roughness map.<li><a href='#H3DU.PbrMaterial_metalness'>metalness</a><br>A value indicating whether objects described by this material are metals.<li><a href='#H3DU.PbrMaterial_metalnessMap'>metalnessMap</a><br>A texture indicating the metalness of each part of the texture,
11-
as specified in the texture's red channel.<li><a href='#H3DU.PbrMaterial_normalMap'>normalMap</a><br>Normal map (bump map) texture.<li><a href='#H3DU.PbrMaterial_roughness'>roughness</a><br>Describes the roughness of the surface described
11+
as specified in the texture's blue channel.<li><a href='#H3DU.PbrMaterial_normalMap'>normalMap</a><br>Normal map (bump map) texture.<li><a href='#H3DU.PbrMaterial_roughness'>roughness</a><br>Describes the roughness of the surface described
1212
by this material.<li><a href='#H3DU.PbrMaterial_roughnessMap'>roughnessMap</a><br>A texture indicating the roughness of each part of the texture,
13-
as specified in the texture's red channel.<li><a href='#H3DU.PbrMaterial_shader'>shader</a><br>Shader program to use when rendering objects with this material.<li><a href='#H3DU.PbrMaterial_specular'>specular</a><br>Specular reflectivity of this material.<li><a href='#H3DU.PbrMaterial_specularMap'>specularMap</a><br>A texture where each pixel identifies the "specular" property of that
13+
as specified in the texture's green channel.<li><a href='#H3DU.PbrMaterial_shader'>shader</a><br>Shader program to use when rendering objects with this material.<li><a href='#H3DU.PbrMaterial_specular'>specular</a><br>Specular reflectivity of this material.<li><a href='#H3DU.PbrMaterial_specularMap'>specularMap</a><br>A texture where each pixel identifies the "specular" property of that
1414
part of the texture, as specified in the texture's red, green, and blue channels
1515
(in the <a href="H3DU.Math.html#H3DU.Math.colorTosRGB">sRGB color space</a>).<li><a href='#H3DU.PbrMaterial_workflow'>workflow</a><br>Specifies which workflow to use when interpreting values for this
1616
material.</ul><h3> Methods</h3><ul><li><a href='#H3DU.PbrMaterial_copy'>copy</a><br>Clones this object's parameters to a new <a href="H3DU.PbrMaterial.html">H3DU.PbrMaterial</a>
@@ -91,8 +91,8 @@ <h3> H3DU.PbrMaterial#metalness
9191
<h3> H3DU.PbrMaterial#metalnessMap
9292

9393
</h3>A texture indicating the metalness of each part of the texture,
94-
as specified in the texture's red channel.
95-
Each pixel value in the red channel (which ranges from 0-255 in most image
94+
as specified in the texture's blue channel.
95+
Each pixel value in the blue channel (which ranges from 0-255 in most image
9696
formats) is scaled to the range [0, 1].<p>
9797
This value is only used in the <b>metallic workflow</b>.
9898
Any texture used for this map should not be in JPEG format or any other
@@ -141,8 +141,8 @@ <h3> H3DU.PbrMaterial#roughness
141141
<h3> H3DU.PbrMaterial#roughnessMap
142142

143143
</h3>A texture indicating the roughness of each part of the texture,
144-
as specified in the texture's red channel.
145-
Each pixel value in the red channel (which ranges from 0-255 in most image
144+
as specified in the texture's green channel.
145+
Each pixel value in the green channel (which ranges from 0-255 in most image
146146
formats) is scaled to the range [0, 1].<p>
147147
The inverse of roughness is <i>glossiness</i> or <i>smoothness</i>;
148148
to treat the texture as a glossiness or smoothness map, set the

dochtml/H3DU.Semantic.html

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,13 @@ <h3> H3DU.Semantic.MODELVIEWPROJECTION (constant)
4444
<h3> H3DU.Semantic.NORMAL (constant)
4545

4646
</h3>Attribute semantic for a vertex normal.
47+
The default shader uses 3-dimensional normals.
4748

4849
<a name='H3DU.Semantic.POSITION'></a>
4950
<h3> H3DU.Semantic.POSITION (constant)
5051

5152
</h3>Attribute semantic for a vertex position.
53+
The default shader uses 3-dimensional positions.
5254

5355
<a name='H3DU.Semantic.PROJECTION'></a>
5456
<h3> H3DU.Semantic.PROJECTION (constant)
@@ -63,7 +65,15 @@ <h3> H3DU.Semantic.TANGENT (constant)
6365
<a name='H3DU.Semantic.TEXCOORD'></a>
6466
<h3> H3DU.Semantic.TEXCOORD (constant)
6567

66-
</h3>Attribute semantic for a texture coordinate.
68+
</h3>Attribute semantic for a texture coordinate.<p>
69+
Note that the default shader supports only 2-dimensional
70+
texture coordinates. For such texturing tasks as mapping
71+
a square to a trapezoid, 3-dimensional texture coordinates
72+
are useful to ensure the texturing is perspective-correct.
73+
In this case, the 3-D texture coordinates are converted
74+
to 2-D by dividing the X and Y components by the Z component.
75+
In a fragment shader, this can look like the following
76+
code: <code>texCoord.xy/texCoord.z</code>.
6777

6878
<a name='H3DU.Semantic.VIEW'></a>
6979
<h3> H3DU.Semantic.VIEW (constant)

dochtml/H3DU.TextureLoader.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ <h3> H3DU.TextureLoader()</h3>An object that caches loaded textures and uploads
55
stores their texture data.</ul><a name='H3DU.TextureLoader_dispose'></a>
66
<h3> H3DU.TextureLoader#dispose()</h3>Disposes all resources used by this texture loader.<h4> Return Value</h4>This method doesn't return a value. (Type: void)<a name='H3DU.TextureLoader_getTexture'></a>
77
<h3> H3DU.TextureLoader#getTexture(name)</h3>Gets an already loaded texture by name from this texture loader.<h4> Parameters</h4><ul><li><code>name</code> (Type: string)<br>The name of the texture, usually its file name.</ul><h4> Return Value</h4>The texture with the given name, or null
8-
if it doesn't exist. (Type: <a href="H3DU.Texture.html">H3DU.Texture</a>)<a name='H3DU.TextureLoader_loadAndMapTexture'></a>
8+
if it isn't fully loaded or doesn't exist. (Type: <a href="H3DU.Texture.html">H3DU.Texture</a>)<a name='H3DU.TextureLoader_loadAndMapTexture'></a>
99
<h3> H3DU.TextureLoader#loadAndMapTexture(texture, context)</h3>Loads the texture referred to in an array of URLs and
1010
uploads its texture data to a WebGL context.<h4> Parameters</h4><ul><li><code>texture</code> (Type: String | <a href="H3DU.TextureInfo.html">H3DU.TextureInfo</a> | <a href="H3DU.Texture.html">H3DU.Texture</a>)<br>An object described in H3DU.TextureLoader.loadTexture.<li><code>context</code> (Type: WebGLRenderingContext | WebGL2RenderingContext | Object)<br>A WebGL context to associate with this scene, or an object, such as <a href="H3DU.Scene3D.html">H3DU.Scene3D</a>, that implements a no-argument <code>getContext</code> method that returns a WebGL context.</ul><h4> Return Value</h4>A promise that resolves when
1111
the texture is loaded successfully (the result will be an H3DU.Texture object)

h3du-bufferhelper.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,8 @@ BufferHelper._wellKnownAttributes = {
291291
"NORMAL":1,
292292
"JOINT":4,
293293
"WEIGHT":5,
294+
"JOINTS":4,
295+
"WEIGHTS":5,
294296
"TANGENT":6,
295297
"BITANGENT":7
296298
};

h3du-mesh.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,6 @@ Mesh.prototype.color3 = function(r, g, b) {
207207
* @returns {H3DU.Mesh} This object.
208208
*/
209209
Mesh.prototype.texCoord2 = function(u, v) {
210-
// LATER: Support 3D texture coordinates
211210
if(typeof u === "number" && typeof v === "number") {
212211
this.texCoord[0] = u;
213212
this.texCoord[1] = v;

h3du-pbrmaterial.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ function PbrMaterial(params) {
6666
this.metalness = 0;
6767
/**
6868
* A texture indicating the metalness of each part of the texture,
69-
* as specified in the texture's red channel.
70-
* Each pixel value in the red channel (which ranges from 0-255 in most image
69+
* as specified in the texture's blue channel.
70+
* Each pixel value in the blue channel (which ranges from 0-255 in most image
7171
* formats) is scaled to the range [0, 1].<p>
7272
* This value is only used in the <b>metallic workflow</b>.
7373
* Any texture used for this map should not be in JPEG format or any other
@@ -88,8 +88,8 @@ function PbrMaterial(params) {
8888
this.roughness = 0.35;
8989
/**
9090
* A texture indicating the roughness of each part of the texture,
91-
* as specified in the texture's red channel.
92-
* Each pixel value in the red channel (which ranges from 0-255 in most image
91+
* as specified in the texture's green channel.
92+
* Each pixel value in the green channel (which ranges from 0-255 in most image
9393
* formats) is scaled to the range [0, 1].<p>
9494
* The inverse of roughness is <i>glossiness</i> or <i>smoothness</i>;
9595
* to treat the texture as a glossiness or smoothness map, set the

0 commit comments

Comments
 (0)