aboutsummaryrefslogtreecommitdiff
path: root/js/lib
diff options
context:
space:
mode:
Diffstat (limited to 'js/lib')
-rwxr-xr-xjs/lib/drawing/world.js26
-rwxr-xr-xjs/lib/rdge/materials/material.js7
-rw-r--r--js/lib/rdge/materials/pulse-material.js14
-rwxr-xr-xjs/lib/rdge/materials/uber-material.js24
-rw-r--r--js/lib/rdge/texture.js25
5 files changed, 91 insertions, 5 deletions
diff --git a/js/lib/drawing/world.js b/js/lib/drawing/world.js
index 402563e9..da8a26ad 100755
--- a/js/lib/drawing/world.js
+++ b/js/lib/drawing/world.js
@@ -239,6 +239,7 @@ var World = function GLWorld( canvas, use3D, preserveDrawingBuffer ) {
239 this.myScene.render(); 239 this.myScene.render();
240 240
241 if (this._firstRender) { 241 if (this._firstRender) {
242 this._notifier.sendNotification( this._notifier.FIRST_RENDER );
242 if (this._canvas.task) { 243 if (this._canvas.task) {
243 this._firstRender = false; 244 this._firstRender = false;
244 245
@@ -828,7 +829,6 @@ World.prototype.exportObjectsJSON = function( obj, parentObj )
828} 829}
829 830
830 831
831
832World.prototype.findTransformNodeByMaterial = function( materialNode, trNode ) { 832World.prototype.findTransformNodeByMaterial = function( materialNode, trNode ) {
833 //if (trNode == null) trNode = this._ctrNode; 833 //if (trNode == null) trNode = this._ctrNode;
834 if (trNode == null) trNode = this._rootNode; 834 if (trNode == null) trNode = this._rootNode;
@@ -926,6 +926,29 @@ World.prototype.importObjectJSON = function( jObj, parentGeomObj )
926 return obj; 926 return obj;
927}; 927};
928 928
929World.prototype.refreshTextures = function( obj )
930{
931 if (obj == null) obj = this._geomRoot;
932 if (!obj) return;
933 if (obj._materialArray)
934 {
935 var nMats = obj._materialArray.length;
936 for (var i=0; i<nMats; i++)
937 {
938 var mat = obj._materialArray[i];
939 if (mat)
940 mat.updateTextures();
941 }
942 }
943
944 if (obj.getChild()) {
945 this.refreshTextures( obj.getChild () );
946 }
947
948 if (obj.getNext())
949 this.refreshTextures( obj.getNext() );
950};
951
929World.prototype.import = function( importStr ) { 952World.prototype.import = function( importStr ) {
930 // import the worldattributes - not currently used 953 // import the worldattributes - not currently used
931 954
@@ -1054,6 +1077,7 @@ function Notifier()
1054 this.OBJECT_DELETE = 1; 1077 this.OBJECT_DELETE = 1;
1055 this.OBJECT_REINSTANTIATE = 2; // the object has come back after a deletion - as in undo 1078 this.OBJECT_REINSTANTIATE = 2; // the object has come back after a deletion - as in undo
1056 this.OBJECT_CHANGE = 3; 1079 this.OBJECT_CHANGE = 3;
1080 this.FIRST_RENDER = 4;
1057 1081
1058 1082
1059 // the array of listener objects 1083 // the array of listener objects
diff --git a/js/lib/rdge/materials/material.js b/js/lib/rdge/materials/material.js
index a81ca18f..bc4c8e6b 100755
--- a/js/lib/rdge/materials/material.js
+++ b/js/lib/rdge/materials/material.js
@@ -257,6 +257,13 @@ var Material = function GLMaterial( world ) {
257 return tex; 257 return tex;
258 }; 258 };
259 259
260 this.updateTextures = function()
261 {
262 // this function is called whenever a world that generates textuers for
263 // the current world changes in some way. Sub-classes with textures
264 // should override this function.
265 }
266
260 this.export = function() { 267 this.export = function() {
261 // this function should be overridden by subclasses 268 // this function should be overridden by subclasses
262 var exportStr = "material: " + this.getShaderName() + "\n" + "endMaterial\n"; 269 var exportStr = "material: " + this.getShaderName() + "\n" + "endMaterial\n";
diff --git a/js/lib/rdge/materials/pulse-material.js b/js/lib/rdge/materials/pulse-material.js
index 276f7de6..0a7a5dd8 100644
--- a/js/lib/rdge/materials/pulse-material.js
+++ b/js/lib/rdge/materials/pulse-material.js
@@ -150,6 +150,20 @@ var PulseMaterial = function PulseMaterial()
150 } 150 }
151 }; 151 };
152 152
153
154 this.updateTextures = function()
155 {
156 if (this._glTex)
157 {
158 if (!this._glTex.isAnimated())
159 {
160 this._glTex.rerender();
161 this.updateTexture();
162 }
163 }
164 }
165
166
153 this.update = function( time ) 167 this.update = function( time )
154 { 168 {
155 var material = this._materialNode; 169 var material = this._materialNode;
diff --git a/js/lib/rdge/materials/uber-material.js b/js/lib/rdge/materials/uber-material.js
index ca244629..71354216 100755
--- a/js/lib/rdge/materials/uber-material.js
+++ b/js/lib/rdge/materials/uber-material.js
@@ -286,6 +286,30 @@ var UberMaterial = function UberMaterial() {
286 } 286 }
287 }; 287 };
288 288
289
290 this.updateTextures = function()
291 {
292 var material = this._materialNode;
293 if (material)
294 {
295 var technique = material.shaderProgram.defaultTechnique;
296 var renderer = g_Engine.getContext().renderer;
297 if (renderer && technique)
298 {
299 if (this._diffuseTexture)
300 {
301 if (!this._diffuseTexture.isAnimated())
302 {
303 this._diffuseTexture.rerender();
304 var tex = this._diffuseTexture.getTexture();
305 technique.s_diffuseMap.set( tex );
306 }
307 }
308 }
309 }
310 }
311
312
289 this.updateSpecularMap = function() { 313 this.updateSpecularMap = function() {
290 var value = this._propValues[ "specularMap" ]; 314 var value = this._propValues[ "specularMap" ];
291 this._specularMapOb.texture = value; 315 this._specularMapOb.texture = value;
diff --git a/js/lib/rdge/texture.js b/js/lib/rdge/texture.js
index d2f66efa..f1448195 100644
--- a/js/lib/rdge/texture.js
+++ b/js/lib/rdge/texture.js
@@ -6,6 +6,8 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot
6 6
7var Material = require("js/lib/rdge/materials/material").Material; 7var Material = require("js/lib/rdge/materials/material").Material;
8 8
9var __textureCounter = 0;
10
9/////////////////////////////////////////////////////////////////////// 11///////////////////////////////////////////////////////////////////////
10// Class GLTexture 12// Class GLTexture
11// GL representation of a texture. 13// GL representation of a texture.
@@ -38,6 +40,9 @@ function Texture( dstWorld, texMapName, wrap, mips )
38 // the destination world that will use the texture map 40 // the destination world that will use the texture map
39 this._dstWorld = dstWorld; 41 this._dstWorld = dstWorld;
40 42
43 this._texCount = __textureCounter;
44 __textureCounter++;
45
41 /////////////////////////////////////////////////////////////////////// 46 ///////////////////////////////////////////////////////////////////////
42 // Property Accessors 47 // Property Accessors
43 /////////////////////////////////////////////////////////////////////// 48 ///////////////////////////////////////////////////////////////////////
@@ -89,7 +94,8 @@ function Texture( dstWorld, texMapName, wrap, mips )
89 console.log( "texture callback, type: " + type ); 94 console.log( "texture callback, type: " + type );
90 if (calleeData.srcWorld) 95 if (calleeData.srcWorld)
91 { 96 {
92 var srcWorld = calleeData.srcWorld; 97 var srcWorld = callbackObj.getSrcWorld();
98 var dstWorld = callbackObj.getDstWorld();
93 var notifier = srcWorld._notifier; 99 var notifier = srcWorld._notifier;
94 var texture = this.callbackObj; 100 var texture = this.callbackObj;
95 if (texture) 101 if (texture)
@@ -103,9 +109,20 @@ function Texture( dstWorld, texMapName, wrap, mips )
103 break; 109 break;
104 110
105 case notifier.OBJECT_CHANGE: 111 case notifier.OBJECT_CHANGE:
106 if (!texture.isAnimated()) 112// this._isAnimated = srcWorld._hasAnimatedMaterials;
107 texture.rerender(); 113// if (!srcWorld.hasAnimatedMaterials())
108 texture.getDstWorld().restartRenderLoop(); 114// srcWorld.restartRenderLoop();
115// else if (!dstWorld.hasAnimatedMaterials())
116// {
117// dstWorld.refreshTextures();
118// dstWorld.restartRenderLoop();
119// }
120 break;
121
122 case notifier.FIRST_RENDER:
123 texture._isAnimated = srcWorld.hasAnimatedMaterials();
124 dstWorld.refreshTextures();
125 dstWorld.restartRenderLoop();
109 break; 126 break;
110 127
111 default: 128 default: