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/flat-material.js | 41 +++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 18 deletions(-) (limited to 'js/lib/rdge/materials/flat-material.js') 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; -- cgit v1.2.3