Skip to content

Commit 768578b

Browse files
committed
Merge branch 'hotfix-5.0.2'
2 parents 9e0f946 + 73b686b commit 768578b

File tree

13 files changed

+225
-148
lines changed

13 files changed

+225
-148
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "xml3d.js",
33
"description": "XML3D implementation based on JS and WebGL",
44
"homepage": "http://ww.xml3d.org",
5-
"version": "5.0.1",
5+
"version": "5.0.2",
66
"repository": {
77
"type": "git",
88
"url": "https://github.com/xml3d/xml3d.js"

spec/index.html

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1671,6 +1671,7 @@ <h4>The <code>assetmesh</code> element</h4>
16711671
<dl class='element'>
16721672
<dt>Categories:</dt>
16731673
<dd><a href="#data-elements">Data element</a></dd>
1674+
<dd><a href="#transformable-elements">Transformable element</a></dd>
16741675
</dl>
16751676

16761677
<p>An <dfn>assetmesh element</dfn> represents a single drawable mesh in the asset and works similar to the
@@ -3432,7 +3433,8 @@ <h3>AxisAngle</h3>
34323433
<h3>Quat</h3>
34333434
<dl class='element'>
34343435
</dl>
3435-
<p>Quat represents a rotation as a quaternion of the form [x, y, z, w]. </p>
3436+
<p>Quat represents a rotation as a quaternion of the form [x, y, z, w]. The provided functions and accessors
3437+
do not automatically normalize the quaternion unless otherwise stated.</p>
34363438

34373439
<dl title='interface Quat' class='idl'>
34383440
<dt>attribute Float32Array data</dt>
@@ -3501,15 +3503,15 @@ <h3>Quat</h3>
35013503
<dt>Quat scale(float scale)</dt>
35023504
<dd>Returns the scaled quaternion as a new Quat. This is identical to <a>Vec4</a>.scale.</dd>
35033505
<dt>static Quat fromAxisAngle(AxisAngle a)</dt>
3504-
<dd>Generates a quaternion representation of the given AxisAngle.</dd>
3506+
<dd>Generates a normalized quaternion representation of the given AxisAngle.</dd>
35053507
<dt>static Quat fromBasis(Vec3 x, Vec3 y, Vec3 z)</dt>
3506-
<dd>Generates a quaternion from the given basis vectors, defined as the rotation between the coordinate
3508+
<dd>Generates a normalized quaternion from the given basis vectors, defined as the rotation between the coordinate
35073509
space defined by these vectors and the standard space.
35083510
</dd>
35093511
<dt>static Quat fromMat3(Mat3 mat)</dt>
3510-
<dd>Generates a quaternion from the given rotation matrix.</dd>
3512+
<dd>Generates a normalized quaternion from the given rotation matrix.</dd>
35113513
<dt>static Quat fromRotationTo(Vec3 from, Vec3 to)</dt>
3512-
<dd>Generates a quaternion representing the shortest rotation from one vector to another.</dd>
3514+
<dd>Generates a normalized quaternion representing the shortest rotation from one vector to another.</dd>
35133515
<dt>Quat slerp()</dt>
35143516
<dd>Returns a spherical linear interpolation between the two quaternions as a new Quat.
35153517
<dl class='parameters'>
@@ -3566,7 +3568,7 @@ <h3>Mat2</h3>
35663568
<dd>Returns the multiplication of this matrix with the other as a new Mat2.</dd>
35673569
<dt>Mat2 rotate(float angleInRadians)</dt>
35683570
<dd>Returns the rotation of this matrix by the given angle in radians as a new Mat2.</dd>
3569-
<dt>Mat2 scale(float scale)</dt>
3571+
<dt>Mat2 scale(Vec2 scale)</dt>
35703572
<dd>Returns the scaled matrix as a new Mat2.</dd>
35713573
<dt>Mat2 transpose()</dt>
35723574
<dd>Returns the transpose of this matrix as a new Mat2.</dd>
@@ -3631,7 +3633,7 @@ <h3>Mat3</h3>
36313633
<dd>Returns the multiplication of this matrix with the other as a new Mat3.</dd>
36323634
<dt>Mat3 rotate(float angleInRadians)</dt>
36333635
<dd>Returns the rotation of this matrix by the given angle in radians as a new Mat3.</dd>
3634-
<dt>Mat3 scale(float scale)</dt>
3636+
<dt>Mat3 scale(Vec3 scale)</dt>
36353637
<dd>Returns the scaled matrix as a new Mat3.</dd>
36363638
<dt>Mat3 translate(Vec3 translation)</dt>
36373639
<dd>Returns the translated matrix as a new Mat3.</dd>
@@ -3721,7 +3723,7 @@ <h3>Mat4</h3>
37213723
<dd>Returns the rotation of this matrix by the given angle around the Y axis as a new Mat4.</dd>
37223724
<dt>Mat4 rotateZ(float angleInRadians)</dt>
37233725
<dd>Returns the rotation of this matrix by the given angle around the Z axis as a new Mat4.</dd>
3724-
<dt>Mat4 scale(float scale)</dt>
3726+
<dt>Mat4 scale(Vec3 scale)</dt>
37253727
<dd>Returns the scaled matrix as a new Mat4.</dd>
37263728
<dt>Mat4 translate(Vec3 translation)</dt>
37273729
<dd>Returns the translated matrix as a new Mat4.</dd>

src/base/resourcemanager.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ function setDocumentData(httpRequest, url, mimetype) {
321321
else{
322322
invalidateDocumentHandles(url);
323323
}
324-
} );
324+
}, url );
325325

326326
}
327327

src/global.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,14 @@ XML3D.util = require("./utils/misc.js");
4848
XML3D.options = require("./utils/options.js");
4949
XML3D.materials = require("./renderer/webgl/materials/urn/registery.js");
5050
XML3D.resource = require("./base/resourcemanager.js").Resource; //Required for the test library because the RM needs to "belong" to the same document as the XML3D element in order to resolve references correctly
51+
5152
XML3D.resource.registerFormat = require("./base/resourcemanager.js").registerFormat;
53+
XML3D.resource.Asset = require("./asset/asset.js").Asset;
54+
XML3D.resource.SubData = require("./asset/asset.js").SubData;
5255
//XML3D.resource.FormatHandler
5356
//XML3D.resource.JSONFormatHandler
5457
//XML3D.resource.AdapterFactory
58+
5559
XML3D.webcl = require("./utils/webcl.js").webcl;
5660
XML3D.math = require("gl-matrix");
5761
require("./math/math.js")(XML3D.math);

src/interface/configuration.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ classInfo['group'] = {
179179
onkeydown: {a: handlers.EventAttributeHandler},
180180
onkeyup: {a: handlers.EventAttributeHandler},
181181
getWorldMatrix: {m: methods.XML3DGraphTypeGetWorldMatrix},
182-
getLocalMatrix: {m: methods.groupGetLocalMatrix},
182+
getLocalMatrix: {m: methods.XML3DGraphTypeGetLocalMatrix},
183183
getWorldBoundingBox : {m: methods.getWorldBoundingBox},
184184
getLocalBoundingBox : {m: methods.getLocalBoundingBox},
185185
transform: {a: handlers.StringAttributeHandler},
@@ -209,6 +209,7 @@ classInfo['mesh'] = {
209209
transform: {a: handlers.StringAttributeHandler},
210210
material: {a: handlers.StringAttributeHandler},
211211
getWorldMatrix: {m: methods.XML3DGraphTypeGetWorldMatrix},
212+
getLocalMatrix: {m: methods.XML3DGraphTypeGetLocalMatrix},
212213
getWorldBoundingBox : {m: methods.getWorldBoundingBox},
213214
getLocalBoundingBox : {m: methods.getLocalBoundingBox},
214215
getOutputNames: {m: methods.meshGetOutputNames},
@@ -237,6 +238,7 @@ classInfo['model'] = {
237238
complete: {p: properties.AssetComplete},
238239
progressLevel: {p: properties.AssetProgressLevel},
239240
getWorldMatrix: {m: methods.XML3DGraphTypeGetWorldMatrix},
241+
getLocalMatrix: {m: methods.XML3DGraphTypeGetLocalMatrix},
240242
getWorldBoundingBox : {m: methods.getWorldBoundingBox},
241243
getLocalBoundingBox : {m: methods.getLocalBoundingBox},
242244
src: {a: handlers.StringAttributeHandler},
@@ -290,6 +292,7 @@ classInfo['light'] = {
290292
onkeyup: {a: handlers.EventAttributeHandler},
291293
global: {a: handlers.BoolAttributeHandler, params: false},
292294
getWorldMatrix: {m: methods.XML3DGraphTypeGetWorldMatrix},
295+
getLocalMatrix: {m: methods.XML3DGraphTypeGetLocalMatrix},
293296
onload: {a: handlers.EventAttributeHandler},
294297
onprogress: {a: handlers.EventAttributeHandler},
295298
complete: {p: properties.XML3DNestedDataContainerTypeComplete},
@@ -525,6 +528,7 @@ classInfo['view'] = {
525528
onkeydown: {a: handlers.EventAttributeHandler},
526529
onkeyup: {a: handlers.EventAttributeHandler},
527530
getWorldMatrix: {m: methods.XML3DGraphTypeGetWorldMatrix},
531+
getLocalMatrix: {m: methods.XML3DGraphTypeGetLocalMatrix},
528532
getProjectionMatrix:{m: methods.viewGetProjectionMatrix},
529533
getViewMatrix: {m: methods.viewGetViewMatrix}
530534
};

src/interface/methods.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -71,17 +71,6 @@ methods.xml3dGenerateRay = function(x, y) {
7171
return new XML3D.Ray();
7272
};
7373

74-
methods.groupGetLocalMatrix = function() {
75-
XML3D.flushDOMChanges();
76-
var adapters = this._configured.adapters || {};
77-
for ( var adapter in adapters) {
78-
if (adapters[adapter].getLocalMatrix) {
79-
return adapters[adapter].getLocalMatrix();
80-
}
81-
}
82-
return new Mat4();
83-
};
84-
8574
/**
8675
* return the bounding box of the owning space in world space
8776
*/
@@ -137,6 +126,17 @@ methods.XML3DGraphTypeGetWorldMatrix = function() {
137126
return new Mat4();
138127
};
139128

129+
methods.XML3DGraphTypeGetLocalMatrix = function() {
130+
XML3D.flushDOMChanges();
131+
var adapters = this._configured.adapters || {};
132+
for ( var adapter in adapters) {
133+
if (adapters[adapter].getLocalMatrix) {
134+
return adapters[adapter].getLocalMatrix();
135+
}
136+
}
137+
return new Mat4();
138+
};
139+
140140
methods.videoPlay = function() {
141141
sendAdapterEvent(this, {play: []});
142142
};

src/renderer/webgl/base/texture.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ var StateMachine = require("../../../contrib/state-machine.js");
33
var SamplerConfig = require("../../../xflow/interface/data.js").SamplerConfig;
44
var XC = require("../../../xflow/interface/constants.js");
55
var uniqueObjectId = utils.getUniqueCounter();
6+
7+
/**
8+
* @type {WebGLRenderingContext}
9+
*/
610
var GL = require("../constants.js");
711

812
//noinspection JSValidateJSDoc
@@ -210,6 +214,7 @@ XML3D.extend(GLTexture.prototype, {
210214
var gl = this.context.gl;
211215
this._bind();
212216

217+
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, this.flipY);
213218
gl.texParameteri(this.textureType, gl.TEXTURE_WRAP_S, this.wrapS);
214219
gl.texParameteri(this.textureType, gl.TEXTURE_WRAP_T, this.wrapT);
215220
gl.texParameteri(this.textureType, gl.TEXTURE_MIN_FILTER, this.minFilter);
@@ -266,7 +271,7 @@ XML3D.extend(GLTexture.prototype, {
266271
this.handle = gl.createTexture();
267272
this._bind();
268273

269-
// gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true);
274+
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, opt.flipY);
270275
gl.texParameteri(this.textureType, gl.TEXTURE_WRAP_S, opt.wrapS);
271276
gl.texParameteri(this.textureType, gl.TEXTURE_WRAP_T, opt.wrapT);
272277
gl.texParameteri(this.textureType, gl.TEXTURE_MIN_FILTER, opt.minFilter);

src/types/axisangle.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
var vec4 = require("gl-matrix").vec4;
22
var Vec3 = require("./vec3.js");
3+
var Quat = require("./quat.js");
34

45
var AxisAngle = function(vec, y, z, angle) {
56
if (this instanceof AxisAngle) {

src/types/quat.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,24 +127,28 @@ Quat.fromAxisAngle = function(axis, rad) {
127127
} else {
128128
quat.setAxisAngle(out.data, axis.data ? axis.data : axis, rad);
129129
}
130+
quat.normalize(out.data, out.data);
130131
return out;
131132
};
132133

133134
Quat.fromBasis = function(x, y, z) {
134135
var out = new Quat();
135136
XML3D.math.quat.setFromBasis(out.data, x.data ? x.data : x, y.data ? y.data : y, z.data ? z.data : z);
137+
quat.normalize(out.data, out.data);
136138
return out;
137139
};
138140

139141
Quat.fromMat3 = function(m) {
140142
var out = new Quat();
141143
quat.fromMat3(out.data, m.data ? m.data : m);
144+
quat.normalize(out.data, out.data);
142145
return out;
143146
};
144147

145148
Quat.fromRotationTo = function(from, to) {
146149
var out = new Quat();
147150
quat.rotationTo(out.data, from.data ? from.data : from, to.data ? to.data : to);
151+
quat.normalize(out.data, out.data);
148152
return out;
149153
};
150154

src/xflow/interface/data.js

Lines changed: 14 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
var Base = require("../base.js");
22
var C = require("./constants.js");
3+
var assign = require('lodash.assign');
34
require("../../utils/array.js");
45

56
/**
@@ -15,53 +16,31 @@ require("../../utils/array.js");
1516
// SamplerConfig
1617
//----------------------------------------------------------------------------------------------------------------------
1718

19+
var SAMPLER_DEFAULTS = {
20+
minFilter : C.TEX_FILTER_TYPE.LINEAR,
21+
magFilter : C.TEX_FILTER_TYPE.LINEAR,
22+
wrapS : C.TEX_WRAP_TYPE.CLAMP,
23+
wrapT : C.TEX_WRAP_TYPE.CLAMP,
24+
textureType : C.TEX_TYPE.TEXTURE_2D,
25+
flipY: true,
26+
anisotropy : 1, // number of max samples for anisotropic filtering
27+
generateMipMap : 0
28+
};
1829

1930
/**
2031
* SamplerConfig is used to define sampler properties of a TextureEntry or ImageDataTextureEntry
2132
* @constructor
2233
*/
2334
var SamplerConfig = function(){
24-
this.minFilter = 0;
25-
this.magFilter = 0;
26-
this.mipFilter = 0;
27-
this.wrapS = 0;
28-
this.wrapT = 0;
29-
this.wrapU = 0;
30-
this.textureType = 0;
31-
this.colorR = 0;
32-
this.colorG = 0;
33-
this.colorB = 0;
34-
this.anisotropy = 0; // number of max samples for anisotropic filtering
35-
this.generateMipMap = 0;
35+
this.setDefaults();
3636
};
3737

3838
SamplerConfig.prototype.setDefaults = function() {
39-
this.minFilter = C.TEX_FILTER_TYPE.LINEAR;
40-
this.magFilter = C.TEX_FILTER_TYPE.LINEAR;
41-
this.mipFilter = C.TEX_FILTER_TYPE.NEAREST;
42-
this.wrapS = C.TEX_WRAP_TYPE.CLAMP;
43-
this.wrapT = C.TEX_WRAP_TYPE.CLAMP;
44-
this.wrapU = C.TEX_WRAP_TYPE.CLAMP;
45-
this.textureType = C.TEX_TYPE.TEXTURE_2D;
46-
this.colorR = 0;
47-
this.colorG = 0;
48-
this.colorB = 0;
49-
this.anisotropy = 1; // number of max samples for anisotropic filtering
50-
this.generateMipMap = 0;
39+
assign(this, SAMPLER_DEFAULTS);
5140
};
5241

5342
SamplerConfig.prototype.set = function(other) {
54-
this.minFilter = other.minFilter;
55-
this.magFilter = other.magFilter;
56-
this.mipFilter = other.mipFilter;
57-
this.wrapS = other.wrapS;
58-
this.wrapT = other.wrapT;
59-
this.wrapU = other.wrapU;
60-
this.textureType = other.textureType;
61-
this.colorR = other.colorR;
62-
this.colorG = other.colorG;
63-
this.colorB = other.colorB;
64-
this.generateMipMap = other.generateMipMap;
43+
assign(this, other);
6544
};
6645

6746

0 commit comments

Comments
 (0)