From 9e40945a5bf4330d1088b56b8011ee625b1adab9 Mon Sep 17 00:00:00 2001 From: Nivesh Rajbhandari Date: Fri, 10 Feb 2012 10:23:48 -0800 Subject: Support export/import of GLLine data. Signed-off-by: Nivesh Rajbhandari --- js/controllers/elements/shapes-controller.js | 19 +++++--- js/data/pi/pi-data.js | 6 ++- js/helper-classes/RDGE/GLLine.js | 67 +++++++++++++++++++++++++--- js/helper-classes/RDGE/GLRectangle.js | 2 +- js/helper-classes/RDGE/GLWorld.js | 6 ++- 5 files changed, 85 insertions(+), 15 deletions(-) diff --git a/js/controllers/elements/shapes-controller.js b/js/controllers/elements/shapes-controller.js index 44723a1e..640119c4 100644 --- a/js/controllers/elements/shapes-controller.js +++ b/js/controllers/elements/shapes-controller.js @@ -351,12 +351,17 @@ exports.ShapesController = Montage.create(CanvasController, { el.elementModel.shapeModel.GLGeomObj = world.getGeomRoot(); sm = Object.create(MaterialsLibrary.getMaterial("FlatMaterial")); - fm = Object.create(MaterialsLibrary.getMaterial("FlatMaterial")); - if(sm && fm) + if(sm) { el.elementModel.shapeModel.GLGeomObj.setStrokeMaterial(sm); - el.elementModel.shapeModel.GLGeomObj.setFillMaterial(fm); el.elementModel.shapeModel.strokeMaterial = sm; + } + fm = Object.create(MaterialsLibrary.getMaterial("FlatMaterial")); + // TODO - Use consts after GL code is converted to object literal notation +// if( fm && (el.elementModel.shapeModel.GLGeomObj.geomType() !== GLGeomObj.GEOM_TYPE_LINE) ) + if( fm && (el.elementModel.shapeModel.GLGeomObj.geomType() !== 3) ) + { + el.elementModel.shapeModel.GLGeomObj.setFillMaterial(fm); el.elementModel.shapeModel.fillMaterial = fm; } } @@ -381,9 +386,13 @@ exports.ShapesController = Montage.create(CanvasController, { world.import(worldData); el.elementModel.shapeModel.GLGeomObj = world.getGeomRoot(); el.elementModel.shapeModel.GLGeomObj.setStrokeMaterial(null); - el.elementModel.shapeModel.GLGeomObj.setFillMaterial(null); el.elementModel.shapeModel.strokeMaterial = null; - el.elementModel.shapeModel.fillMaterial = null; + // TODO - Use consts after GL code is converted to object literal notation + if(el.elementModel.shapeModel.GLGeomObj.geomType() !== 3) + { + el.elementModel.shapeModel.GLGeomObj.setFillMaterial(null); + el.elementModel.shapeModel.fillMaterial = null; + } } } } diff --git a/js/data/pi/pi-data.js b/js/data/pi/pi-data.js index 10b33a0e..8ffd0ec7 100644 --- a/js/data/pi/pi-data.js +++ b/js/data/pi/pi-data.js @@ -459,12 +459,14 @@ exports.PiData = Montage.create( Montage, { [ { type: "dropdown", - id: "stroke", + id: "strokeMaterial", + prop: "strokeMaterial", label: "Stroke", labelField: "_name", dataField: "_name", items : { boundObject: "this.application.ninja.appModel", boundProperty: "materials" }, - enabled: { boundObject: "this.controls", boundProperty: "useWebGl" } + enabled: { boundObject: "this.controls", boundProperty: "useWebGl" }, + divider : true } ] ] diff --git a/js/helper-classes/RDGE/GLLine.js b/js/helper-classes/RDGE/GLLine.js index 1cd70575..5ec51230 100644 --- a/js/helper-classes/RDGE/GLLine.js +++ b/js/helper-classes/RDGE/GLLine.js @@ -28,6 +28,8 @@ function GLLine( world, xOffset, yOffset, width, height, slope, strokeSize, stro this._strokeWidth = 0.25; this._strokeStyle = "Solid"; + this._scaleX = 1.0; + this._scaleY = 1.0; if (arguments.length > 0) { @@ -44,13 +46,9 @@ function GLLine( world, xOffset, yOffset, width, height, slope, strokeSize, stro this._strokeColor = strokeColor; this._strokeStyle = strokeStyle; + this._scaleX = (world.getViewportWidth())/(world.getViewportHeight()); } - this._scaleX = 1.0; - this._scaleY = 1.0; - - this._scaleX = (world._viewportWidth)/(world._viewportHeight); - this._strokeVerticesLen = 0; this.m_world = world; @@ -104,7 +102,64 @@ function GLLine( world, xOffset, yOffset, width, height, slope, strokeSize, stro this.setSlope = function(m) { this._slope = m; } this.geomType = function() { return this.GEOM_TYPE_LINE; } - + + /////////////////////////////////////////////////////////////////////// + // Methods + /////////////////////////////////////////////////////////////////////// + this.export = function() + { + var rtnStr = "type: " + this.geomType() + "\n"; + + rtnStr += "xoff: " + this._xOffset + "\n"; + rtnStr += "yoff: " + this._yOffset + "\n"; + rtnStr += "width: " + this._width + "\n"; + rtnStr += "height: " + this._height + "\n"; + rtnStr += "xAdj: " + this._xAdj + "\n"; + rtnStr += "yAdj: " + this._yAdj + "\n"; + rtnStr += "strokeWidth: " + this._strokeWidth + "\n"; + rtnStr += "strokeColor: " + String(this._strokeColor) + "\n"; + rtnStr += "strokeStyle: " + this._strokeStyle + "\n"; + rtnStr += "slope: " + String(this._slope) + "\n"; + + rtnStr += "strokeMat: "; + if (this._strokeMaterial) + rtnStr += this._strokeMaterial.getName(); + else + rtnStr += "flatMaterial"; + rtnStr += "\n"; + + return rtnStr; + } + + this.import = function( importStr ) + { + this._xOffset = Number( this.getPropertyFromString( "xoff: ", importStr ) ); + this._yOffset = Number( this.getPropertyFromString( "yoff: ", importStr ) ); + this._width = Number( this.getPropertyFromString( "width: ", importStr ) ); + this._height = Number( this.getPropertyFromString( "height: ", importStr ) ); + this._xAdj = Number( this.getPropertyFromString( "xAdj: ", importStr ) ); + this._yAdj = Number( this.getPropertyFromString( "yAdj: ", importStr ) ); + this._strokeWidth = Number( this.getPropertyFromString( "strokeWidth: ", importStr ) ); + var slope = this.getPropertyFromString( "slope: ", importStr ); + if(isNaN(Number(slope))) + this._slope = slope; + else + this._slope = Number(slope); + + var strokeMaterialName = this.getPropertyFromString( "strokeMat: ", importStr ); + this._strokeStyle = this.getPropertyFromString( "strokeStyle: ", importStr ); + this._strokeColor = eval( "[" + this.getPropertyFromString( "strokeColor: ", importStr ) + "]" ); + + var strokeMat = MaterialsLibrary.getMaterial( strokeMaterialName ); + if (!strokeMat) + { + console.log( "object material not found in library: " + strokeMaterialName ); + strokeMat = new FlatMaterial(); + } + this._strokeMaterial = strokeMat; + + } + /////////////////////////////////////////////////////////////////////// // Methods /////////////////////////////////////////////////////////////////////// diff --git a/js/helper-classes/RDGE/GLRectangle.js b/js/helper-classes/RDGE/GLRectangle.js index d24ade2b..4216fe53 100644 --- a/js/helper-classes/RDGE/GLRectangle.js +++ b/js/helper-classes/RDGE/GLRectangle.js @@ -180,7 +180,7 @@ function GLRectangle() this._strokeStyle = Number( this.getPropertyFromString( "strokeStyle: ", importStr ) ); var strokeMaterialName = this.getPropertyFromString( "strokeMat: ", importStr ); var fillMaterialName = this.getPropertyFromString( "fillMat: ", importStr ); - this._strokeStyle = Number( this.getPropertyFromString( "strokeColor: ", importStr ) ); + this._strokeStyle = this.getPropertyFromString( "strokeStyle: ", importStr ); this._fillColor = eval( "[" + this.getPropertyFromString( "fillColor: ", importStr ) + "]" ); this._strokeColor = eval( "[" + this.getPropertyFromString( "strokeColor: ", importStr ) + "]" ); this._tlRadius = Number( this.getPropertyFromString( "tlRadius: ", importStr ) ); diff --git a/js/helper-classes/RDGE/GLWorld.js b/js/helper-classes/RDGE/GLWorld.js index f9081248..c8327064 100644 --- a/js/helper-classes/RDGE/GLWorld.js +++ b/js/helper-classes/RDGE/GLWorld.js @@ -973,7 +973,11 @@ GLWorld.prototype.importObject = function( objStr, parentNode ) obj.import( objStr ); break; - case 3: // line - not implemented + case 3: // line + obj = new GLLine(); + obj.import( objStr ); + break; + default: throw new Error( "Unrecognized object type: " + type ); break; -- cgit v1.2.3