From a0d23354802ebc6b437698acb4b18d3395d47cd1 Mon Sep 17 00:00:00 2001 From: hwc487 Date: Fri, 16 Mar 2012 12:26:30 -0700 Subject: Conversion to JSON based file IO for canvas2D and WebGL rendering --- js/document/html-document.js | 43 ++++++++++++++++++++----------------------- 1 file changed, 20 insertions(+), 23 deletions(-) (limited to 'js/document') diff --git a/js/document/html-document.js b/js/document/html-document.js index d4db6e2f..bf03e38b 100755 --- a/js/document/html-document.js +++ b/js/document/html-document.js @@ -194,11 +194,7 @@ exports.HTMLDocument = Montage.create(TextDocument, { // if (elt) { this._glData = []; - //if (path) { - //this.collectGLData(elt, this._glData, path); - //} else { - this.collectGLData(elt, this._glData ); - //} + this.collectGLData(elt, this._glData ); } else { this._glData = null } @@ -220,25 +216,26 @@ exports.HTMLDocument = Montage.create(TextDocument, { // /* var importStr = value[i]; - var startIndex = importStr.indexOf( "id: " ); - if (startIndex >= 0) { - var endIndex = importStr.indexOf( "\n", startIndex ); - if (endIndex > 0) { - var id = importStr.substring( startIndex+4, endIndex ); - if (id) { - var canvas = this.findCanvasWithID( id, elt ); - if (canvas) { - if (!canvas.elementModel) { - NJUtils.makeElementModel(canvas, "Canvas", "shape", true); + var jObj = JSON.parse( importStr ); + if (jObj) + { + var id = jObj.id; + if (id) + { + var canvas = this.findCanvasWithID( id, elt ); + if (canvas) { + if (!canvas.elementModel) { + NJUtils.makeElementModel(canvas, "Canvas", "shape", true); + } + if (canvas.elementModel) { + if (canvas.elementModel.shapeModel.GLWorld) { + canvas.elementModel.shapeModel.GLWorld.clearTree(); } - if (canvas.elementModel) { - if (canvas.elementModel.shapeModel.GLWorld) { - canvas.elementModel.shapeModel.GLWorld.clearTree(); - } - var index = importStr.indexOf( "webGL: " ); - var useWebGL = (index >= 0) + if (jObj) + { + var useWebGL = jObj.webGL; var world = new GLWorld( canvas, useWebGL ); - world.import( importStr ); + world.importJSON( jObj ); this.buildShapeModel( canvas.elementModel, world ); } } @@ -382,7 +379,7 @@ exports.HTMLDocument = Montage.create(TextDocument, { { if (elt.elementModel && elt.elementModel.shapeModel && elt.elementModel.shapeModel.GLWorld) { - var data = elt.elementModel.shapeModel.GLWorld.export(); + var data = elt.elementModel.shapeModel.GLWorld.exportJSON(); dataArray.push( data ); } -- cgit v1.2.3 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 +++++++++++++++++++++++++++++++------------- 1 file changed, 49 insertions(+), 19 deletions(-) (limited to 'js/document') 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 ); } -- cgit v1.2.3 From 98a02c1ac6f189aba93d7cce64ba5bdbc0617f6c Mon Sep 17 00:00:00 2001 From: hwc487 Date: Tue, 20 Mar 2012 16:26:52 -0700 Subject: Bug Fixes for Canvas & WebGL File IO --- js/document/html-document.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'js/document') diff --git a/js/document/html-document.js b/js/document/html-document.js index bb54874c..8b765501 100755 --- a/js/document/html-document.js +++ b/js/document/html-document.js @@ -291,7 +291,7 @@ exports.HTMLDocument = Montage.create(TextDocument, { shapeModel.GLGeomObj = root; shapeModel.strokeSize = root._strokeWidth; shapeModel.stroke = root._strokeColor.slice(); - shapeModel.strokeMaterial = root._strokeMaterial.dup(); + shapeModel.strokeMaterial = root._strikeMaterial ? root._strokeMaterial.dup() : null; shapeModel.strokeStyle = "solid"; //shapeModel.strokeStyleIndex //shapeModel.border @@ -302,7 +302,7 @@ exports.HTMLDocument = Montage.create(TextDocument, { elementModel.selection = "Rectangle"; elementModel.pi = "RectanglePi"; shapeModel.fill = root._fillColor.slice(); - shapeModel.fillMaterial = root._fillMaterial.dup(); + shapeModel.fillMaterial = root._fillMaterial ? root._fillMaterial.dup() : null; shapeModel.tlRadius = root._tlRadius; shapeModel.trRadius = root._trRadius; shapeModel.blRadius = root._blRadius; @@ -313,7 +313,7 @@ exports.HTMLDocument = Montage.create(TextDocument, { elementModel.selection = "Oval"; elementModel.pi = "OvalPi"; shapeModel.fill = root._fillColor.slice(); - shapeModel.fillMaterial = root._fillMaterial.dup(); + shapeModel.fillMaterial = root._fillMaterial ? root._fillMaterial.dup() : null; shapeModel.innerRadius = root._innerRadius; break; -- cgit v1.2.3 From eb59a523258cad3351cba9bf8de986e90a8e5b1c Mon Sep 17 00:00:00 2001 From: hwc487 Date: Wed, 21 Mar 2012 15:17:58 -0700 Subject: Added material library data to the canvas data. --- js/document/html-document.js | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) (limited to 'js/document') diff --git a/js/document/html-document.js b/js/document/html-document.js index 8b765501..3d109fdb 100755 --- a/js/document/html-document.js +++ b/js/document/html-document.js @@ -9,7 +9,8 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot var Montage = require("montage/core/core").Montage, TextDocument = require("js/document/text-document").TextDocument, NJUtils = require("js/lib/NJUtils").NJUtils, - GLWorld = require("js/lib/drawing/world").World; + GLWorld = require("js/lib/drawing/world").World, + MaterialsModel = require("js/models/materials-model").MaterialsModel; //////////////////////////////////////////////////////////////////////// // exports.HTMLDocument = Montage.create(TextDocument, { @@ -193,7 +194,8 @@ exports.HTMLDocument = Montage.create(TextDocument, { var elt = this.iframe.contentWindow.document.getElementById("UserContent"); // if (elt) { - this._glData = []; + var matLib = MaterialsModel.exportMaterials(); + this._glData = [matLib]; this.collectGLData(elt, this._glData ); } else { this._glData = null @@ -231,12 +233,27 @@ exports.HTMLDocument = Montage.create(TextDocument, { } else { - var startIndex = importStr.indexOf( "id: " ); - if (startIndex >= 0) { - var endIndex = importStr.indexOf( "\n", startIndex ); - if (endIndex > 0) - id = importStr.substring( startIndex+4, endIndex ); - } + // at this point the data could be either the materials library or + // an old style world. We can determine which by converting the string + // to an object via JSON.parse. That operation will fail if the string + // is an old style world. + var matLibStr = 'materialLibrary;'; + index = importStr.indexOf( matLibStr ); + if (index == 0) + { + importStr = importStr.substr( matLibStr.length ); + var matLibObj = JSON.parse( importStr ); + MaterialsModel.importMaterials( matLibObj ); + } + else + { + 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) -- cgit v1.2.3