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/lib/drawing/world.js | 31 ++++++++++++++++++--------- js/lib/geom/circle.js | 18 ---------------- js/lib/geom/geom-obj.js | 12 +++++++++++ js/lib/geom/line.js | 11 +--------- js/lib/geom/rectangle.js | 28 ++++-------------------- js/lib/rdge/materials/julia-material.js | 6 +----- js/lib/rdge/materials/mandel-material.js | 6 +----- js/lib/rdge/materials/plasma-material.js | 19 ++++++++++++++++ js/lib/rdge/materials/pulse-material.js | 1 + js/lib/rdge/materials/radial-blur-material.js | 29 ++++++++++++++++++++++--- js/lib/rdge/materials/water-material.js | 25 +++++++++++++++++++++ 11 files changed, 111 insertions(+), 75 deletions(-) (limited to 'js/lib') diff --git a/js/lib/drawing/world.js b/js/lib/drawing/world.js index 0ee66abe..0979cf12 100755 --- a/js/lib/drawing/world.js +++ b/js/lib/drawing/world.js @@ -751,6 +751,21 @@ World.prototype.exportJSON = function() var strArray = []; this.exportObjectsJSON( this._geomRoot, worldObj ); + // You would think that the RDGE export function + // would not be destructive of the data. You would be wrong... + // We need to rebuild everything + if (this._useWebGL) + { + var root = this._rootNode; + root.children = new Array(); + if (worldObj.children && (worldObj.children.length === 1)) + { + this.init(); + this._geomRoot = undefined; + this.importObjectsJSON( worldObj.children[0] ); + } + } + // convert the object to a string var jStr = JSON.stringify( worldObj ); @@ -759,14 +774,6 @@ World.prototype.exportJSON = function() // 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(); - if (worldObj.children && (worldObj.children.length === 1)) - this.importObjectsJSON( worldObj.children[0] ); return jStr; } @@ -780,13 +787,14 @@ World.prototype.exportObjectsJSON = function( obj, parentObj ) parentObj.children.push( jObj ); if (obj.getChild()) { - this.exportObjects( obj.getChild (), jObj ); + this.exportObjectsJSON( obj.getChild (), jObj ); } if (obj.getNext()) - this.exportObjects( obj.getNext(), parentObj ); + this.exportObjectsJSON( obj.getNext(), parentObj ); } +/* World.prototype.export = function() { var exportStr = "GLWorld 1.0\n"; @@ -849,6 +857,7 @@ World.prototype.exportObjects = function( obj ) { return rtnStr; }; +*/ World.prototype.findTransformNodeByMaterial = function( materialNode, trNode ) { //if (trNode == null) trNode = this._ctrNode; @@ -893,6 +902,8 @@ World.prototype.importJSON = function( jObj ) // render using canvas 2D this.render(); } + else + this.restartRenderLoop(); } World.prototype.importObjectsJSON = function( jObj, parentGeomObj ) diff --git a/js/lib/geom/circle.js b/js/lib/geom/circle.js index fec62308..d48bf98b 100755 --- a/js/lib/geom/circle.js +++ b/js/lib/geom/circle.js @@ -634,24 +634,6 @@ var Circle = function GLCircle() { var strokeMaterialName = jObj.strokeMat; var fillMaterialName = jObj.fillMat; this.importMaterialsJSON( jObj.materials ); - - var strokeMat = MaterialsModel.getMaterial( strokeMaterialName ); - if (!strokeMat) { - console.log( "object material not found in library: " + strokeMaterialName ); - strokeMat = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ); - } - else - strokeMat = strokeMat.dup(); - this._strokeMaterial = strokeMat; - - var fillMat = MaterialsModel.getMaterial( fillMaterialName ); - if (!fillMat) { - console.log( "object material not found in library: " + fillMaterialName ); - fillMat = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ); - } - else - fillMat = fillMat.dup(); - this._fillMaterial = fillMat; }; diff --git a/js/lib/geom/geom-obj.js b/js/lib/geom/geom-obj.js index 63f71955..75b7808b 100755 --- a/js/lib/geom/geom-obj.js +++ b/js/lib/geom/geom-obj.js @@ -279,6 +279,11 @@ var GeomObj = function GLGeomObj() { this.importMaterialsJSON = function( jObj ) { + this._materialArray = []; + this._materialTypeArray = []; + + if (!jObj) return; + var nMaterials = jObj.nMaterials; var matArray = jObj.materials; for (var i=0; i