diff options
Diffstat (limited to 'js/lib/rdge/materials/bump-metal-material.js')
-rwxr-xr-x | js/lib/rdge/materials/bump-metal-material.js | 84 |
1 files changed, 59 insertions, 25 deletions
diff --git a/js/lib/rdge/materials/bump-metal-material.js b/js/lib/rdge/materials/bump-metal-material.js index 27d5793c..981edbfd 100755 --- a/js/lib/rdge/materials/bump-metal-material.js +++ b/js/lib/rdge/materials/bump-metal-material.js | |||
@@ -6,6 +6,8 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot | |||
6 | 6 | ||
7 | var MaterialParser = require("js/lib/rdge/materials/material-parser").MaterialParser; | 7 | var MaterialParser = require("js/lib/rdge/materials/material-parser").MaterialParser; |
8 | var Material = require("js/lib/rdge/materials/material").Material; | 8 | var Material = require("js/lib/rdge/materials/material").Material; |
9 | var Texture = require("js/lib/rdge/texture").Texture; | ||
10 | |||
9 | /////////////////////////////////////////////////////////////////////// | 11 | /////////////////////////////////////////////////////////////////////// |
10 | // Class GLMaterial | 12 | // Class GLMaterial |
11 | // RDGE representation of a material. | 13 | // RDGE representation of a material. |
@@ -18,10 +20,15 @@ var BumpMetalMaterial = function BumpMetalMaterial() { | |||
18 | this._shaderName = "bumpMetal"; | 20 | this._shaderName = "bumpMetal"; |
19 | 21 | ||
20 | this._lightDiff = [0.3, 0.3, 0.3, 1.0]; | 22 | this._lightDiff = [0.3, 0.3, 0.3, 1.0]; |
21 | this._diffuseTexture = "assets/images/metal.png"; | 23 | |
22 | this._specularTexture = "assets/images/silver.png"; | 24 | this._diffuseTexture = "assets/images/metal.png"; |
25 | //this._diffuseTexture = "texture"; | ||
26 | this._specularTexture = "assets/images/silver.png"; | ||
23 | this._normalTexture = "assets/images/normalMap.png"; | 27 | this._normalTexture = "assets/images/normalMap.png"; |
24 | 28 | ||
29 | // keep the array of initialized textures | ||
30 | this._textures = []; | ||
31 | |||
25 | /////////////////////////////////////////////////////////////////////// | 32 | /////////////////////////////////////////////////////////////////////// |
26 | // Property Accessors | 33 | // Property Accessors |
27 | /////////////////////////////////////////////////////////////////////// | 34 | /////////////////////////////////////////////////////////////////////// |
@@ -48,13 +55,13 @@ var BumpMetalMaterial = function BumpMetalMaterial() { | |||
48 | }; | 55 | }; |
49 | 56 | ||
50 | this.getDiffuseTexture = function() { return this._propValues[this._propNames[1]] ? this._propValues[this._propNames[1]].slice() : null }; | 57 | this.getDiffuseTexture = function() { return this._propValues[this._propNames[1]] ? this._propValues[this._propNames[1]].slice() : null }; |
51 | this.setDiffuseTexture = function(m) { this._propValues[this._propNames[1]] = m ? m.slice(0) : null; this.updateTexture(1); }; | 58 | this.setDiffuseTexture = function(m) { this._propValues[this._propNames[1]] = m ? m.slice(0) : null; this.initTexture(1); }; |
52 | 59 | ||
53 | this.getNormalTexture = function() { return this._propValues[this._propNames[2]] ? this._propValues[this._propNames[2]].slice() : null }; | 60 | this.getNormalTexture = function() { return this._propValues[this._propNames[2]] ? this._propValues[this._propNames[2]].slice() : null }; |
54 | this.setNormalTexture = function(m) { this._propValues[this._propNames[2]] = m ? m.slice(0) : null; this.updateTexture(2); }; | 61 | this.setNormalTexture = function(m) { this._propValues[this._propNames[2]] = m ? m.slice(0) : null; this.initTexture(2); }; |
55 | 62 | ||
56 | this.getSpecularTexture = function() { return this._propValues[this._propNames[3]] ? this._propValues[this._propNames[3]].slice() : null }; | 63 | this.getSpecularTexture = function() { return this._propValues[this._propNames[3]] ? this._propValues[this._propNames[3]].slice() : null }; |
57 | this.setSpecularTexture = function(m) { this._propValues[this._propNames[3]] = m ? m.slice(0) : null; this.updateTexture(3); }; | 64 | this.setSpecularTexture = function(m) { this._propValues[this._propNames[3]] = m ? m.slice(0) : null; this.initTexture(3); }; |
58 | 65 | ||
59 | this.isAnimated = function() { return true; }; | 66 | this.isAnimated = function() { return true; }; |
60 | 67 | ||
@@ -108,8 +115,8 @@ var BumpMetalMaterial = function BumpMetalMaterial() { | |||
108 | { | 115 | { |
109 | // save the world | 116 | // save the world |
110 | if (world) { | 117 | if (world) { |
111 | this.setWorld( world ); | 118 | this.setWorld( world ); |
112 | } | 119 | } |
113 | 120 | ||
114 | // set up the shader | 121 | // set up the shader |
115 | this._shader = new RDGE.jshader(); | 122 | this._shader = new RDGE.jshader(); |
@@ -121,12 +128,35 @@ var BumpMetalMaterial = function BumpMetalMaterial() { | |||
121 | this._materialNode = RDGE.createMaterialNode( this.getShaderName() + "_" + world.generateUniqueNodeID() ); | 128 | this._materialNode = RDGE.createMaterialNode( this.getShaderName() + "_" + world.generateUniqueNodeID() ); |
122 | this._materialNode.setShader(this._shader); | 129 | this._materialNode.setShader(this._shader); |
123 | 130 | ||
124 | // set some image maps | 131 | // DEBUG CODE |
125 | this.updateTexture(1); | 132 | this.initTextures(); |
126 | this.updateTexture(2); | ||
127 | this.updateTexture(3); | ||
128 | }; | 133 | }; |
129 | 134 | ||
135 | this.initTexture = function( index ) | ||
136 | { | ||
137 | var dstWorld = this.getWorld(); | ||
138 | if (dstWorld) | ||
139 | { | ||
140 | var texMapName = this._propValues[this._propNames[index]]; | ||
141 | var texture = new Texture( dstWorld, texMapName ); | ||
142 | this._textures[index] = texture; | ||
143 | this.updateTexture( index ); | ||
144 | } | ||
145 | } | ||
146 | |||
147 | this.initTextures = function() | ||
148 | { | ||
149 | var dstWorld = this.getWorld(); | ||
150 | if (dstWorld) | ||
151 | { | ||
152 | // find the world with the given id | ||
153 | for (var i=1; i<=3; i++) | ||
154 | { | ||
155 | this.initTexture( i ); | ||
156 | } | ||
157 | } | ||
158 | } | ||
159 | |||
130 | this.updateTexture = function( index ) | 160 | this.updateTexture = function( index ) |
131 | { | 161 | { |
132 | var material = this._materialNode; | 162 | var material = this._materialNode; |
@@ -136,20 +166,24 @@ var BumpMetalMaterial = function BumpMetalMaterial() { | |||
136 | var renderer = RDGE.globals.engine.getContext().renderer; | 166 | var renderer = RDGE.globals.engine.getContext().renderer; |
137 | if (renderer && technique) | 167 | if (renderer && technique) |
138 | { | 168 | { |
139 | var texMapName = this._propValues[this._propNames[index]]; | 169 | var glTex = this._textures[ index ]; |
140 | var wrap = 'REPEAT', mips = true; | 170 | if (glTex) |
141 | var tex = this.loadTexture( texMapName, wrap, mips ); | 171 | { |
142 | 172 | if (glTex.isAnimated()) | |
143 | if (tex) | 173 | glTex.render(); |
144 | { | 174 | |
145 | switch (index) | 175 | var tex = glTex.getTexture(); |
146 | { | 176 | if (tex) |
147 | case 1: technique.u_colMap.set( tex ); break; | 177 | { |
148 | case 2: technique.u_normalMap.set( tex ); break; | 178 | switch (index) |
149 | case 3: technique.u_glowMap.set( tex ); break; | 179 | { |
150 | default: console.log( "invalid map index in BumpMetalMaterial, " + index ); | 180 | case 1: technique.u_colMap.set( tex ); break; |
151 | } | 181 | case 2: technique.u_normalMap.set( tex ); break; |
152 | } | 182 | case 3: technique.u_glowMap.set( tex ); break; |
183 | default: console.log( "invalid map index in BumpMetalMaterial, " + index ); | ||
184 | } | ||
185 | } | ||
186 | } | ||
153 | } | 187 | } |
154 | } | 188 | } |
155 | }; | 189 | }; |