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/lib/geom/circle.js | 72 +++++++++++++++++++++++++++++++++++---- js/lib/geom/geom-obj.js | 79 +++++++++++++++++++++++++++++++++++++++++++ js/lib/geom/line.js | 53 +++++++++++++++++++++++++++-- js/lib/geom/rectangle.js | 87 +++++++++++++++++++++++++++++++++++++++++------- 4 files changed, 269 insertions(+), 22 deletions(-) (limited to 'js/lib/geom') diff --git a/js/lib/geom/circle.js b/js/lib/geom/circle.js index f94d4e6b..7d1a3452 100755 --- a/js/lib/geom/circle.js +++ b/js/lib/geom/circle.js @@ -53,13 +53,13 @@ var Circle = function GLCircle() { if(strokeMaterial){ this._strokeMaterial = strokeMaterial; } else { - this._strokeMaterial = MaterialsModel.exportFlatMaterial(); + this._strokeMaterial = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ); } if(fillMaterial) { this._fillMaterial = fillMaterial; } else { - this._fillMaterial = MaterialsModel.exportFlatMaterial(); + this._fillMaterial = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ); } this.exportMaterials(); @@ -551,7 +551,65 @@ var Circle = function GLCircle() { } }; - this.export = function() { + this.exportJSON = function() + { + var jObj = + { + 'type' : this.geomType(), + 'xoff' : this._xOffset, + 'yoff' : this._yOffset, + 'width' : this._width, + 'height' : this._height, + 'strokeWidth' : this._strokeWidth, + 'strokeColor' : this._strokeColor, + 'fillColor' : this._fillColor, + 'innerRadius' : this._innerRadius, + 'strokeStyle' : this._strokeStyle, + 'strokeMat' : this._strokeMaterial ? this._strokeMaterial.getName() : MaterialsModel.getDefaultMaterialName(), + 'fillMat' : this._fillMaterial ? this._fillMaterial.getName() : MaterialsModel.getDefaultMaterialName(), + 'materials' : this.exportMaterialsJSON() + }; + + return jObj; + }; + + this.importJSON = function( jObj ) + { + this._xOffset = jObj.xoff; + this._yOffset = jObj.yoff; + this._width = jObj.width; + this._height = jObj.height; + this._strokeWidth = jObj.strokeWidth; + this._strokeColor = jObj.strokeColor; + this._fillColor = jObj.fillColor; + this._innerRadius = jObj.innerRadius; + this._strokeStyle = jObj.strokeStyle; + 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; + }; + + + this.export = function() + { var rtnStr = "type: " + this.geomType() + "\n"; rtnStr += "xoff: " + this._xOffset + "\n"; @@ -568,7 +626,7 @@ var Circle = function GLCircle() { if (this._strokeMaterial) { rtnStr += this._strokeMaterial.getName(); } else { - rtnStr += "flatMaterial"; + rtnStr += MaterialsModel.getDefaultMaterialName(); } rtnStr += "\n"; @@ -577,7 +635,7 @@ var Circle = function GLCircle() { if (this._fillMaterial) { rtnStr += this._fillMaterial.getName(); } else { - rtnStr += "flatMaterial"; + rtnStr += MaterialsModel.getDefaultMaterialName(); } rtnStr += "\n"; @@ -602,7 +660,7 @@ var Circle = function GLCircle() { var strokeMat = MaterialsModel.getMaterial( strokeMaterialName ); if (!strokeMat) { console.log( "object material not found in library: " + strokeMaterialName ); - strokeMat = MaterialsModel.exportFlatMaterial(); + strokeMat = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ); } this._strokeMaterial = strokeMat; @@ -610,7 +668,7 @@ var Circle = function GLCircle() { var fillMat = MaterialsModel.getMaterial( fillMaterialName ); if (!fillMat) { console.log( "object material not found in library: " + fillMaterialName ); - fillMat = MaterialsModel.exportFlatMaterial(); + fillMat = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ); } this._fillMaterial = fillMat; diff --git a/js/lib/geom/geom-obj.js b/js/lib/geom/geom-obj.js index 35ebadb9..2a5b0641 100755 --- a/js/lib/geom/geom-obj.js +++ b/js/lib/geom/geom-obj.js @@ -5,6 +5,7 @@ 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; @@ -25,6 +26,7 @@ var TwistMaterial = require("js/lib/rdge/materials/twist-material").TwistMateria 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 @@ -225,6 +227,83 @@ var GeomObj = function GLGeomObj() { return fillMaterial; }; + this.exportMaterialsJSON = function() + { + var jObj; + if (this._materialArray && this._materialNodeArray) + { + var nMats = this._materialArray.length; + if (nMats > 0) + { + var arr = []; + + for (var i=0; i */ 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 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/geom/circle.js | 18 ------------------ js/lib/geom/geom-obj.js | 12 ++++++++++++ js/lib/geom/line.js | 11 +---------- js/lib/geom/rectangle.js | 28 ++++------------------------ 4 files changed, 17 insertions(+), 52 deletions(-) (limited to 'js/lib/geom') 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