From 818582d389f504c915be0c9052fafa33e3e76c92 Mon Sep 17 00:00:00 2001 From: hwc487 Date: Wed, 7 Mar 2012 16:48:48 -0800 Subject: File IO --- js/lib/rdge/materials/bump-metal-material.js | 4 +- js/lib/rdge/materials/deform-material.js | 2 +- js/lib/rdge/materials/flat-material.js | 41 +++++++------ js/lib/rdge/materials/fly-material.js | 2 +- js/lib/rdge/materials/julia-material.js | 2 +- js/lib/rdge/materials/keleidoscope-material.js | 2 +- js/lib/rdge/materials/linear-gradient-material.js | 2 +- js/lib/rdge/materials/mandel-material.js | 2 +- js/lib/rdge/materials/plasma-material.js | 7 ++- js/lib/rdge/materials/pulse-material.js | 7 ++- js/lib/rdge/materials/radial-blur-material.js | 2 +- js/lib/rdge/materials/radial-gradient-material.js | 7 ++- js/lib/rdge/materials/relief-tunnel-material.js | 2 +- js/lib/rdge/materials/square-tunnel-material.js | 2 +- js/lib/rdge/materials/star-material.js | 2 +- js/lib/rdge/materials/taper-material.js | 6 +- js/lib/rdge/materials/tunnel-material.js | 2 +- js/lib/rdge/materials/twist-material.js | 2 +- js/lib/rdge/materials/twist-vert-material.js | 6 +- js/lib/rdge/materials/uber-material.js | 71 ++++++++++++++++++++++- js/lib/rdge/materials/water-material.js | 2 +- js/lib/rdge/materials/z-invert-material.js | 2 +- 22 files changed, 133 insertions(+), 44 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 61126952..67b16371 100755 --- a/js/lib/rdge/materials/bump-metal-material.js +++ b/js/lib/rdge/materials/bump-metal-material.js @@ -75,7 +75,7 @@ var BumpMetalMaterial = function BumpMetalMaterial() { this.setProperty = function( prop, value ) { // every material should do something with the "color" property - if (prop === "color") prop = "lightDiff"; + if (prop === "color") return; // make sure we have legitimate imput var ok = this.validateProperty( prop, value ); @@ -116,7 +116,7 @@ var BumpMetalMaterial = function BumpMetalMaterial() { this._shader['default'].u_light0Diff.set( this.getLightDiff() ); // set up the material node - this._materialNode = createMaterialNode( this.getShaderName() ); + this._materialNode = createMaterialNode( this.getShaderName() + "_" + world.generateUniqueNodeID() ); this._materialNode.setShader(this._shader); // set some image maps diff --git a/js/lib/rdge/materials/deform-material.js b/js/lib/rdge/materials/deform-material.js index 1e6af6ac..dfd89d12 100644 --- a/js/lib/rdge/materials/deform-material.js +++ b/js/lib/rdge/materials/deform-material.js @@ -60,7 +60,7 @@ var DeformMaterial = function DeformMaterial() { this._shader.init(); // set up the material node - this._materialNode = createMaterialNode("deformMaterial"); + this._materialNode = createMaterialNode("deformMaterial" + "_" + world.generateUniqueNodeID()); this._materialNode.setShader(this._shader); this._time = 0; diff --git a/js/lib/rdge/materials/flat-material.js b/js/lib/rdge/materials/flat-material.js index be8bf2b8..97e4f646 100755 --- a/js/lib/rdge/materials/flat-material.js +++ b/js/lib/rdge/materials/flat-material.js @@ -36,19 +36,27 @@ var FlatMaterial = function FlatMaterial() { // duplcate method requirde this.dup = function() { return new FlatMaterial(); } ; - this.init = function() + this.init = function( world ) { - // set up the shader - this._shader = new jshader(); - this._shader.def = flatShaderDef; - this._shader.init(); - - // set the defaults - this._shader.colorMe.color.set( this.getColor() ); - - // set up the material node - this._materialNode = createMaterialNode("flatMaterial"); - this._materialNode.setShader(this._shader); + // save the world + if (world) + { + this.setWorld( world ); + + // set up the shader + this._shader = new jshader(); + this._shader.def = flatShaderDef; + this._shader.init(); + + // set the defaults + this._shader.colorMe.color.set( this.getColor() ); + + // set up the material node + this._materialNode = createMaterialNode("flatMaterial_" + world.generateUniqueNodeID() ); + this._materialNode.setShader(this._shader); + } + else + throw new Error( "GLWorld not supplied to material initialization" ); }; @@ -73,15 +81,12 @@ var FlatMaterial = function FlatMaterial() { }; /////////////////////////////////////////////////////////////////////// - this.export = function() { + this.export = function() + { // this function should be overridden by subclasses var exportStr = "material: " + this.getShaderName() + "\n"; exportStr += "name: " + this.getName() + "\n"; - - if (this._shader) - exportStr += "color: " + String(this._shader.colorMe.color) + "\n"; - else - exportStr += "color: " + this.getColor() + "\n"; + exportStr += "color: " + String(this._propValues["color"]) + "\n"; exportStr += "endMaterial\n"; return exportStr; diff --git a/js/lib/rdge/materials/fly-material.js b/js/lib/rdge/materials/fly-material.js index 8eadb3ab..bd92ecd8 100644 --- a/js/lib/rdge/materials/fly-material.js +++ b/js/lib/rdge/materials/fly-material.js @@ -53,7 +53,7 @@ var FlyMaterial = function FlyMaterial() { this._shader.init(); // set up the material node - this._materialNode = createMaterialNode("flyMaterial"); + this._materialNode = createMaterialNode("flyMaterial" + "_" + world.generateUniqueNodeID()); this._materialNode.setShader(this._shader); this._time = 0; diff --git a/js/lib/rdge/materials/julia-material.js b/js/lib/rdge/materials/julia-material.js index 07536f33..976dfad3 100644 --- a/js/lib/rdge/materials/julia-material.js +++ b/js/lib/rdge/materials/julia-material.js @@ -55,7 +55,7 @@ var JuliaMaterial = function JuliaMaterial() { this._shader.init(); // set up the material node - this._materialNode = createMaterialNode("juliaMaterial"); + this._materialNode = createMaterialNode("juliaMaterial" + "_" + world.generateUniqueNodeID()); this._materialNode.setShader(this._shader); this._time = 0; diff --git a/js/lib/rdge/materials/keleidoscope-material.js b/js/lib/rdge/materials/keleidoscope-material.js index 3ef5d613..16d1ccfa 100644 --- a/js/lib/rdge/materials/keleidoscope-material.js +++ b/js/lib/rdge/materials/keleidoscope-material.js @@ -60,7 +60,7 @@ var KeleidoscopeMaterial = function KeleidoscopeMaterial() { this._shader.init(); // set up the material node - this._materialNode = createMaterialNode("keleidoscopeMaterial"); + this._materialNode = createMaterialNode("keleidoscopeMaterial" + "_" + world.generateUniqueNodeID()); this._materialNode.setShader(this._shader); this._time = 0; diff --git a/js/lib/rdge/materials/linear-gradient-material.js b/js/lib/rdge/materials/linear-gradient-material.js index 2c52c67d..8e05e23d 100755 --- a/js/lib/rdge/materials/linear-gradient-material.js +++ b/js/lib/rdge/materials/linear-gradient-material.js @@ -212,7 +212,7 @@ var LinearGradientMaterial = function LinearGradientMaterial() { this._shader.init(); // set up the material node - this._materialNode = createMaterialNode( this.getShaderName() ); + this._materialNode = createMaterialNode( this.getShaderName() + "_" + world.generateUniqueNodeID() ); this._materialNode.setShader(this._shader); // send the current values to the shader diff --git a/js/lib/rdge/materials/mandel-material.js b/js/lib/rdge/materials/mandel-material.js index 07e009a2..d9f00383 100644 --- a/js/lib/rdge/materials/mandel-material.js +++ b/js/lib/rdge/materials/mandel-material.js @@ -66,7 +66,7 @@ var MandelMaterial = function MandelMaterial() { this._shader.init(); // set up the material node - this._materialNode = createMaterialNode("mandelMaterial"); + this._materialNode = createMaterialNode("mandelMaterial" + "_" + world.generateUniqueNodeID()); this._materialNode.setShader(this._shader); this._time = 0; diff --git a/js/lib/rdge/materials/plasma-material.js b/js/lib/rdge/materials/plasma-material.js index 9ecc2b48..62d0db70 100644 --- a/js/lib/rdge/materials/plasma-material.js +++ b/js/lib/rdge/materials/plasma-material.js @@ -54,7 +54,10 @@ var PlasmaMaterial = function PlasmaMaterial() { return new PlasmaMaterial(); }; - this.init = function() { + this.init = function( world) + { + this.setWorld( world ); + // set up the shader this._shader = new jshader(); this._shader.def = plasmaShaderDef; @@ -66,7 +69,7 @@ var PlasmaMaterial = function PlasmaMaterial() { this.setProperty( "color", [this._time, 0, 0, 1] ); // set up the material node - this._materialNode = createMaterialNode("plasmaMaterial"); + this._materialNode = createMaterialNode("plasmaMaterial" + "_" + world.generateUniqueNodeID()); this._materialNode.setShader(this._shader); }; diff --git a/js/lib/rdge/materials/pulse-material.js b/js/lib/rdge/materials/pulse-material.js index 63cab2f4..1e3137eb 100644 --- a/js/lib/rdge/materials/pulse-material.js +++ b/js/lib/rdge/materials/pulse-material.js @@ -101,7 +101,7 @@ var PulseMaterial = function PulseMaterial() { this._shader.init(); // set up the material node - this._materialNode = createMaterialNode("pulseMaterial"); + this._materialNode = createMaterialNode("pulseMaterial" + "_" + world.generateUniqueNodeID()); this._materialNode.setShader(this._shader); this._time = 0; @@ -178,6 +178,9 @@ var PulseMaterial = function PulseMaterial() { // every material needs the base type and instance name var exportStr = "material: " + this.getShaderName() + "\n"; exportStr += "name: " + this.getName() + "\n"; + + var texMapName = this._propValues[this._propNames[0]]; + exportStr += "texture: " + texMapName + "\n"; // every material needs to terminate like this exportStr += "endMaterial\n"; @@ -193,6 +196,8 @@ var PulseMaterial = function PulseMaterial() { var rtnStr; try { + this._propValues[this._propNames[0]] = pu.nextValue( "texture: " ); + var endKey = "endMaterial\n"; var index = importStr.indexOf( endKey ); index += endKey.length; diff --git a/js/lib/rdge/materials/radial-blur-material.js b/js/lib/rdge/materials/radial-blur-material.js index 41e68182..89116af4 100644 --- a/js/lib/rdge/materials/radial-blur-material.js +++ b/js/lib/rdge/materials/radial-blur-material.js @@ -94,7 +94,7 @@ var RadialBlurMaterial = function RadialBlurMaterial() { this._shader.init(); // set up the material node - this._materialNode = createMaterialNode("radialBlurMaterial"); + this._materialNode = createMaterialNode("radialBlurMaterial" + "_" + world.generateUniqueNodeID()); this._materialNode.setShader(this._shader); this._time = 0; diff --git a/js/lib/rdge/materials/radial-gradient-material.js b/js/lib/rdge/materials/radial-gradient-material.js index 13be50f5..d19b44b7 100755 --- a/js/lib/rdge/materials/radial-gradient-material.js +++ b/js/lib/rdge/materials/radial-gradient-material.js @@ -193,14 +193,17 @@ var RadialGradientMaterial = function RadialGradientMaterial() { return new RadialGradientMaterial(); }; - this.init = function() { + this.init = function( world ) + { + this.setWorld( world ); + // set up the shader this._shader = new jshader(); this._shader.def = radialGradientMaterialDef; this._shader.init(); // set up the material node - this._materialNode = createMaterialNode("radialGradientMaterial"); + this._materialNode = createMaterialNode("radialGradientMaterial" + "_" + world.generateUniqueNodeID()); this._materialNode.setShader(this._shader); // set the shader values in the shader diff --git a/js/lib/rdge/materials/relief-tunnel-material.js b/js/lib/rdge/materials/relief-tunnel-material.js index 20290895..52c40543 100644 --- a/js/lib/rdge/materials/relief-tunnel-material.js +++ b/js/lib/rdge/materials/relief-tunnel-material.js @@ -54,7 +54,7 @@ var ReliefTunnelMaterial = function ReliefTunnelMaterial() { this._shader.init(); // set up the material node - this._materialNode = createMaterialNode("reliefTunnelMaterial"); + this._materialNode = createMaterialNode("reliefTunnelMaterial" + "_" + world.generateUniqueNodeID()); this._materialNode.setShader(this._shader); this._time = 0; diff --git a/js/lib/rdge/materials/square-tunnel-material.js b/js/lib/rdge/materials/square-tunnel-material.js index b5cbff30..9264872f 100644 --- a/js/lib/rdge/materials/square-tunnel-material.js +++ b/js/lib/rdge/materials/square-tunnel-material.js @@ -55,7 +55,7 @@ var SquareTunnelMaterial = function SquareTunnelMaterial() { this._shader.init(); // set up the material node - this._materialNode = createMaterialNode("squareTunnelMaterial"); + this._materialNode = createMaterialNode("squareTunnelMaterial" + "_" + world.generateUniqueNodeID()); this._materialNode.setShader(this._shader); this._time = 0; diff --git a/js/lib/rdge/materials/star-material.js b/js/lib/rdge/materials/star-material.js index 9c0f3172..d7d797e4 100644 --- a/js/lib/rdge/materials/star-material.js +++ b/js/lib/rdge/materials/star-material.js @@ -55,7 +55,7 @@ var StarMaterial = function StarMaterial() { this._shader.init(); // set up the material node - this._materialNode = createMaterialNode("starMaterial"); + this._materialNode = createMaterialNode("starMaterial" + "_" + world.generateUniqueNodeID()); this._materialNode.setShader(this._shader); this._time = 0; diff --git a/js/lib/rdge/materials/taper-material.js b/js/lib/rdge/materials/taper-material.js index eeb08aec..bd89f08f 100644 --- a/js/lib/rdge/materials/taper-material.js +++ b/js/lib/rdge/materials/taper-material.js @@ -42,8 +42,10 @@ function TaperMaterial() // duplcate method requirde this.dup = function() { return new TaperMaterial(); } - this.init = function() + this.init = function( world ) { + this.setWorld( world ); + // set up the shader this._shader = new jshader(); this._shader.def = taperShaderDef; @@ -53,7 +55,7 @@ function TaperMaterial() this._shader.colorMe.color.set( this.getColor() ); // set up the material node - this._materialNode = createMaterialNode("taperMaterial"); + this._materialNode = createMaterialNode("taperMaterial" + "_" + world.generateUniqueNodeID()); this._materialNode.setShader(this._shader); // initialize the taper properties diff --git a/js/lib/rdge/materials/tunnel-material.js b/js/lib/rdge/materials/tunnel-material.js index fe787d16..fe0fbd51 100644 --- a/js/lib/rdge/materials/tunnel-material.js +++ b/js/lib/rdge/materials/tunnel-material.js @@ -56,7 +56,7 @@ var TunnelMaterial = function TunnelMaterial() { this._shader.init(); // set up the material node - this._materialNode = createMaterialNode("tunnelMaterial"); + this._materialNode = createMaterialNode("tunnelMaterial" + "_" + world.generateUniqueNodeID()); this._materialNode.setShader(this._shader); this._time = 0; diff --git a/js/lib/rdge/materials/twist-material.js b/js/lib/rdge/materials/twist-material.js index eb562e99..163c8a77 100644 --- a/js/lib/rdge/materials/twist-material.js +++ b/js/lib/rdge/materials/twist-material.js @@ -56,7 +56,7 @@ var TwistMaterial = function TwistMaterial() { this._shader.init(); // set up the material node - this._materialNode = createMaterialNode("twistMaterial"); + this._materialNode = createMaterialNode("twistMaterial" + "_" + world.generateUniqueNodeID()); this._materialNode.setShader(this._shader); this._time = 0; diff --git a/js/lib/rdge/materials/twist-vert-material.js b/js/lib/rdge/materials/twist-vert-material.js index c2573071..05172a1b 100644 --- a/js/lib/rdge/materials/twist-vert-material.js +++ b/js/lib/rdge/materials/twist-vert-material.js @@ -46,8 +46,10 @@ function TwistVertMaterial() // duplcate method requirde this.dup = function() { return new TwistVertMaterial(); } - this.init = function() + this.init = function( world ) { + this.setWorld( world ); + // set up the shader this._shader = new jshader(); this._shader.def = twistVertShaderDef; @@ -57,7 +59,7 @@ function TwistVertMaterial() this._shader.twistMe.color.set( this.getColor() ); // set up the material node - this._materialNode = createMaterialNode("twistVertMaterial"); + this._materialNode = createMaterialNode("twistVertMaterial" + "_" + world.generateUniqueNodeID()); this._materialNode.setShader(this._shader); // initialize the twist vert properties diff --git a/js/lib/rdge/materials/uber-material.js b/js/lib/rdge/materials/uber-material.js index 6bc35d51..0964c9c4 100755 --- a/js/lib/rdge/materials/uber-material.js +++ b/js/lib/rdge/materials/uber-material.js @@ -363,10 +363,79 @@ var UberMaterial = function UberMaterial() { this._shader = this.buildUberShader( this._ubershaderCaps ); // set up the material node - this._materialNode = createMaterialNode("uberMaterial"); + this._materialNode = createMaterialNode("uberMaterial" + "_" + world.generateUniqueNodeID()); this._materialNode.setShader(this._shader); }; + this.import = function( importStr ) + { + // limit the key searches to this material + var endKey = "endMaterial\n"; + var index = importStr.indexOf( endKey ); + index += endKey.length; + importStr = importStr.substr( index ); + } + + this.export = function() + { + // every material needs the base type and instance name + var exportStr = "material: " + this.getShaderName() + "\n"; + exportStr += "name: " + this.getName() + "\n"; + + var caps = this._ubershaderCaps; + + // export the material properties + if (typeof caps.material != 'undefined') + { + exportStr += "material: true\n"; + exportStr += "ambientColor: " + caps.material.ambientColor + "\n"; + exportStr += "diffuseColor: " + caps.material.diffuseColor + "\n"; + exportStr += "specularColor: " + caps.material.specularColor + "\n"; + exportStr += "specularPower: " + caps.material.specularPower + "\n"; + } + + if (typeof caps.lighting != 'undefined') + { + var light = caps.lighting['light' + i]; + var t; + for (var i=0; i