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 --- .../RDGE/Materials/BumpMetalMaterial.js | 10 ++--- js/helper-classes/RDGE/Materials/FlatMaterial.js | 48 ++++++++++++++-------- js/helper-classes/RDGE/Materials/UberMaterial.js | 6 +-- 3 files changed, 39 insertions(+), 25 deletions(-) (limited to 'js/helper-classes/RDGE/Materials') 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); -- cgit v1.2.3 From d83fb1180aee8b046074b27ebd01aae378363a46 Mon Sep 17 00:00:00 2001 From: Nivesh Rajbhandari Date: Thu, 9 Feb 2012 12:19:16 -0800 Subject: Fixed bad merge in FlatMaterials. Signed-off-by: Nivesh Rajbhandari --- js/helper-classes/RDGE/Materials/FlatMaterial.js | 1 + 1 file changed, 1 insertion(+) (limited to 'js/helper-classes/RDGE/Materials') diff --git a/js/helper-classes/RDGE/Materials/FlatMaterial.js b/js/helper-classes/RDGE/Materials/FlatMaterial.js index 83da145e..e2f23d75 100644 --- a/js/helper-classes/RDGE/Materials/FlatMaterial.js +++ b/js/helper-classes/RDGE/Materials/FlatMaterial.js @@ -127,6 +127,7 @@ function FlatMaterial() { } +} // used to create unique names var flatMaterialCounter = 0; -- cgit v1.2.3