diff options
author | Jonathan Duran | 2012-03-23 07:24:39 -0700 |
---|---|---|
committer | Jonathan Duran | 2012-03-23 07:24:39 -0700 |
commit | 846d539997bf188b9caf63cdf0008367fe6c9ede (patch) | |
tree | ae0ed9293cd5859cd10694fb2e045b2101ed8df8 /assets | |
parent | 595a569cf459e7e7cbe19e546c23322b56e44341 (diff) | |
parent | 57cc00a5ef3ab525e54a030d7692b2d9eefaa68b (diff) | |
download | ninja-846d539997bf188b9caf63cdf0008367fe6c9ede.tar.gz |
Merge branch 'refs/heads/NINJAmaster' into TimelineUber
Diffstat (limited to 'assets')
-rw-r--r-- | assets/canvas-runtime.js | 243 |
1 files changed, 215 insertions, 28 deletions
diff --git a/assets/canvas-runtime.js b/assets/canvas-runtime.js index 655e52fa..fd823f35 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 ) |
@@ -482,20 +504,7 @@ function RuntimeGeomObj() | |||
482 | 504 | ||
483 | /////////////////////////////////////////////////////////////////////// | 505 | /////////////////////////////////////////////////////////////////////// |
484 | // Methods | 506 | // Methods |
485 | /////////////////////////////////////////////////////////////////////// | 507 | /////////////////////////////////////////////////////////////////////// |
486 | this.makeStrokeMaterial = function() | ||
487 | { | ||
488 | } | ||
489 | |||
490 | this.makeFillMaterial = function() | ||
491 | { | ||
492 | } | ||
493 | |||
494 | |||
495 | this.render = function() | ||
496 | { | ||
497 | } | ||
498 | |||
499 | this.addChild = function( child ) | 508 | this.addChild = function( child ) |
500 | { | 509 | { |
501 | if (!this._children) this._children = []; | 510 | if (!this._children) this._children = []; |
@@ -551,9 +560,10 @@ function RuntimeGeomObj() | |||
551 | this._materials.push( mat ); | 560 | this._materials.push( mat ); |
552 | } | 561 | } |
553 | 562 | ||
554 | var endIndex = importStr.indexOf( "endMaterial\n" ); | 563 | var endKey = "endMaterial\n"; |
564 | var endIndex = importStr.indexOf( endKey ); | ||
555 | if (endIndex < 0) break; | 565 | if (endIndex < 0) break; |
556 | importStr = importStr.substr( endIndex ); | 566 | importStr = importStr.substr( endIndex + endKey.length ); |
557 | } | 567 | } |
558 | } | 568 | } |
559 | 569 | ||
@@ -1080,7 +1090,7 @@ function RuntimeMaterial( world ) | |||
1080 | /////////////////////////////////////////////////////////////////////// | 1090 | /////////////////////////////////////////////////////////////////////// |
1081 | // Methods | 1091 | // Methods |
1082 | /////////////////////////////////////////////////////////////////////// | 1092 | /////////////////////////////////////////////////////////////////////// |
1083 | this.init = function() | 1093 | this.init = function( world ) |
1084 | { | 1094 | { |
1085 | } | 1095 | } |
1086 | 1096 | ||
@@ -1127,7 +1137,7 @@ function RuntimeFlatMaterial() | |||
1127 | }; | 1137 | }; |
1128 | 1138 | ||
1129 | 1139 | ||
1130 | this.init = function() | 1140 | this.init = function( world ) |
1131 | { | 1141 | { |
1132 | if (this._shader) | 1142 | if (this._shader) |
1133 | { | 1143 | { |
@@ -1302,7 +1312,7 @@ function RuntimeBumpMetalMaterial() | |||
1302 | this._normalTexture = this.getPropertyFromString( "normalMap: ", importStr ); | 1312 | this._normalTexture = this.getPropertyFromString( "normalMap: ", importStr ); |
1303 | } | 1313 | } |
1304 | 1314 | ||
1305 | this.init = function() | 1315 | this.init = function( world ) |
1306 | { | 1316 | { |
1307 | var material = this._materialNode; | 1317 | var material = this._materialNode; |
1308 | if (material) | 1318 | if (material) |
@@ -1322,7 +1332,6 @@ function RuntimeBumpMetalMaterial() | |||
1322 | this._diffuseTexture = world.remapAssetFolder( this._diffuseTexture ); | 1332 | this._diffuseTexture = world.remapAssetFolder( this._diffuseTexture ); |
1323 | tex = renderer.getTextureByName(this._diffuseTexture, wrap, mips ); | 1333 | tex = renderer.getTextureByName(this._diffuseTexture, wrap, mips ); |
1324 | if (tex) technique.u_colMap.set( tex ); | 1334 | if (tex) technique.u_colMap.set( tex ); |
1325 | |||
1326 | } | 1335 | } |
1327 | if (this._normalTexture) | 1336 | if (this._normalTexture) |
1328 | { | 1337 | { |
@@ -1344,6 +1353,184 @@ function RuntimeBumpMetalMaterial() | |||
1344 | 1353 | ||
1345 | function RuntimeUberMaterial() | 1354 | function RuntimeUberMaterial() |
1346 | { | 1355 | { |
1356 | // inherit the members of RuntimeMaterial | ||
1357 | this.inheritedFrom = RuntimeMaterial; | ||
1358 | this.inheritedFrom(); | ||
1359 | |||
1360 | this._MAX_LIGHTS = 4; | ||
1361 | |||
1362 | this.init = function( ) | ||
1363 | { | ||
1364 | var material = this._materialNode; | ||
1365 | if (material) | ||
1366 | { | ||
1367 | var technique = material.shaderProgram.defaultTechnique; | ||
1368 | var renderer = g_Engine.getContext().renderer; | ||
1369 | if (renderer && technique) | ||
1370 | { | ||
1371 | if (this._shader && this._shader.defaultTechnique) | ||
1372 | { | ||
1373 | if (this._ambientColor && technique.u_ambientColor) technique.u_ambientColor.set(this._ambientColor ); | ||
1374 | if (this._diffuseColor && technique.u_diffuseColor ) technique.u_diffuseColor.set(this._diffuseColor ); | ||
1375 | if (this._specularColor && technique.u_specularColor) technique.u_specularColor.set(this._specularColor); | ||
1376 | if (this._specularPower && technique.u_specularPower) technique.u_specularPower.set([this._specularPower]); | ||
1377 | |||
1378 | if (this._lights) | ||
1379 | { | ||
1380 | for(var i = 0; i < 4; ++i) | ||
1381 |