From d4ca478ad313c6c20834e410ba14ad3a5e7b20bf Mon Sep 17 00:00:00 2001 From: hwc487 Date: Tue, 12 Jun 2012 10:28:26 -0700 Subject: Material cleanup & bug fixes. --- js/lib/rdge/materials/square-tunnel-material.js | 44 ++++++++++--------------- 1 file changed, 17 insertions(+), 27 deletions(-) (limited to 'js/lib/rdge/materials/square-tunnel-material.js') diff --git a/js/lib/rdge/materials/square-tunnel-material.js b/js/lib/rdge/materials/square-tunnel-material.js index 78cd45d4..bffae254 100644 --- a/js/lib/rdge/materials/square-tunnel-material.js +++ b/js/lib/rdge/materials/square-tunnel-material.js @@ -14,38 +14,31 @@ var SquareTunnelMaterial = function SquareTunnelMaterial() { this._name = "SquareTunnelMaterial"; this._shaderName = "squareTunnel"; - this._texMap = 'assets/images/rocky-normal.jpg'; + this._defaultTexMap = 'assets/images/rocky-normal.jpg'; this._time = 0.0; this._dTime = 0.01; /////////////////////////////////////////////////////////////////////// - // Properties + // Material Property Accessors /////////////////////////////////////////////////////////////////////// - // all defined in parent PulseMaterial.js - // load the local default value - this._propValues[this._propNames[0]] = this._texMap.slice(0); + var u_tex0_index = 0, u_speed_index = 1; + this._propNames = ["u_tex0", "u_speed" ]; + this._propLabels = ["Texture map", "Speed" ]; + this._propTypes = ["file", "float" ]; + this._propValues = []; + this._propValues[this._propNames[u_tex0_index]] = this._defaultTexMap.slice(0); + this._propValues[this._propNames[u_speed_index]] = 1.0; /////////////////////////////////////////////////////////////////////// - // Methods + // Material Property Accessors /////////////////////////////////////////////////////////////////////// - // duplcate method requirde - this.dup = function (world) { - // get the current values; - var propNames = [], propValues = [], propTypes = [], propLabels = []; - this.getAllProperties(propNames, propValues, propTypes, propLabels); - - // allocate a new material - var newMat = new SquareTunnelMaterial(); - - // copy over the current values; - var n = propNames.length; - for (var i = 0; i < n; i++) - newMat.setProperty(propNames[i], propValues[i]); - - return newMat; - }; + this.isAnimated = function() { return true; }; + this.getShaderDef = function() { return squareTunnelMaterialDef; }; + /////////////////////////////////////////////////////////////////////// + // Methods + /////////////////////////////////////////////////////////////////////// this.init = function (world) { // save the world if (world) this.setWorld(world); @@ -64,12 +57,8 @@ var SquareTunnelMaterial = function SquareTunnelMaterial() { this._shader['default'].u_time.set([this._time]); } - // set up the texture - var texMapName = this._propValues[this._propNames[0]]; - this._glTex = new Texture( world, texMapName ); - // set the shader values in the shader - this.updateTexture(); + this.setShaderValues(); this.setResolution([world.getViewportWidth(), world.getViewportHeight()]); this.update(0); }; @@ -104,6 +93,7 @@ var squareTunnelMaterialDef = { 'u_tex0': { 'type': 'tex2d' }, 'u_time': { 'type': 'float' }, + 'u_speed': { 'type': 'float' }, 'u_resolution': { 'type': 'vec2' } }, -- cgit v1.2.3