aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhwc4872012-03-16 15:17:53 -0700
committerhwc4872012-03-16 15:17:53 -0700
commit55b2231d7badec16990b63ef1b6c770ef1e6fc25 (patch)
tree62d555dc627d30be8d7aec49e36935baca4e7fc3
parent2ac5db3bb1bcee887d6dd742e6c0273abb5366bd (diff)
downloadninja-55b2231d7badec16990b63ef1b6c770ef1e6fc25.tar.gz
Supporting new and old GL data formats.
-rw-r--r--assets/canvas-runtime.js22
-rwxr-xr-xjs/document/html-document.js68
-rwxr-xr-xjs/lib/drawing/world.js9
-rwxr-xr-xjs/lib/geom/geom-obj.js67
4 files changed, 97 insertions, 69 deletions
diff --git a/assets/canvas-runtime.js b/assets/canvas-runtime.js
index dd4ad6f9..adff0e8c 100644
--- a/assets/canvas-runtime.js
+++ b/assets/canvas-runtime.js
@@ -37,15 +37,25 @@ 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 jObj = JSON.parse( importStr );
41 40
42 var id = jObj.id; 41 // there should be some version information in
43 if (id) 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))
44 { 46 {
45 var canvas = this.findCanvasWithID( id, root ); 47 // JSON format. pull off the version info
46 if (canvas) 48 importStr = importStr.substr( index+1 );
49
50 var jObj = JSON.parse( importStr );
51 var id = jObj.id;
52 if (id)
47 { 53 {
48 new GLRuntime( canvas, jObj, assetPath ); 54 var canvas = this.findCanvasWithID( id, root );
55 if (canvas)
56 {
57 new GLRuntime( canvas, jObj, assetPath );
58 }
49 } 59 }
50 } 60 }
51 } 61 }
diff --git a/js/document/html-document.js b/js/document/html-document.js
index bf03e38b..bb54874c 100755
--- a/js/document/html-document.js
+++ b/js/document/html-document.js
@@ -215,30 +215,59 @@ exports.HTMLDocument = Montage.create(TextDocument, {
215 */ 215 */
216 216
217 // /* 217 // /*
218 // get the data for the next canvas
218 var importStr = value[i]; 219 var importStr = value[i];
219 var jObj = JSON.parse( importStr ); 220
220 if (jObj) 221 // determine if it is the new (JSON) or old style format
222 var id = null;
223 var jObj = null;
224 var index = importStr.indexOf( ';' );
225 if ((importStr[0] === 'v') && (index < 24))
226 {
227 // JSON format. pull off the
228 importStr = importStr.substr( index+1 );
229 jObj = jObj = JSON.parse( importStr );
230 id = jObj.id;
231 }
232 else
221 { 233 {
222 var id = jObj.id; 234 var startIndex = importStr.indexOf( "id: " );
223 if (id) 235 if (startIndex >= 0) {
236 var endIndex = importStr.indexOf( "\n", startIndex );
237 if (endIndex > 0)
238 id = importStr.substring( startIndex+4, endIndex );
239 }
240 }
241
242 if (id != null)
243 {
244 var canvas = this.findCanvasWithID( id, elt );
245 if (canvas)
224 { 246 {
225 var canvas = this.findCanvasWithID( id, elt ); 247 if (!canvas.elementModel)
226 if (canvas) { 248 {
227 if (!canvas.elementModel) { 249 NJUtils.makeElementModel(canvas, "Canvas", "shape", true);
228 NJUtils.makeElementModel(canvas, "Canvas", "shape", true); 250 }
251 if (canvas.elementModel)
252 {
253 if (canvas.elementModel.shapeModel.GLWorld)
254 canvas.elementModel.shapeModel.GLWorld.clearTree();
255
256 if (jObj)
257 {
258 var useWebGL = jObj.webGL;
259 var world = new GLWorld( canvas, useWebGL );
260 world.importJSON( jObj );
229 } 261 }
230 if (canvas.elementModel) { 262 else
231 if (canvas.elementModel.shapeModel.GLWorld) { 263 {
232 canvas.elementModel.shapeModel.GLWorld.clearTree(); 264 var index = importStr.indexOf( "webGL: " );
233 } 265 var useWebGL = (index >= 0);
234 if (jObj) 266 var world = new GLWorld( canvas, useWebGL );
235 { 267 world.import( importStr );
236 var useWebGL = jObj.webGL;
237 var world = new GLWorld( canvas, useWebGL );
238 world.importJSON( jObj );
239 this.buildShapeModel( canvas.elementModel, world );
240 }
241 } 268 }
269
270 this.buildShapeModel( canvas.elementModel, world );
242 } 271 }
243 } 272 }
244 } 273 }
@@ -380,6 +409,7 @@ exports.HTMLDocument = Montage.create(TextDocument, {
380 if (elt.elementModel && elt.elementModel.shapeModel && elt.elementModel.shapeModel.GLWorld) 409 if (elt.elementModel && elt.elementModel.shapeModel && elt.elementModel.shapeModel.GLWorld)
381 { 410 {
382 var data = elt.elementModel.shapeModel.GLWorld.exportJSON(); 411 var data = elt.elementModel.shapeModel.GLWorld.exportJSON();
412 //var data = elt.elementModel.shapeModel.GLWorld.export();
383 dataArray.push( data ); 413 dataArray.push( data );
384 } 414 }
385 415
diff --git a/js/lib/drawing/world.js b/js/lib/drawing/world.js
index 4b117242..0ee66abe 100755
--- a/js/lib/drawing/world.js
+++ b/js/lib/drawing/world.js
@@ -754,7 +754,14 @@ World.prototype.exportJSON = function()
754 // convert the object to a string 754 // convert the object to a string
755 var jStr = JSON.stringify( worldObj ); 755 var jStr = JSON.stringify( worldObj );
756 756
757 // the RDGE export function corrupts the data. 757 // prepend some version information to the string.
758 // this string is also used to differentiate between JSON
759 // and pre-JSON versions of fileIO.
760 // the ending ';' in the version string is necessary
761 jStr = "v1.0;" + jStr;
762
763 // You would think that the RDGE export function
764 // would not change the data. You would be wrong...
758 // rebuild the tree 765 // rebuild the tree
759 var root = this._rootNode; 766 var root = this._rootNode;
760 root.children = new Array(); 767 root.children = new Array();
diff --git a/js/lib/geom/geom-obj.js b/js/lib/geom/geom-obj.js
index a4813326..63f71955 100755
--- a/js/lib/geom/geom-obj.js
+++ b/js/lib/geom/geom-obj.js
@@ -5,28 +5,6 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot
5</copyright> */ 5</copyright> */
6 6
7var MaterialsModel = require("js/models/materials-model").MaterialsModel; 7var MaterialsModel = require("js/models/materials-model").MaterialsModel;
8/*
9var FlatMaterial = require("js/lib/rdge/materials/flat-material").FlatMaterial;
10var LinearGradientMaterial = require("js/lib/rdge/materials/linear-gradient-material").LinearGradientMaterial;
11var RadialGradientMaterial = require("js/lib/rdge/materials/radial-gradient-material").RadialGradientMaterial;
12var BumpMetalMaterial = require("js/lib/rdge/materials/bump-metal-material").BumpMetalMaterial;
13var UberMaterial = require("js/lib/rdge/materials/uber-material").UberMaterial;
14var RadialBlurMaterial = require("js/lib/rdge/materials/radial-blur-material").RadialBlurMaterial;
15var PlasmaMaterial = require("js/lib/rdge/materials/plasma-material").PlasmaMaterial;
16var PulseMaterial = require("js/lib/rdge/materials/pulse-material").PulseMaterial;
17var TunnelMaterial = require("js/lib/rdge/materials/tunnel-material").TunnelMaterial;
18var ReliefTunnelMaterial = require("js/lib/rdge/materials/relief-tunnel-material").ReliefTunnelMaterial;
19var SquareTunnelMaterial = require("js/lib/rdge/materials/square-tunnel-material").SquareTunnelMaterial;
20var FlyMaterial = require("js/lib/rdge/materials/fly-material").FlyMaterial;
21var WaterMaterial = require("js/lib/rdge/materials/water-material").WaterMaterial;
22var ZInvertMaterial = require("js/lib/rdge/materials/z-invert-material").ZInvertMaterial;
23var DeformMaterial = require("js/lib/rdge/materials/deform-material").DeformMaterial;
24var StarMaterial = require("js/lib/rdge/materials/star-material").StarMaterial;
25var TwistMaterial = require("js/lib/rdge/materials/twist-material").TwistMaterial;
26var JuliaMaterial = require("js/lib/rdge/materials/julia-material").JuliaMaterial;
27var KeleidoscopeMaterial = require("js/lib/rdge/materials/keleidoscope-material").KeleidoscopeMaterial;
28var MandelMaterial = require("js/lib/rdge/materials/mandel-material").MandelMaterial;
29*/
30 8
31/////////////////////////////////////////////////////////////////////// 9///////////////////////////////////////////////////////////////////////
32// Class GLGeomObj 10// Class GLGeomObj
@@ -335,7 +313,7 @@ var GeomObj = function GLGeomObj() {
335 break; 313 break;
336 314
337 default: 315 default:
338 console.log( "material type: " + materialType + " is not supported" ); 316 console.log( "material type: " + shaderName + " is not supported" );
339 break; 317 break;
340 } 318 }
341 319
@@ -375,26 +353,29 @@ var GeomObj = function GLGeomObj() {
375 var materialType = this.getPropertyFromString( "material: ", importStr ); 353 var materialType = this.getPropertyFromString( "material: ", importStr );
376 switch (materialType) 354 switch (materialType)
377 { 355 {
378 case "flat": mat = new FlatMaterial(); break; 356 case "flat":
379 case "radialGradient": mat = new RadialGradientMaterial(); break; 357 case "radialGradient":
380 case "linearGradient": mat = new LinearGradientMaterial(); break; 358 case "linearGradient":
381 case "bumpMetal": mat = new BumpMetalMaterial(); break; 359 case "bumpMetal":
382 case "uber": mat = new UberMaterial(); break; 360 case "uber":
383 case "plasma": mat = new PlasmaMaterial(); break; 361 case "plasma":
384 case "deform": mat = new DeformMaterial(); break; 362 case "deform":
385 case "water": mat = new WaterMaterial(); break; 363 case "water":
386 case "tunnel": mat = new TunnelMaterial(); break; 364 case "tunnel":