diff options
-rw-r--r-- | assets/canvas-runtime.js | 58 | ||||
-rwxr-xr-x | js/document/html-document.js | 12 | ||||
-rwxr-xr-x | js/helper-classes/3D/vec-utils.js | 71 |
3 files changed, 127 insertions, 14 deletions
diff --git a/assets/canvas-runtime.js b/assets/canvas-runtime.js index 655e52fa..51c1de1f 100644 --- a/assets/canvas-runtime.js +++ b/assets/canvas-runtime.js | |||
@@ -4,6 +4,8 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot | |||
4 | (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. | 4 | (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. |
5 | </copyright> */ | 5 | </copyright> */ |
6 | 6 | ||
7 | |||
8 | |||
7 | /////////////////////////////////////////////////////////////////////// | 9 | /////////////////////////////////////////////////////////////////////// |
8 | //Loading webGL/canvas data | 10 | //Loading webGL/canvas data |
9 | function initWebGl (rootElement, directory) { | 11 | function initWebGl (rootElement, directory) { |
@@ -27,7 +29,8 @@ function CanvasDataManager() | |||
27 | { | 29 | { |
28 | this.loadGLData = function(root, valueArray, assetPath ) | 30 | this.loadGLData = function(root, valueArray, assetPath ) |
29 | { | 31 | { |
30 | this._assetPath = assetPath.slice(); | 32 | if (assetPath) |
33 | this._assetPath = assetPath.slice(); | ||
31 | 34 | ||
32 | var value = valueArray; | 35 | var value = valueArray; |
33 | var nWorlds = value.length; | 36 | var nWorlds = value.length; |
@@ -118,17 +121,22 @@ function GLRuntime( canvas, importStr, assetPath ) | |||
118 | this._zFar = 100.0; | 121 | this._zFar = 100.0; |
119 | this._viewDist = 5.0; | 122 | this._viewDist = 5.0; |
120 | 123 | ||
124 | this.elapsed = 0; | ||
125 | |||
121 | this._aspect = canvas.width/canvas.height; | 126 | this._aspect = canvas.width/canvas.height; |
122 | 127 | ||
123 | this._geomRoot; | 128 | this._geomRoot = null; |
124 | 129 | ||
125 | // all "live" materials | 130 | // all "live" materials |
126 | this._materials = []; | 131 | this._materials = []; |
127 | 132 | ||
128 | // provide the mapping for the asset directory | 133 | // provide the mapping for the asset directory |
129 | this._assetPath = assetPath.slice(); | 134 | if (assetPath) |
130 | if (this._assetPath[this._assetPath.length-1] != '/') | 135 | { |
131 | this._assetPath += '/'; | 136 | this._assetPath = assetPath.slice(); |
137 | if (this._assetPath[this._assetPath.length-1] != '/') | ||
138 | this._assetPath += '/'; | ||
139 | } | ||
132 | 140 | ||
133 | /////////////////////////////////////////////////////////////////////// | 141 | /////////////////////////////////////////////////////////////////////// |
134 | // accessors | 142 | // accessors |
@@ -166,6 +174,7 @@ function GLRuntime( canvas, importStr, assetPath ) | |||
166 | this.importObjects( importStr ); | 174 | this.importObjects( importStr ); |
167 | this.linkMaterials( this._geomRoot ); | 175 | this.linkMaterials( this._geomRoot ); |
168 | this.initMaterials(); | 176 | this.initMaterials(); |
177 | this.linkLights(); | ||
169 | } | 178 | } |
170 | else | 179 | else |
171 | { | 180 | { |
@@ -221,8 +230,8 @@ function GLRuntime( canvas, importStr, assetPath ) | |||
221 | rdgeGlobalParameters.u_light0Pos.set( [5*Math.cos(this.elapsed), 5*Math.sin(this.elapsed), 20]); | 230 | rdgeGlobalParameters.u_light0Pos.set( [5*Math.cos(this.elapsed), 5*Math.sin(this.elapsed), 20]); |
222 | 231 | ||
223 | // orbit the light nodes around the boxes | 232 | // orbit the light nodes around the boxes |
224 | //this.light.setPosition([1.2*Math.cos(this.elapsed*2.0), 1.2*Math.sin(this.elapsed*2.0), 1.2*Math.cos(this.elapsed*2.0)]); | 233 | if (this.light ) this.light.setPosition([1.2*Math.cos(this.elapsed*2.0), 1.2*Math.sin(this.elapsed*2.0), 1.2*Math.cos(this.elapsed*2.0)]); |
225 | //this.light2.setPosition([-1.2*Math.cos(this.elapsed*2.0), 1.2*Math.sin(this.elapsed*2.0), -1.2*Math.cos(this.elapsed)]); | 234 | if (this.light2) this.light2.setPosition([-1.2*Math.cos(this.elapsed*2.0), 1.2*Math.sin(this.elapsed*2.0), -1.2*Math.cos(this.elapsed)]); |
226 | 235 | ||
227 | this.updateMaterials(); | 236 | this.updateMaterials(); |
228 | 237 | ||
@@ -344,6 +353,16 @@ function GLRuntime( canvas, importStr, assetPath ) | |||
344 | parent.addChild( obj ); | 353 | parent.addChild( obj ); |
345 | } | 354 | } |
346 | 355 | ||
356 | this.linkLights = function() | ||
357 | { | ||
358 | var matNode = this.findMaterialNode( "lights", this.myScene.scene ); | ||
359 | if (matNode) | ||
360 | { | ||
361 | this.light = matNode.lightChannel[1]; | ||
362 | this.light2 = matNode.lightChannel[2]; | ||
363 | } | ||
364 | } | ||
365 | |||
347 | this.linkMaterials = function( obj ) | 366 | this.linkMaterials = function( obj ) |
348 | { | 367 | { |
349 | if (!obj) return; | 368 | if (!obj) return; |
@@ -377,6 +396,7 @@ function GLRuntime( canvas, importStr, assetPath ) | |||
377 | 396 | ||
378 | this.remapAssetFolder = function( url ) | 397 | this.remapAssetFolder = function( url ) |
379 | { | 398 | { |
399 | /* | ||
380 | var searchStr = "assets/"; | 400 | var searchStr = "assets/"; |
381 | var index = url.indexOf( searchStr ); | 401 | var index = url.indexOf( searchStr ); |
382 | var rtnPath = url; | 402 | var rtnPath = url; |
@@ -386,6 +406,8 @@ function GLRuntime( canvas, importStr, assetPath ) | |||
386 | rtnPath = this._assetPath + rtnPath; | 406 | rtnPath = this._assetPath + rtnPath; |
387 | } | 407 | } |
388 | return rtnPath; | 408 | return rtnPath; |
409 | */ | ||
410 | return url; | ||
389 | } | 411 | } |
390 | 412 | ||
391 | this.findMaterialNode = function( nodeName, node ) | 413 | this.findMaterialNode = function( nodeName, node ) |
@@ -1080,7 +1102,7 @@ function RuntimeMaterial( world ) | |||
1080 | /////////////////////////////////////////////////////////////////////// | 1102 | /////////////////////////////////////////////////////////////////////// |
1081 | // Methods | 1103 | // Methods |
1082 | /////////////////////////////////////////////////////////////////////// | 1104 | /////////////////////////////////////////////////////////////////////// |
1083 | this.init = function() | 1105 | this.init = function( world ) |
1084 | { | 1106 | { |
1085 | } | 1107 | } |
1086 | 1108 | ||
@@ -1127,7 +1149,7 @@ function RuntimeFlatMaterial() | |||
1127 | }; | 1149 | }; |
1128 | 1150 | ||
1129 | 1151 | ||
1130 | this.init = function() | 1152 | this.init = function( world ) |
1131 | { | 1153 | { |
1132 | if (this._shader) | 1154 | if (this._shader) |
1133 | { | 1155 | { |
@@ -1302,7 +1324,7 @@ function RuntimeBumpMetalMaterial() | |||
1302 | this._normalTexture = this.getPropertyFromString( "normalMap: ", importStr ); | 1324 | this._normalTexture = this.getPropertyFromString( "normalMap: ", importStr ); |
1303 | } | 1325 | } |
1304 | 1326 | ||
1305 | this.init = function() | 1327 | this.init = function( world ) |
1306 | { | 1328 | { |
1307 | var material = this._materialNode; | 1329 | var material = this._materialNode; |
1308 | if (material) | 1330 | if (material) |
@@ -1322,7 +1344,6 @@ function RuntimeBumpMetalMaterial() | |||
1322 | this._diffuseTexture = world.remapAssetFolder( this._diffuseTexture ); | 1344 | this._diffuseTexture = world.remapAssetFolder( this._diffuseTexture ); |
1323 | tex = renderer.getTextureByName(this._diffuseTexture, wrap, mips ); | 1345 | tex = renderer.getTextureByName(this._diffuseTexture, wrap, mips ); |
1324 | if (tex) technique.u_colMap.set( tex ); | 1346 | if (tex) technique.u_colMap.set( tex ); |
1325 | |||
1326 | } | 1347 | } |
1327 | if (this._normalTexture) | 1348 | if (this._normalTexture) |
1328 | { | 1349 | { |
@@ -1344,6 +1365,21 @@ function RuntimeBumpMetalMaterial() | |||
1344 | 1365 | ||
1345 | function RuntimeUberMaterial() | 1366 | function RuntimeUberMaterial() |
1346 | { | 1367 | { |
1368 | // inherit the members of RuntimeMaterial | ||
1369 | this.inheritedFrom = RuntimeMaterial; | ||
1370 | this.inheritedFrom(); | ||
1371 | |||
1372 | this.init = function( ) | ||
1373 | { | ||
1374 | } | ||
1375 | |||
1376 | this.update = function( time ) | ||
1377 | { | ||
1378 | } | ||
1379 | |||
1380 | this.import = function( importStr ) | ||
1381 | { | ||
1382 | } | ||
1347 | } | 1383 | } |
1348 | 1384 | ||
1349 | function RuntimePlasmaMaterial() | 1385 | function RuntimePlasmaMaterial() |
diff --git a/js/document/html-document.js b/js/document/html-document.js index 051490f5..f4ec3184 100755 --- a/js/document/html-document.js +++ b/js/document/html-document.js | |||
@@ -207,9 +207,17 @@ exports.HTMLDocument = Montage.create(TextDocument, { | |||
207 | }, | 207 | }, |
208 | set: function(value) { | 208 | set: function(value) { |
209 | var elt = this.documentRoot; | 209 | var elt = this.documentRoot; |
210 | if (elt) { | 210 | if (elt) |
211 | { | ||
211 | var nWorlds= value.length; | 212 | var nWorlds= value.length; |
212 | for (var i=0; i<nWorlds; i++) { | 213 | for (var i=0; i<nWorlds; i++) |
214 | { | ||
215 | /* | ||
216 | // Use this code to test the runtime version of WebGL | ||
217 | var cdm = new CanvasDataManager(); | ||
218 | cdm.loadGLData(elt, value, null ); | ||
219 | */ | ||
220 | |||
213 | var importStr = value[i]; | 221 | var importStr = value[i]; |
214 | var startIndex = importStr.indexOf( "id: " ); | 222 | var startIndex = importStr.indexOf( "id: " ); |
215 | if (startIndex >= 0) { | 223 | if (startIndex >= 0) { |
diff --git a/js/helper-classes/3D/vec-utils.js b/js/helper-classes/3D/vec-utils.js index 3db95ab7..e6db4a8d 100755 --- a/js/helper-classes/3D/vec-utils.js +++ b/js/helper-classes/3D/vec-utils.js | |||
@@ -191,5 +191,74 @@ var VecUtils = exports.VecUtils = Object.create(Object.prototype, | |||
191 | 191 | ||
192 | return vec; | 192 | return vec; |
193 | } | 193 | } |
194 | } | 194 | }, |
195 | |||
196 | matI : | ||
197 | { | ||
198 | value: function(dimen) | ||
199 | { | ||
200 | var mat = []; | ||
201 | for (var i=0; i<dimen*dimen; i++) mat.push(0); | ||
202 | |||
203 | var index = 0; | ||
204 | for (var i=0; i<dimen; i++) | ||
205 | { | ||
206 | mat[index] = 1.0; | ||
207 | index += dimen + 1; | ||
208 | } | ||
209 | |||
210 | return mat; | ||
211 | } | ||