aboutsummaryrefslogtreecommitdiff
path: root/assets
diff options
context:
space:
mode:
authorJose Antonio Marquez Russo2012-03-09 13:44:58 -0800
committerJose Antonio Marquez Russo2012-03-09 13:44:58 -0800
commitaf4b43723df785c946abae90d44269e819d55d71 (patch)
tree761159dc0056354c231d3bfb4f851bfdcea4b462 /assets
parent5da69dfd30f353ff753cba9322744e2f33f32a1a (diff)
parente92a6da7b84c58803489d70efedf74837ddfe4cd (diff)
downloadninja-af4b43723df785c946abae90d44269e819d55d71.tar.gz
Merge pull request #32 from ericmueller/integration
Added asset folder replacement to runtime load.
Diffstat (limited to 'assets')
-rw-r--r--assets/CanvasRuntime.js34
1 files changed, 29 insertions, 5 deletions
diff --git a/assets/CanvasRuntime.js b/assets/CanvasRuntime.js
index d16613ca..5caf72ee 100644
--- a/assets/CanvasRuntime.js
+++ b/assets/CanvasRuntime.js
@@ -11,8 +11,10 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot
11/////////////////////////////////////////////////////////////////////// 11///////////////////////////////////////////////////////////////////////
12function CanvasDataManager() 12function CanvasDataManager()
13{ 13{
14 this.loadGLData = function(root, valueArray ) 14 this.loadGLData = function(root, valueArray, assetPath )
15 { 15 {
16 this._assetPath = assetPath.slice();
17
16 var value = valueArray; 18 var value = valueArray;
17 var nWorlds = value.length; 19 var nWorlds = value.length;
18 for (var i=0; i<nWorlds; i++) 20 for (var i=0; i<nWorlds; i++)
@@ -28,7 +30,7 @@ function CanvasDataManager()
28 var canvas = this.findCanvasWithID( id, root ); 30 var canvas = this.findCanvasWithID( id, root );
29 if (canvas) 31 if (canvas)
30 { 32 {
31 var rt = new GLRuntime( canvas, importStr ); 33 var rt = new GLRuntime( canvas, importStr, assetPath );
32 } 34 }
33 } 35 }
34 } 36 }
@@ -76,7 +78,7 @@ function CanvasDataManager()
76// Class GLRuntime 78// Class GLRuntime
77// Manages runtime fora WebGL canvas 79// Manages runtime fora WebGL canvas
78/////////////////////////////////////////////////////////////////////// 80///////////////////////////////////////////////////////////////////////
79function GLRuntime( canvas, importStr ) 81function GLRuntime( canvas, importStr, assetPath )
80{ 82{
81 /////////////////////////////////////////////////////////////////////// 83 ///////////////////////////////////////////////////////////////////////
82 // Instance variables 84 // Instance variables
@@ -109,6 +111,11 @@ function GLRuntime( canvas, importStr )
109 // all "live" materials 111 // all "live" materials
110 this._materials = []; 112 this._materials = [];
111 113
114 // provide the mapping for the asset directory
115 this._assetPath = assetPath.slice();
116 if (this._assetPath[this._assetPath.length-1] != '/')
117 this._assetPath += '/';
118
112 /////////////////////////////////////////////////////////////////////// 119 ///////////////////////////////////////////////////////////////////////
113 // accessors 120 // accessors
114 /////////////////////////////////////////////////////////////////////// 121 ///////////////////////////////////////////////////////////////////////
@@ -350,10 +357,23 @@ function GLRuntime( canvas, importStr )
350 for (var i=0; i<nMats; i++) 357 for (var i=0; i<nMats; i++)
351 { 358 {
352 var mat = this._materials[i]; 359 var mat = this._materials[i];
353 mat.init(); 360 mat.init( this );
354 } 361 }
355 } 362 }
356 363
364 this.remapAssetFolder = function( url )
365 {
366 var searchStr = "assets/";
367 var index = url.indexOf( searchStr );
368 var rtnPath = url;
369 if (index >= 0)
370 {
371 rtnPath = url.substr( index + searchStr.length );
372 rtnPath = this._assetPath + rtnPath;
373 }
374 return rtnPath;
375 }
376
357 this.findMaterialNode = function( nodeName, node ) 377 this.findMaterialNode = function( nodeName, node )
358 { 378 {
359 if (node.transformNode) 379 if (node.transformNode)
@@ -1121,7 +1141,7 @@ function RuntimePulseMaterial()
1121 this._texMap = this.getPropertyFromString( "texture: ", importStr ); 1141 this._texMap = this.getPropertyFromString( "texture: ", importStr );
1122 } 1142 }
1123 1143
1124 this.init = function() 1144 this.init = function( world )
1125 { 1145 {
1126 var material = this._materialNode; 1146 var material = this._materialNode;
1127 if (material) 1147 if (material)
@@ -1136,6 +1156,7 @@ function RuntimePulseMaterial()
1136 technique.u_resolution.set( res ); 1156 technique.u_resolution.set( res );
1137 1157
1138 var wrap = 'REPEAT', mips = true; 1158 var wrap = 'REPEAT', mips = true;
1159 this._texMap = world.remapAssetFolder( this._texMap );
1139 var tex = renderer.getTextureByName(this._texMap, wrap, mips ); 1160 var tex = renderer.getTextureByName(this._texMap, wrap, mips );
1140 if (tex) 1161 if (tex)
1141 technique.u_tex0.set( tex ); 1162 technique.u_tex0.set( tex );
@@ -1284,17 +1305,20 @@ function RuntimeBumpMetalMaterial()
1284 var wrap = 'REPEAT', mips = true; 1305 var wrap = 'REPEAT', mips = true;
1285 if (this._diffuseTexture) 1306 if (this._diffuseTexture)
1286 { 1307 {
1308 this._diffuseTexture = world.remapAssetFolder( this._diffuseTexture );
1287 tex = renderer.getTextureByName(this._diffuseTexture, wrap, mips ); 1309 tex = renderer.getTextureByName(this._diffuseTexture, wrap, mips );
1288 if (tex) technique.u_colMap.set( tex ); 1310 if (tex) technique.u_colMap.set( tex );
1289 1311
1290 } 1312 }
1291 if (this._normalTexture) 1313 if (this._normalTexture)
1292 { 1314 {
1315 this._normalTexture = world.remapAssetFolder( this._normalTexture );
1293 tex = renderer.getTextureByName(this._normalTexture, wrap, mips ); 1316 tex = renderer.getTextureByName(this._normalTexture, wrap, mips );
1294 if (tex) technique.u_normalMap.set( tex ); 1317 if (tex) technique.u_normalMap.set( tex );
1295 } 1318 }
1296 if (this._specularTexture) 1319 if (this._specularTexture)
1297 { 1320 {
1321 this._specularTexture = world.remapAssetFolder( this._specularTexture );
1298 tex = renderer.getTextureByName(this._specularTexture, wrap, mips ); 1322 tex = renderer.getTextureByName(this._specularTexture, wrap, mips );
1299 technique.u_glowMap.set( tex ); 1323 technique.u_glowMap.set( tex );
1300 } 1324 }