diff options
author | Jose Antonio Marquez | 2012-03-26 15:37:41 -0700 |
---|---|---|
committer | Jose Antonio Marquez | 2012-03-26 15:37:41 -0700 |
commit | 9d88d2827c6c1cc10f64575bd3c2f5f21dd0d89d (patch) | |
tree | af3b114d6a83ae62dfcead8bd61bc62efe0c9516 /assets | |
parent | b1ba63e509f77b14c05b89ea193f4d706a28ac9b (diff) | |
parent | 309dde5a8c4599cef6a1052c1ff9ee1ad8ec5858 (diff) | |
download | ninja-9d88d2827c6c1cc10f64575bd3c2f5f21dd0d89d.tar.gz |
Merge branch 'refs/heads/Ninja-Internal' into Document
Diffstat (limited to 'assets')
-rw-r--r-- | assets/canvas-runtime.js | 529 | ||||
-rw-r--r-- | assets/descriptor.json | 4 | ||||
-rw-r--r-- | assets/images/paris.png | bin | 0 -> 4108 bytes | |||
-rw-r--r-- | assets/images/powderblue.png | bin | 0 -> 176 bytes | |||
-rw-r--r-- | assets/images/raiders.png | bin | 0 -> 5674 bytes | |||
-rwxr-xr-x | assets/rdge-compiled.js | 6 | ||||
-rw-r--r-- | assets/shaders/Paris.frag.glsl | 68 |
7 files changed, 374 insertions, 233 deletions
diff --git a/assets/canvas-runtime.js b/assets/canvas-runtime.js index fd823f35..dd909e26 100644 --- a/assets/canvas-runtime.js +++ b/assets/canvas-runtime.js | |||
@@ -37,17 +37,24 @@ function CanvasDataManager() | |||
37 | for (var i=0; i<nWorlds; i++) | 37 | for (var i=0; i<nWorlds; i++) |
38 | { | 38 | { |
39 | var importStr = value[i]; | 39 | var importStr = value[i]; |
40 | var startIndex = importStr.indexOf( "id: " ); | 40 | |
41 | if (startIndex >= 0) | 41 | // there should be some version information in |
42 | // the form of 'v0.0;' Pull that off. (the trailing ';' should | ||
43 | // be in the first 24 characters). | ||
44 | var index = importStr.indexOf( ';' ); | ||
45 | if ((importStr[0] === 'v') && (index < 24)) | ||
42 | { | 46 | { |
43 | var endIndex = importStr.indexOf( "\n", startIndex ); | 47 | // JSON format. pull off the version info |
44 | if (endIndex > 0) | 48 | importStr = importStr.substr( index+1 ); |
49 | |||
50 | var jObj = JSON.parse( importStr ); | ||
51 | var id = jObj.id; | ||
52 | if (id) | ||
45 | { | 53 | { |
46 | var id = importStr.substring( startIndex+4, endIndex ); | ||
47 | var canvas = this.findCanvasWithID( id, root ); | 54 | var canvas = this.findCanvasWithID( id, root ); |
48 | if (canvas) | 55 | if (canvas) |
49 | { | 56 | { |
50 | var rt = new GLRuntime( canvas, importStr, assetPath ); | 57 | new GLRuntime( canvas, jObj, assetPath ); |
51 | } | 58 | } |
52 | } | 59 | } |
53 | } | 60 | } |
@@ -95,14 +102,15 @@ function CanvasDataManager() | |||
95 | // Class GLRuntime | 102 | // Class GLRuntime |
96 | // Manages runtime fora WebGL canvas | 103 | // Manages runtime fora WebGL canvas |
97 | /////////////////////////////////////////////////////////////////////// | 104 | /////////////////////////////////////////////////////////////////////// |
98 | function GLRuntime( canvas, importStr, assetPath ) | 105 | function GLRuntime( canvas, jObj, assetPath ) |
99 | { | 106 | { |
100 | /////////////////////////////////////////////////////////////////////// | 107 | /////////////////////////////////////////////////////////////////////// |
101 | // Instance variables | 108 | // Instance variables |
102 | /////////////////////////////////////////////////////////////////////// | 109 | /////////////////////////////////////////////////////////////////////// |
103 | this._canvas = canvas; | 110 | this._canvas = canvas; |
104 | this._context = null; | 111 | this._context = null; |
105 | this._importStr = importStr; | 112 | //this._importStr = importStr; |
113 | this._jObj = jObj; | ||
106 | 114 | ||
107 | this.renderer = null; | 115 | this.renderer = null; |
108 | this.myScene = null; | 116 | this.myScene = null; |
@@ -157,21 +165,19 @@ function GLRuntime( canvas, importStr, assetPath ) | |||
157 | /////////////////////////////////////////////////////////////////////// | 165 | /////////////////////////////////////////////////////////////////////// |
158 | this.loadScene = function() | 166 | this.loadScene = function() |
159 | { | 167 | { |
168 | var jObj = this._jObj; | ||
169 | if (!jObj.children || (jObj.children.length != 1)) | ||
170 | throw new Error( "ill-formed JSON for runtime load: " + jObj ); | ||
171 | var root = jObj.children[0]; | ||
172 | |||
160 | // parse the data | 173 | // parse the data |
161 | // the GL runtime must start with a "sceneData: " | 174 | if (jObj.scenedata) |
162 | var index = importStr.indexOf( "scenedata: " ); | ||
163 | if (index >= 0) | ||
164 | { | 175 | { |
165 | this._useWebGL = true; | 176 | this._useWebGL = true; |
166 | 177 | ||
167 | var rdgeStr = importStr.substr( index+11 ); | 178 | var rdgeStr = jObj.scenedata; |
168 | var endIndex = rdgeStr.indexOf( "endscene\n" ); | ||
169 | if (endIndex < 0) throw new Error( "ill-formed WebGL data" ); | ||
170 | var len = endIndex - index + 11; | ||
171 | rdgeStr = rdgeStr.substr( 0, endIndex ); | ||
172 | |||
173 | this.myScene.importJSON( rdgeStr ); | 179 | this.myScene.importJSON( rdgeStr ); |
174 | this.importObjects( importStr ); | 180 | this.importObjects( root ); |
175 | this.linkMaterials( this._geomRoot ); | 181 | this.linkMaterials( this._geomRoot ); |
176 | this.initMaterials(); | 182 | this.initMaterials(); |
177 | this.linkLights(); | 183 | this.linkLights(); |
@@ -179,7 +185,7 @@ function GLRuntime( canvas, importStr, assetPath ) | |||
179 | else | 185 | else |
180 | { | 186 | { |
181 | this._context = this._canvas.getContext( "2d" ); | 187 | this._context = this._canvas.getContext( "2d" ); |
182 | this.importObjects( importStr ); | 188 | this.importObjects( root ); |
183 | this.render(); | 189 | this.render(); |
184 | } | 190 | } |
185 | } | 191 | } |
@@ -277,58 +283,42 @@ function GLRuntime( canvas, importStr, assetPath ) | |||
277 | } | 283 | } |
278 | } | 284 | } |
279 | 285 | ||
280 | this.importObjects = function( importStr, parent ) | 286 | this.importObjects = function( jObj, parent ) |
281 | { | 287 | { |
282 | var index = importStr.indexOf( "OBJECT\n", 0 ); | 288 | // read the next object |
283 | while (index >= 0) | 289 | var gObj = this.importObject( jObj, parent ); |
284 | { | ||
285 | // update the string to the current object | ||
286 | importStr = importStr.substr( index+7 ); | ||
287 | |||
288 | // read the next object | ||
289 | var obj = this.importObject( importStr, parent ); | ||
290 | 290 | ||
291 | // determine if we have children | 291 | // load the children |
292 | var endIndex = importStr.indexOf( "ENDOBJECT\n" ), | 292 | if (jObj.children) |
293 | childIndex = importStr.indexOf( "OBJECT\n" ); | 293 | { |
294 | if (endIndex < 0) throw new Error( "ill-formed object data" ); | 294 | var nKids = jObj.children.length; |
295 | if ((childIndex >= 0) && (childIndex < endIndex)) | 295 | for (var i=0; i<nKids; i++) |
296 | { | 296 | { |
297 | importStr = importStr.substr( childIndex + 7 ); | 297 | var child = jObj.children[i]; |
298 | importStr = this.importObjects( importStr, obj ); | 298 | this.importObjects( child, gObj ); |
299 | endIndex = importStr.indexOf( "ENDOBJECT\n" ) | ||
300 | } | 299 | } |
301 | |||
302 | // remove the string for the object(s) just created | ||
303 | importStr = importStr.substr( endIndex ); | ||
304 | |||
305 | // get the location of the next object | ||
306 | index = importStr.indexOf( "OBJECT\n", endIndex ); | ||
307 | } | 300 | } |
308 | |||
309 | return importStr; | ||
310 | } | 301 | } |
311 | 302 | ||
312 | this.importObject = function( objStr, parent ) | 303 | this.importObject = function( jObj, parent ) |
313 | { | 304 | { |
314 | var type = Number( getPropertyFromString( "type: ", objStr ) ); | 305 | var type = jObj.type |
315 | |||
316 | var obj; | 306 | var obj; |
317 | switch (type) | 307 | switch (type) |
318 | { | 308 | { |
319 | case 1: | 309 | case 1: |
320 | obj = new RuntimeRectangle(); | 310 | obj = new RuntimeRectangle(); |
321 | obj.import( objStr, parent ); | 311 | obj.import( jObj, parent ); |
322 | break; | 312 | break; |
323 | 313 | ||
324 | case 2: // circle | 314 | case 2: // circle |
325 | obj = new RuntimeOval(); | 315 | obj = new RuntimeOval(); |
326 | obj.import( objStr, parent ); | 316 | obj.import( jObj, parent ); |
327 | break; | 317 | break; |
328 | 318 | ||
329 | case 3: // line | 319 | case 3: // line |
330 | obj = new RuntimeLine(); | 320 | obj = new RuntimeLine(); |
331 | obj.import( objStr, parent ); | 321 | obj.import( jObj, parent ); |
332 | break; | 322 | break; |
333 | 323 | ||
334 | default: | 324 | default: |
@@ -337,7 +327,7 @@ function GLRuntime( canvas, importStr, assetPath ) | |||
337 | } | 327 | } |
338 | 328 | ||
339 | if (obj) | 329 | if (obj) |
340 | this.addObject( obj ); | 330 | this.addObject( obj, parent ); |
341 | 331 | ||
342 | return obj; | 332 | return obj; |
343 | } | 333 | } |
@@ -396,17 +386,16 @@ function GLRuntime( canvas, importStr, assetPath ) | |||
396 | 386 | ||
397 | this.remapAssetFolder = function( url ) | 387 | this.remapAssetFolder = function( url ) |
398 | { | 388 | { |
399 | /* | 389 | // var searchStr = "assets/"; |
400 | var searchStr = "assets/"; | 390 | // var index = url.indexOf( searchStr ); |
401 | var index = url.indexOf( searchStr ); | 391 | // var rtnPath = url; |
402 | var rtnPath = url; | 392 | // if (index >= 0) |
403 | if (index >= 0) | 393 | // { |
404 | { | 394 | // rtnPath = url.substr( index + searchStr.length ); |
405 | rtnPath = url.substr( index + searchStr.length ); | 395 | // rtnPath = this._assetPath + rtnPath; |
406 | rtnPath = this._assetPath + rtnPath; | 396 | // } |
407 | } | 397 | // return rtnPath; |
408 | return rtnPath; | 398 | |