From 7b6e8194b91168abdeb94702eb350d14f147858b Mon Sep 17 00:00:00 2001 From: hwc487 Date: Thu, 8 Mar 2012 17:29:18 -0800 Subject: Canvas IO --- js/lib/rdge/materials/bump-metal-material.js | 10 ++++-- js/lib/rdge/materials/pulse-material.js | 8 +++-- js/lib/rdge/materials/radial-blur-material.js | 6 +++- js/lib/rdge/materials/taper-material.js | 2 +- js/lib/rdge/materials/uber-material.js | 46 ++++++++++++++++++++++++--- 5 files changed, 61 insertions(+), 11 deletions(-) (limited to 'js/lib/rdge/materials') diff --git a/js/lib/rdge/materials/bump-metal-material.js b/js/lib/rdge/materials/bump-metal-material.js index 67b16371..70873885 100755 --- a/js/lib/rdge/materials/bump-metal-material.js +++ b/js/lib/rdge/materials/bump-metal-material.js @@ -158,10 +158,14 @@ var BumpMetalMaterial = function BumpMetalMaterial() { var exportStr = "material: " + this.getShaderName() + "\n"; exportStr += "name: " + this.getName() + "\n"; + var world = this.getWorld(); + if (!world) + throw new Error( "no world in material.export, " + this.getName() ); + exportStr += "lightDiff: " + this.getLightDiff() + "\n"; - exportStr += "diffuseTexture: " + this.getDiffuseTexture() + "\n"; - exportStr += "specularTexture: " + this.getSpecularTexture() + "\n"; - exportStr += "normalMap: " + this.getNormalTexture() + "\n"; + exportStr += "diffuseTexture: " + world.cleansePath(this.getDiffuseTexture()) + "\n"; + exportStr += "specularTexture: " + world.cleansePath(this.getSpecularTexture()) + "\n"; + exportStr += "normalMap: " + world.cleansePath(this.getNormalTexture()) + "\n"; // every material needs to terminate like this exportStr += "endMaterial\n"; diff --git a/js/lib/rdge/materials/pulse-material.js b/js/lib/rdge/materials/pulse-material.js index 1e3137eb..8ad78bd4 100644 --- a/js/lib/rdge/materials/pulse-material.js +++ b/js/lib/rdge/materials/pulse-material.js @@ -179,8 +179,12 @@ var PulseMaterial = function PulseMaterial() { var exportStr = "material: " + this.getShaderName() + "\n"; exportStr += "name: " + this.getName() + "\n"; - var texMapName = this._propValues[this._propNames[0]]; - exportStr += "texture: " + texMapName + "\n"; + var world = this.getWorld(); + if (!world) + throw new Error( "no world in material.export, " + this.getName() ); + + var texMapName = world.cleansePath( this._propValues[this._propNames[0]] ); + exportStr += "texture: " +texMapName + "\n"; // every material needs to terminate like this exportStr += "endMaterial\n"; diff --git a/js/lib/rdge/materials/radial-blur-material.js b/js/lib/rdge/materials/radial-blur-material.js index d0d05e8d..f23f0712 100644 --- a/js/lib/rdge/materials/radial-blur-material.js +++ b/js/lib/rdge/materials/radial-blur-material.js @@ -162,7 +162,11 @@ var RadialBlurMaterial = function RadialBlurMaterial() { var exportStr = "material: " + this.getShaderName() + "\n"; exportStr += "name: " + this.getName() + "\n"; - var texMapName = this._propValues[this._propNames[0]]; + var world = this.getWorld(); + if (!world) + throw new Error( "no world in material.export, " + this.getName() ); + + var texMapName = world.cleansePath( this._propValues[this._propNames[0]] ); exportStr += "texture: " + texMapName + "\n"; // every material needs to terminate like this diff --git a/js/lib/rdge/materials/taper-material.js b/js/lib/rdge/materials/taper-material.js index bd89f08f..03a7ba9c 100644 --- a/js/lib/rdge/materials/taper-material.js +++ b/js/lib/rdge/materials/taper-material.js @@ -104,7 +104,7 @@ function TaperMaterial() exportStr += "name: " + this.getName() + "\n"; if (this._shader) - exportStr += "color: " + String(this._shader.colorMe.color) + "\n"; + exportStr += "color: " + this._shader.colorMe.color + "\n"; else exportStr += "color: " + this.getColor() + "\n"; exportStr += "endMaterial\n"; diff --git a/js/lib/rdge/materials/uber-material.js b/js/lib/rdge/materials/uber-material.js index 0964c9c4..d120ffa1 100755 --- a/js/lib/rdge/materials/uber-material.js +++ b/js/lib/rdge/materials/uber-material.js @@ -33,6 +33,8 @@ var UberMaterial = function UberMaterial() { this._useEnvironmentMap = true; this._useLights = [true, true, true, true]; + this._MAX_LIGHTS = 4; + /////////////////////////////////////////////////////////////////////// // Material Property Accessors /////////////////////////////////////////////////////////////////////// @@ -374,6 +376,18 @@ var UberMaterial = function UberMaterial() { var index = importStr.indexOf( endKey ); index += endKey.length; importStr = importStr.substr( index ); + var pu = new MaterialParser( importStr ); + + var matProps = pu.nextValue( "materialProps: " ); + if (matProps) + { + var ambientColor = Number( pu.nextValue( "ambientColor: " )); this.setProperty( "ambientColor", ambientColor ); + var diffuseColor = Number( pu.nextValue( "diffuseColor: " )); this.setProperty( "diffuseColor", diffuseColor ); + var specularColor = Number( pu.nextValue( "specularColor: " )); this.setProperty( "specularColor", specularColor ); + var specularPower = Number( pu.nextValue( "specularPower: " )); this.setProperty( "specularPower", specularPower ); + } + + var lightProps = pu.nextValue( "theLights" ); } this.export = function() @@ -387,7 +401,7 @@ var UberMaterial = function UberMaterial() { // export the material properties if (typeof caps.material != 'undefined') { - exportStr += "material: true\n"; + exportStr += "materialProps: true\n"; exportStr += "ambientColor: " + caps.material.ambientColor + "\n"; exportStr += "diffuseColor: " + caps.material.diffuseColor + "\n"; exportStr += "specularColor: " + caps.material.specularColor + "\n"; @@ -396,8 +410,9 @@ var UberMaterial = function UberMaterial() { if (typeof caps.lighting != 'undefined') { + exportStr += "lightProps: true\n"; + var light = caps.lighting['light' + i]; - var t; for (var i=0; i