From fdeed8051c3af538d28ca3bc599121cea483c22c Mon Sep 17 00:00:00 2001 From: Valerio Virgillito Date: Thu, 22 Mar 2012 15:47:56 -0700 Subject: Squashed commit of the following GL integration Signed-off-by: Valerio Virgillito --- js/lib/rdge/materials/pulse-material.js | 44 ++++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 12 deletions(-) (limited to 'js/lib/rdge/materials/pulse-material.js') diff --git a/js/lib/rdge/materials/pulse-material.js b/js/lib/rdge/materials/pulse-material.js index 81db36c6..2075d1ff 100644 --- a/js/lib/rdge/materials/pulse-material.js +++ b/js/lib/rdge/materials/pulse-material.js @@ -125,18 +125,6 @@ var PulseMaterial = function PulseMaterial() { var texMapName = this._propValues[this._propNames[0]]; var wrap = 'REPEAT', mips = true; var tex = this.loadTexture( texMapName, wrap, mips ); - - /* - var glTex = new GLTexture( this.getWorld() ); - var prevWorld = this.findPreviousWorld(); - if (prevWorld) - { - var srcCanvas = prevWorld.getCanvas(); - tex = glTex.loadFromCanvas( srcCanvas ); - } - else - tex = glTex.loadFromFile( texMapName, wrap, mips ); - */ if (tex) { technique.u_tex0.set( tex ); @@ -174,6 +162,38 @@ var PulseMaterial = function PulseMaterial() { } }; + // JSON export + this.exportJSON = function() + { + var jObj = + { + 'material' : this.getShaderName(), + 'name' : this.getName(), + 'texture' : this._propValues[this._propNames[0]], + 'dTime' : this._dTime + }; + + return jObj; + }; + + this.importJSON = function( jObj ) + { + if (this.getShaderName() != jObj.material) throw new Error( "ill-formed material" ); + this.setName( jObj.name ); + + try { + this._propValues[this._propNames[0]] = jObj.texture; + this._texMap = jObj.texture; + if (jObj.dTime) + this._dTime = jObj.dTime; + } + catch (e) + { + throw new Error( "could not import material: " + jObj ); + } + } + + this.export = function() { // every material needs the base type and instance name var exportStr = "material: " + this.getShaderName() + "\n"; -- cgit v1.2.3