From 55b2231d7badec16990b63ef1b6c770ef1e6fc25 Mon Sep 17 00:00:00 2001 From: hwc487 Date: Fri, 16 Mar 2012 15:17:53 -0700 Subject: Supporting new and old GL data formats. --- js/document/html-document.js | 68 +++++++++++++++++++++++++++++++------------- js/lib/drawing/world.js | 9 +++++- js/lib/geom/geom-obj.js | 67 ++++++++++++++++--------------------------- 3 files changed, 81 insertions(+), 63 deletions(-) (limited to 'js') 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, { */ // /* + // get the data for the next canvas var importStr = value[i]; - var jObj = JSON.parse( importStr ); - if (jObj) + + // determine if it is the new (JSON) or old style format + var id = null; + var jObj = null; + var index = importStr.indexOf( ';' ); + if ((importStr[0] === 'v') && (index < 24)) + { + // JSON format. pull off the + importStr = importStr.substr( index+1 ); + jObj = jObj = JSON.parse( importStr ); + id = jObj.id; + } + else { - var id = jObj.id; - if (id) + var startIndex = importStr.indexOf( "id: " ); + if (startIndex >= 0) { + var endIndex = importStr.indexOf( "\n", startIndex ); + if (endIndex > 0) + id = importStr.substring( startIndex+4, endIndex ); + } + } + + if (id != null) + { + var canvas = this.findCanvasWithID( id, elt ); + if (canvas) { - var canvas = this.findCanvasWithID( id, elt ); - if (canvas) { - if (!canvas.elementModel) { - NJUtils.makeElementModel(canvas, "Canvas", "shape", true); + if (!canvas.elementModel) + { + NJUtils.makeElementModel(canvas, "Canvas", "shape", true); + } + if (canvas.elementModel) + { + if (canvas.elementModel.shapeModel.GLWorld) + canvas.elementModel.shapeModel.GLWorld.clearTree(); + + if (jObj) + { + var useWebGL = jObj.webGL; + var world = new GLWorld( canvas, useWebGL ); + world.importJSON( jObj ); } - if (canvas.elementModel) { - if (canvas.elementModel.shapeModel.GLWorld) { - canvas.elementModel.shapeModel.GLWorld.clearTree(); - } - if (jObj) - { - var useWebGL = jObj.webGL; - var world = new GLWorld( canvas, useWebGL ); - world.importJSON( jObj ); - this.buildShapeModel( canvas.elementModel, world ); - } + else + { + var index = importStr.indexOf( "webGL: " ); + var useWebGL = (index >= 0); + var world = new GLWorld( canvas, useWebGL ); + world.import( importStr ); } + + this.buildShapeModel( canvas.elementModel, world ); } } } @@ -380,6 +409,7 @@ exports.HTMLDocument = Montage.create(TextDocument, { if (elt.elementModel && elt.elementModel.shapeModel && elt.elementModel.shapeModel.GLWorld) { var data = elt.elementModel.shapeModel.GLWorld.exportJSON(); + //var data = elt.elementModel.shapeModel.GLWorld.export(); dataArray.push( data ); } 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() // convert the object to a string var jStr = JSON.stringify( worldObj ); - // the RDGE export function corrupts the data. + // prepend some version information to the string. + // this string is also used to differentiate between JSON + // and pre-JSON versions of fileIO. + // the ending ';' in the version string is necessary + jStr = "v1.0;" + jStr; + + // You would think that the RDGE export function + // would not change the data. You would be wrong... // rebuild the tree var root = this._rootNode; 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 */ var MaterialsModel = require("js/models/materials-model").MaterialsModel; -/* -var FlatMaterial = require("js/lib/rdge/materials/flat-material").FlatMaterial; -var LinearGradientMaterial = require("js/lib/rdge/materials/linear-gradient-material").LinearGradientMaterial; -var RadialGradientMaterial = require("js/lib/rdge/materials/radial-gradient-material").RadialGradientMaterial; -var BumpMetalMaterial = require("js/lib/rdge/materials/bump-metal-material").BumpMetalMaterial; -var UberMaterial = require("js/lib/rdge/materials/uber-material").UberMaterial; -var RadialBlurMaterial = require("js/lib/rdge/materials/radial-blur-material").RadialBlurMaterial; -var PlasmaMaterial = require("js/lib/rdge/materials/plasma-material").PlasmaMaterial; -var PulseMaterial = require("js/lib/rdge/materials/pulse-material").PulseMaterial; -var TunnelMaterial = require("js/lib/rdge/materials/tunnel-material").TunnelMaterial; -var ReliefTunnelMaterial = require("js/lib/rdge/materials/relief-tunnel-material").ReliefTunnelMaterial; -var SquareTunnelMaterial = require("js/lib/rdge/materials/square-tunnel-material").SquareTunnelMaterial; -var FlyMaterial = require("js/lib/rdge/materials/fly-material").FlyMaterial; -var WaterMaterial = require("js/lib/rdge/materials/water-material").WaterMaterial; -var ZInvertMaterial = require("js/lib/rdge/materials/z-invert-material").ZInvertMaterial; -var DeformMaterial = require("js/lib/rdge/materials/deform-material").DeformMaterial; -var StarMaterial = require("js/lib/rdge/materials/star-material").StarMaterial; -var TwistMaterial = require("js/lib/rdge/materials/twist-material").TwistMaterial; -var JuliaMaterial = require("js/lib/rdge/materials/julia-material").JuliaMaterial; -var KeleidoscopeMaterial = require("js/lib/rdge/materials/keleidoscope-material").KeleidoscopeMaterial; -var MandelMaterial = require("js/lib/rdge/materials/mandel-material").MandelMaterial; -*/ /////////////////////////////////////////////////////////////////////// // Class GLGeomObj @@ -335,7 +313,7 @@ var GeomObj = function GLGeomObj() { break; default: - console.log( "material type: " + materialType + " is not supported" ); + console.log( "material type: " + shaderName + " is not supported" ); break; } @@ -375,26 +353,29 @@ var GeomObj = function GLGeomObj() { var materialType = this.getPropertyFromString( "material: ", importStr ); switch (materialType) { - case "flat": mat = new FlatMaterial(); break; - case "radialGradient": mat = new RadialGradientMaterial(); break; - case "linearGradient": mat = new LinearGradientMaterial(); break; - case "bumpMetal": mat = new BumpMetalMaterial(); break; - case "uber": mat = new UberMaterial(); break; - case "plasma": mat = new PlasmaMaterial(); break; - case "deform": mat = new DeformMaterial(); break; - case "water": mat = new WaterMaterial(); break; - case "tunnel": mat = new TunnelMaterial(); break; - case "reliefTunnel": mat = new ReliefTunnelMaterial(); break; - case "squareTunnel": mat = new SquareTunnelMaterial(); break; - case "twist": mat = new TwiseMaterial(); break; - case "fly": mat = new FlyMaterial(); break; - case "julia": mat = new JuliaMaterial(); break; - case "mandel": mat = new MandelMaterial(); break; - case "star": mat = new StarMaterial(); break; - case "zinvert": mat = new ZInvertMaterial(); break; - case "keleidoscope": mat = new KeleidoscopeMaterial(); break; - case "radialBlur": mat = new RadialBlurMaterial(); break; - case "pulse": mat = new PulseMaterial(); break; + case "flat": + case "radialGradient": + case "linearGradient": + case "bumpMetal": + case "uber": + case "plasma": + case "deform": + case "water": + case "tunnel": + case "reliefTunnel": + case "squareTunnel": + case "twist": + case "fly": + case "julia": + case "mandel": + case "star": + case "zinvert": + case "keleidoscope": + case "radialBlur": + case "pulse": + mat = MaterialsModel.getMaterialByShader( materialType ); + if (mat) mat = mat.dup(); + break; default: console.log( "material type: " + materialType + " is not supported" ); -- cgit v1.2.3