aboutsummaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
Diffstat (limited to 'js')
-rwxr-xr-xjs/lib/rdge/materials/bump-metal-material.js89
-rwxr-xr-xjs/lib/rdge/materials/material.js95
-rw-r--r--js/lib/rdge/materials/pulse-material.js38
-rw-r--r--js/lib/rdge/texture.js134
4 files changed, 171 insertions, 185 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 };
diff --git a/js/lib/rdge/materials/material.js b/js/lib/rdge/materials/material.js
index 157fa7db..13251ce8 100755
--- a/js/lib/rdge/materials/material.js
+++ b/js/lib/rdge/materials/material.js
@@ -252,29 +252,6 @@ var Material = function GLMaterial( world ) {
252 return tex; 252 return tex;
253 }; 253 };
254 254
255 this.findWorld = function( id, elt )
256 {
257 if (elt.id && elt.id === id)
258 {
259 if (elt.elementModel && elt.elementModel.shapeModel && elt.elementModel.shapeModel.GLWorld)
260 {
261 var world = elt.elementModel.shapeModel.GLWorld;
262 return world;
263 }
264 }
265
266 if (elt.children)
267 {
268 var nKids = elt.children.length;
269 for (var i=0; i<nKids; i++)
270 {
271 var child = elt.children[i];
272 var world = this.findWorld( id, child );
273 if (world) return world;
274 }
275 }
276 }
277
278 this.export = function() { 255 this.export = function() {
279 // this function should be overridden by subclasses 256 // this function should be overridden by subclasses
280 var exportStr = "material: " + this.getShaderName() + "\n" + "endMaterial\n"; 257 var exportStr = "material: " + this.getShaderName() + "\n" + "endMaterial\n";
@@ -290,78 +267,6 @@ var Material = function GLMaterial( world ) {
290 return rtnStr; 267 return rtnStr;
291 }; 268 };
292 269
293 /*
294 this.setRenderProperties = function( glContext, shaderProgram )
295 {
296 glContext.uniform1f( shaderProgram.materialShininessUniform, this._shininess );
297
298 if (this._texture)
299 this.prepareTextureForRender( 0 );
300 else
301 glContext.uniform1i( shaderProgram.useTextureUniform, false );
302
303 var amb = this._ambient, diff = this._diffuse, spec = this._specular;
304 glContext.uniform4f( shaderProgram.materialAmbientUniform, amb[0], amb[1], amb[2], amb[3]);
305 glContext.uniform4f( shaderProgram.materialDiffuseUniform, diff[0], diff[1], diff[2], diff[3]);
306 glContext.uniform4f( shaderProgram.materialSpecularUniform, spec[0], spec[1], spec[2], spec[3]);
307 }
308
309
310
311 this.prepareTextureForRender = function ( index )
312 {
313 // we will need to be able to handle multiple textures.
314 // currently only dealing with 1.
315 index = 0;
316 var texture = this._texture;
317
318 var gl = this.getWorld().getGLContext();
319 var shaderProgram = this.getWorld().getShaderProgram();