diff options
Diffstat (limited to 'js/lib/rdge/materials/bump-metal-material.js')
-rwxr-xr-x | js/lib/rdge/materials/bump-metal-material.js | 89 |
1 files changed, 47 insertions, 42 deletions
diff --git a/js/lib/rdge/materials/bump-metal-material.js b/js/lib/rdge/materials/bump-metal-material.js index a3ef9d37..0570e8ed 100755 --- a/js/lib/rdge/materials/bump-metal-material.js +++ b/js/lib/rdge/materials/bump-metal-material.js | |||
@@ -21,14 +21,14 @@ var BumpMetalMaterial = function BumpMetalMaterial() { | |||
21 | 21 | ||
22 | this._lightDiff = [0.3, 0.3, 0.3, 1.0]; | 22 | this._lightDiff = [0.3, 0.3, 0.3, 1.0]; |
23 | 23 | ||
24 | //this._diffuseTexture = "assets/images/metal.png"; | 24 | this._diffuseTexture = "assets/images/metal.png"; |
25 | this._diffuseTexture = "texture"; | 25 | //this._diffuseTexture = "texture"; |
26 | this._diffuseWorld = null; // the world that the texture is derived from (if there is one). | ||
27 | this._diffuseTextureObj = null; | ||
28 | |||
29 | this._specularTexture = "assets/images/silver.png"; | 26 | this._specularTexture = "assets/images/silver.png"; |
30 | this._normalTexture = "assets/images/normalMap.png"; | 27 | this._normalTexture = "assets/images/normalMap.png"; |
31 | 28 | ||
29 | // keep the array of initialized textures | ||
30 | this._textures = []; | ||
31 | |||
32 | /////////////////////////////////////////////////////////////////////// | 32 | /////////////////////////////////////////////////////////////////////// |
33 | // Property Accessors | 33 | // Property Accessors |
34 | /////////////////////////////////////////////////////////////////////// | 34 | /////////////////////////////////////////////////////////////////////// |
@@ -55,13 +55,13 @@ var BumpMetalMaterial = function BumpMetalMaterial() { | |||
55 | }; | 55 | }; |
56 | 56 | ||
57 | 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 }; |
58 | 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); }; |
59 | 59 | ||
60 | 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 }; |
61 | 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); }; |
62 | 62 | ||
63 | 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 }; |
64 | 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); }; |
65 | 65 | ||
66 | this.isAnimated = function() { return true; }; | 66 | this.isAnimated = function() { return true; }; |
67 | 67 | ||
@@ -127,29 +127,34 @@ var BumpMetalMaterial = function BumpMetalMaterial() { | |||
127 | this._materialNode.setShader(this._shader); | 127 | this._materialNode.setShader(this._shader); |
128 | 128 | ||
129 | // DEBUG CODE | 129 | // DEBUG CODE |
130 | this.initWorldTextures(); | 130 | this.initTextures(); |
131 | |||
132 | // set some image maps | ||
133 | this.updateTexture(1); | ||
134 | this.updateTexture(2); | ||
135 | this.updateTexture(3); | ||
136 | }; | 131 | }; |
137 | 132 | ||
138 | this.initWorldTextures = function() | 133 | this.initTexture = function( index ) |
139 | { | 134 | { |
140 | // find the world with the given id | 135 | var dstWorld = this.getWorld(); |
141 | var viewUtils = require("js/helper-classes/3D/view-utils").ViewUtils; | 136 | if (dstWorld) |
142 | var root = viewUtils.application.ninja.currentDocument.documentRoot; | ||
143 | this._diffuseWorld = this.findWorld( this._diffuseTexture, root ); | ||
144 | if (this._diffuseWorld) | ||
145 | { | 137 | { |
146 | var world = this.getWorld(); | 138 | var texMapName = this._propValues[this._propNames[index]]; |
147 | var tex = new Texture( world ); | 139 | var texture = new Texture( dstWorld, texMapName ); |
148 | this._diffuseTextureObj = tex; | 140 | this._textures[index] = texture; |
149 | tex.loadFromCanvas( this._diffuseWorld.getCanvas() ); | 141 | this.updateTexture( index ); |
150 | } | 142 | } |
151 | } | 143 | } |
152 | 144 | ||
145 | this.initTextures = function() | ||
146 | { | ||
147 | var dstWorld = this.getWorld(); | ||
148 | if (dstWorld) | ||
149 | { | ||
150 | // find the world with the given id | ||
151 | for (var i=1; i<=3; i++) | ||
152 | { | ||
153 | this.initTexture( i ); | ||
154 | } | ||
155 | } | ||
156 | } | ||
157 | |||
153 | this.updateTexture = function( index ) | 158 | this.updateTexture = function( index ) |
154 | { | 159 | { |
155 | var material = this._materialNode; | 160 | var material = this._materialNode; |
@@ -159,24 +164,24 @@ var BumpMetalMaterial = function BumpMetalMaterial() { | |||
159 | var renderer = g_Engine.getContext().renderer; | 164 | var renderer = g_Engine.getContext().renderer; |
160 | if (renderer && technique) | 165 | if (renderer && technique) |
161 | { | 166 | { |
162 | var texMapName = this._propValues[this._propNames[index]]; | 167 | var glTex = this._textures[ index ]; |
163 | var wrap = 'REPEAT', mips = true; | 168 | if (glTex) |
164 | var tex; | 169 | { |
165 | if ((index === 1) && this._diffuseTextureObj) | 170 | if (glTex.isAnimated()) |
166 | tex = this._diffuseTextureObj.getTexture(); | 171 | glTex.rerender(); |
167 | else | 172 | |
168 | tex = this.loadTexture( texMapName, wrap, mips ); | 173 | var tex = glTex.getTexture(); |
169 | 174 | if (tex) | |
170 | if (tex) | 175 | { |
171 | { | 176 | switch (index) |
172 | switch (index) | 177 | { |
173 | { | 178 | case 1: technique.u_colMap.set( tex ); break; |
174 | case 1: technique.u_colMap.set( tex ); break; | 179 | case 2: technique.u_normalMap.set( tex ); break; |
175 | case 2: technique.u_normalMap.set( tex ); break; | 180 | case 3: technique.u_glowMap.set( tex ); break; |
176 | case 3: technique.u_glowMap.set( tex ); break; | 181 | default: console.log( "invalid map index in BumpMetalMaterial, " + index ); |
177 | default: console.log( "invalid map index in BumpMetalMaterial, " + index ); | 182 | } |
178 | } | 183 | } |
179 | } | 184 | } |
180 | } | 185 | } |
181 | } | 186 | } |
182 | }; | 187 | }; |