From 2d68f944e93b201deb46015392e706b7a24201c9 Mon Sep 17 00:00:00 2001 From: Nivesh Rajbhandari Date: Wed, 8 Feb 2012 14:24:48 -0800 Subject: Fixed several typos in Materials import/export code to support toggling between 2d and 3d shape modes. Signed-off-by: Nivesh Rajbhandari --- js/controllers/elements/shapes-controller.js | 25 +++++++++-- js/helper-classes/RDGE/GLMaterial.js | 2 +- js/helper-classes/RDGE/GLRectangle.js | 4 +- .../RDGE/Materials/BumpMetalMaterial.js | 10 ++--- js/helper-classes/RDGE/Materials/FlatMaterial.js | 48 ++++++++++++++-------- js/helper-classes/RDGE/Materials/UberMaterial.js | 6 +-- js/helper-classes/RDGE/MaterialsLibrary.js | 2 +- 7 files changed, 64 insertions(+), 33 deletions(-) diff --git a/js/controllers/elements/shapes-controller.js b/js/controllers/elements/shapes-controller.js index e764de4e..b9c033aa 100644 --- a/js/controllers/elements/shapes-controller.js +++ b/js/controllers/elements/shapes-controller.js @@ -63,11 +63,11 @@ exports.ShapesController = Montage.create(CanvasController, { canvas.height = el.height; this.application.ninja.elementMediator.replaceElement(el, canvas); NJevent("elementDeleted", el); - this.application.ninja.selectionController.selectElement(canvas); el = canvas; this.toggleWebGlMode(el, value); - el.elementModel.shapeModel.GLGeomObj.buildBuffers(); - break; + el.elementModel.shapeModel.GLWorld.render(); + this.application.ninja.selectionController.selectElement(el); + return; case "strokeMaterial": var sm = Object.create(MaterialsLibrary.getMaterial(value)); if(sm) @@ -338,13 +338,26 @@ exports.ShapesController = Montage.create(CanvasController, { { return; } - var world, + var sm, + fm, + world, worldData = el.elementModel.shapeModel.GLWorld.export(); if(worldData) { world = new GLWorld(el, true); el.elementModel.shapeModel.GLWorld = world; + el.elementModel.shapeModel.GLGeomObj.setWorld(world); el.elementModel.shapeModel.useWebGl = true; + sm = Object.create(MaterialsLibrary.getMaterial("FlatMaterial")); + fm = Object.create(MaterialsLibrary.getMaterial("FlatMaterial")); + if(sm && fm) + { + el.elementModel.shapeModel.GLGeomObj.setStrokeMaterial(sm); + el.elementModel.shapeModel.GLGeomObj.setFillMaterial(fm); + el.elementModel.shapeModel.strokeMaterial = sm; + el.elementModel.shapeModel.fillMaterial = fm; + el.elementModel.shapeModel.GLGeomObj.buildBuffers(); + } world.import(worldData); } @@ -365,6 +378,10 @@ exports.ShapesController = Montage.create(CanvasController, { world = new GLWorld(el, false); el.elementModel.shapeModel.GLWorld = world; el.elementModel.shapeModel.useWebGl = false; + el.elementModel.shapeModel.GLGeomObj.setStrokeMaterial(null); + el.elementModel.shapeModel.GLGeomObj.setFillMaterial(null); + el.elementModel.shapeModel.strokeMaterial = null; + el.elementModel.shapeModel.fillMaterial = null; world.import(worldData); } diff --git a/js/helper-classes/RDGE/GLMaterial.js b/js/helper-classes/RDGE/GLMaterial.js index 51c27ace..e1a68abd 100644 --- a/js/helper-classes/RDGE/GLMaterial.js +++ b/js/helper-classes/RDGE/GLMaterial.js @@ -186,7 +186,7 @@ function GLMaterial( world ) var endKey = "endMaterial\n"; var index = importStr.indexOf( endKey ); index += endKey.length; - rtnStr = importStr.substr( index ); + var rtnStr = importStr.substr( index ); return rtnStr; } diff --git a/js/helper-classes/RDGE/GLRectangle.js b/js/helper-classes/RDGE/GLRectangle.js index 8535a683..b88ecc71 100644 --- a/js/helper-classes/RDGE/GLRectangle.js +++ b/js/helper-classes/RDGE/GLRectangle.js @@ -177,8 +177,8 @@ function GLRectangle() this._strokeWidth = Number( this.getPropertyFromString( "strokeWidth: ", importStr ) ); this._innerRadius = Number( this.getPropertyFromString( "innerRadius: ", importStr ) ); this._strokeStyle = Number( this.getPropertyFromString( "strokeStyle: ", importStr ) ); - var strokeMaterialName = Number( this.getPropertyFromString( "strokeMat: ", importStr ) ); - var fillMaterialName = Number( this.getPropertyFromString( "fillMat: ", importStr ) ); + var strokeMaterialName = this.getPropertyFromString( "strokeMat: ", importStr ); + var fillMaterialName = this.getPropertyFromString( "fillMat: ", importStr ); this._strokeStyle = Number( this.getPropertyFromString( "strokeColor: ", importStr ) ); this._fillColor = eval( "[" + this.getPropertyFromString( "fillColor: ", importStr ) + "]" ); this._strokeColor = eval( "[" + this.getPropertyFromString( "strokeColor: ", importStr ) + "]" ); diff --git a/js/helper-classes/RDGE/Materials/BumpMetalMaterial.js b/js/helper-classes/RDGE/Materials/BumpMetalMaterial.js index 0aa3ee78..59720611 100644 --- a/js/helper-classes/RDGE/Materials/BumpMetalMaterial.js +++ b/js/helper-classes/RDGE/Materials/BumpMetalMaterial.js @@ -52,7 +52,7 @@ function BumpMetalMaterial() /////////////////////////////////////////////////////////////////////// // Material Property Accessors /////////////////////////////////////////////////////////////////////// - this._propNames = ["lightDiff", "diffuseMap", "normalMap", "specularMap"]; + this._propNames = ["lightDiff", "diffuseTexture", "normalMap", "specularTexture"]; this._propLabels = ["Diffuse Color", "Diffuse Map", "Bump Map", "Specular Map"]; this._propTypes = ["color", "file", "file", "file"]; this._propValues = []; @@ -122,7 +122,7 @@ function BumpMetalMaterial() exportStr += "lightDiff: " + this.getLightDiff() + "\n"; exportStr += "diffuseTexture: " + this.getDiffuseTexture() + "\n"; exportStr += "specularTexture: " + this.getSpecularTexture() + "\n"; - exportStr += "normalTexture: " + this.getNormalTexture() + "\n"; + exportStr += "normalMap: " + this.getNormalTexture() + "\n"; // every material needs to terminate like this exportStr += "endMaterial\n"; @@ -143,12 +143,12 @@ function BumpMetalMaterial() var lightDiff = eval( "[" + pu.nextValue( "lightDiff: " ) + "]" ), dt = pu.nextValue( "diffuseTexture: " ), st = pu.nextValue( "specularTexture: " ), - nt = pu.nextValue( "normalTexture: " ); + nt = pu.nextValue( "normalMap: " ); - this.setProperty( "lightDiff", lightDif); + this.setProperty( "lightDiff", lightDiff); this.setProperty( "diffuseTexture", dt ); this.setProperty( "specularTexture", st ); - this.setProperty( "normalTexture", nt ); + this.setProperty( "normalMap", nt ); var endKey = "endMaterial\n"; var index = importStr.indexOf( endKey ); diff --git a/js/helper-classes/RDGE/Materials/FlatMaterial.js b/js/helper-classes/RDGE/Materials/FlatMaterial.js index 5177a8a0..a5c079a8 100644 --- a/js/helper-classes/RDGE/Materials/FlatMaterial.js +++ b/js/helper-classes/RDGE/Materials/FlatMaterial.js @@ -63,11 +63,12 @@ function FlatMaterial() this.setProperty = function( prop, value ) { - // make sure we have legitimate imput + // make sure we have legitimate input if (this.validateProperty( prop, value )) { - this._color = value.slice(0); - this._shader.colorMe[prop].set(value); + this._propValues[prop] = value; + if (this._shader && this._shader.colorMe) + this._shader.colorMe[prop].set(value); } } /////////////////////////////////////////////////////////////////////// @@ -76,7 +77,7 @@ function FlatMaterial() { // this function should be overridden by subclasses var exportStr = "material: " + this.getShaderName() + "\n"; - exportStr = "name: " + this.getName() + "\n"; + exportStr += "name: " + this.getName() + "\n"; if (this._shader) exportStr += "color: " + String(this._shader.colorMe.color) + "\n"; @@ -87,19 +88,32 @@ function FlatMaterial() return exportStr; } - this.import = function( importStr ) - { - var pu = new ParseUtils( importStr ); - var material = pu.nextValue( "material: " ); - if (material != this.getShaderName()) throw new Error( "ill-formed material" ); - this.setName( pu.nextValue( "material: ") ); - var color = pu.nextValue( "color: " ); - - var endKey = "endMaterial\n"; - var index = importStr.indexOf( endKey ) + endKey.len; - var rtnStr = importStr.substr( index ); - return rtnStr; - } + this.import = function( importStr ) + { + var pu = new ParseUtils( importStr ); + var material = pu.nextValue( "material: " ); + if (material != this.getShaderName()) throw new Error( "ill-formed material" ); + this.setName( pu.nextValue( "name: ") ); + + var rtnStr; + try + { + var color = eval( "[" + pu.nextValue( "color: " ) + "]" ); + + this.setProperty( "color", color); + + var endKey = "endMaterial\n"; + var index = importStr.indexOf( endKey ); + index += endKey.length; + rtnStr = importStr.substr( index ); + } + catch (e) + { + throw new Error( "could not import material: " + importStr ); + } + + return rtnStr; + } } // used to create unique names diff --git a/js/helper-classes/RDGE/Materials/UberMaterial.js b/js/helper-classes/RDGE/Materials/UberMaterial.js index a8254465..f3acdaa6 100644 --- a/js/helper-classes/RDGE/Materials/UberMaterial.js +++ b/js/helper-classes/RDGE/Materials/UberMaterial.js @@ -45,9 +45,9 @@ function UberMaterial() /////////////////////////////////////////////////////////////////////// // Material Property Accessors /////////////////////////////////////////////////////////////////////// - this._propNames = ["ambientColor", "diffuseColor", "specularColor", "specularPower" , "diffuseMap", "normalMap", "specularMap", "environmentMap", "environmentAmount", "dummy" ]; - this._propLabels = ["Ambient Color", "Diffuse Color", "Specular Color", "Specular Power", "Texture Map", "Bump Map", "Specular Map", "Environment Map", "Environment Map Amount", "Dummy" ]; - this._propTypes = ["color", "color", "color", "float", "file", "file", "file", "file", "float", "checkbox"]; + this._propNames = ["ambientColor", "diffuseColor", "specularColor", "specularPower" , "diffuseMap", "normalMap", "specularMap", "environmentMap", "environmentAmount" ]; + this._propLabels = ["Ambient Color", "Diffuse Color", "Specular Color", "Specular Power", "Texture Map", "Bump Map", "Specular Map", "Environment Map", "Environment Map Amount" ]; + this._propTypes = ["color", "color", "color", "float", "file", "file", "file", "file", "float" ]; this._propValues = []; this._propValues[ this._propNames[0] ] = this._ambientColor.slice(0); diff --git a/js/helper-classes/RDGE/MaterialsLibrary.js b/js/helper-classes/RDGE/MaterialsLibrary.js index 9616b525..e7fc51ac 100644 --- a/js/helper-classes/RDGE/MaterialsLibrary.js +++ b/js/helper-classes/RDGE/MaterialsLibrary.js @@ -141,7 +141,7 @@ var MaterialsLibrary = Object.create(Object.prototype, { case "julia": mat = new JuliaMaterial(); break; case "mandel": mat = new MandelMaterial(); break; case "plasma": mat = new PlasmaMaterial(); break; - case "bumpMetal": mat = new PlasmaMaterial(); break; + case "bumpMetal": mat = new BumpMetalMaterial(); break; case "uber": mat = new UberMaterial(); break; default: -- cgit v1.2.3