diff options
author | Jose Antonio Marquez Russo | 2012-03-09 13:44:58 -0800 |
---|---|---|
committer | Jose Antonio Marquez Russo | 2012-03-09 13:44:58 -0800 |
commit | af4b43723df785c946abae90d44269e819d55d71 (patch) | |
tree | 761159dc0056354c231d3bfb4f851bfdcea4b462 | |
parent | 5da69dfd30f353ff753cba9322744e2f33f32a1a (diff) | |
parent | e92a6da7b84c58803489d70efedf74837ddfe4cd (diff) | |
download | ninja-af4b43723df785c946abae90d44269e819d55d71.tar.gz |
Merge pull request #32 from ericmueller/integration
Added asset folder replacement to runtime load.
-rw-r--r-- | assets/CanvasRuntime.js | 34 | ||||
-rwxr-xr-x | js/document/html-document.js | 6 | ||||
-rwxr-xr-x | js/lib/drawing/world.js | 23 | ||||
-rwxr-xr-x | js/lib/rdge/materials/bump-metal-material.js | 6 | ||||
-rw-r--r-- | js/lib/rdge/materials/pulse-material.js | 2 | ||||
-rw-r--r-- | js/lib/rdge/materials/radial-blur-material.js | 2 | ||||
-rwxr-xr-x | js/lib/rdge/materials/uber-material.js | 8 |
7 files changed, 42 insertions, 39 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 | /////////////////////////////////////////////////////////////////////// |
12 | function CanvasDataManager() | 12 | function 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 | /////////////////////////////////////////////////////////////////////// |
79 | function GLRuntime( canvas, importStr ) | 81 | function 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 | } |
diff --git a/js/document/html-document.js b/js/document/html-document.js index aa56fd0e..f57c61ee 100755 --- a/js/document/html-document.js +++ b/js/document/html-document.js | |||
@@ -197,7 +197,7 @@ exports.HTMLDocument = Montage.create(TextDocument, { | |||
197 | //if (path) { | 197 | //if (path) { |
198 | //this.collectGLData(elt, this._glData, path); | 198 | //this.collectGLData(elt, this._glData, path); |
199 | //} else { | 199 | //} else { |
200 | this.collectGLData(elt, this._glData, "assets/"); | 200 | this.collectGLData(elt, this._glData ); |
201 | //} | 201 | //} |
202 | } else { | 202 | } else { |
203 | this._glData = null | 203 | this._glData = null |
@@ -368,11 +368,11 @@ exports.HTMLDocument = Montage.create(TextDocument, { | |||
368 | 368 | ||
369 | 369 | ||
370 | collectGLData: { | 370 | collectGLData: { |
371 | value: function( elt, dataArray, imagePath ) | 371 | value: function( elt, dataArray ) |
372 | { | 372 | { |
373 | if (elt.elementModel && elt.elementModel.shapeModel && elt.elementModel.shapeModel.GLWorld) | 373 | if (elt.elementModel && elt.elementModel.shapeModel && elt.elementModel.shapeModel.GLWorld) |
374 | { | 374 | { |
375 | var data = elt.elementModel.shapeModel.GLWorld.export( imagePath ); | 375 | var data = elt.elementModel.shapeModel.GLWorld.export(); |
376 | dataArray.push( data ); | 376 | dataArray.push( data ); |
377 | } | 377 | } |
378 | 378 | ||
diff --git a/js/lib/drawing/world.js b/js/lib/drawing/world.js index cffd0083..44c9e37d 100755 --- a/js/lib/drawing/world.js +++ b/js/lib/drawing/world.js | |||
@@ -727,7 +727,7 @@ World.prototype.getShapeFromPoint = function( offsetX, offsetY ) { | |||
727 | } | 727 | } |
728 | }; | 728 | }; |
729 | 729 | ||
730 | World.prototype.export = function( imagePath ) | 730 | World.prototype.export = function() |
731 | { | 731 | { |
732 | var exportStr = "GLWorld 1.0\n"; | 732 | var exportStr = "GLWorld 1.0\n"; |
733 | var id = this.getCanvas().getAttribute( "data-RDGE-id" ); | 733 | var id = this.getCanvas().getAttribute( "data-RDGE-id" ); |
@@ -747,13 +747,6 @@ World.prototype.export = function( imagePath ) | |||
747 | var exportForPublish = true; | 747 | var exportForPublish = true; |
748 | exportStr += "publish: " + exportForPublish + "\n"; | 748 | exportStr += "publish: " + exportForPublish + "\n"; |
749 | 749 | ||
750 | // the relative path for local assets needs to be modified to | ||
751 | // the path specified by argument 'imagePath'. Save that path | ||
752 | // so exporting functions can call newPath = world.cleansePath( oldPath ); | ||
753 | this._imagePath = imagePath.slice(); | ||
754 | var endchar = this._imagePath[this._imagePath.length-1] | ||
755 | if (endchar != '/') this._imagePath += '/'; | ||
756 | |||
757 | if (exportForPublish && this._useWebGL) | 750 | if (exportForPublish && this._useWebGL) |
758 | { | 751 | { |
759 | exportStr += "scenedata: " + this.myScene.exportJSON() + "endscene\n"; | 752 | exportStr += "scenedata: " + this.myScene.exportJSON() + "endscene\n"; |
@@ -937,20 +930,6 @@ World.prototype.importSubObject = function( objStr, parentNode ) { | |||
937 | return trNode; | 930 | return trNode; |
938 | }; | 931 | }; |
939 | 932 | ||
940 | World.prototype.cleansePath = function( url ) | ||
941 | { | ||
942 | //this._imagePath | ||
943 | var searchStr = "assets/"; | ||
944 | var index = url.indexOf( searchStr ); | ||
945 | var rtnPath = url; | ||
946 | if (index >= 0) | ||
947 | { | ||
948 | rtnPath = url.substr( index + searchStr.length ); | ||
949 | rtnPath = this._imagePath + rtnPath; | ||
950 | } | ||
951 | return rtnPath; | ||
952 | } | ||
953 | |||
954 | if (typeof exports === "object") { | 933 | if (typeof exports === "object") { |
955 | exports.World = World; | 934 | exports.World = World; |
956 | } \ No newline at end of file | 935 | } \ No newline at end of file |
diff --git a/js/lib/rdge/materials/bump-metal-material.js b/js/lib/rdge/materials/bump-metal-material.js index 70873885..fa6f5300 100755 --- a/js/lib/rdge/materials/bump-metal-material.js +++ b/js/lib/rdge/materials/bump-metal-material.js | |||
@@ -163,9 +163,9 @@ var BumpMetalMaterial = function BumpMetalMaterial() { | |||
163 | throw new Error( "no world in material.export, " + this.getName() |