aboutsummaryrefslogtreecommitdiff
path: root/js/lib/drawing
diff options
context:
space:
mode:
Diffstat (limited to 'js/lib/drawing')
-rwxr-xr-xjs/lib/drawing/world.js291
1 files changed, 229 insertions, 62 deletions
diff --git a/js/lib/drawing/world.js b/js/lib/drawing/world.js
index 0dde9af4..14e63f4a 100755
--- a/js/lib/drawing/world.js
+++ b/js/lib/drawing/world.js
@@ -29,13 +29,19 @@ var World = function GLWorld( canvas, use3D, preserveDrawingBuffer ) {
29 } 29 }
30 30
31 this._canvas = canvas; 31 this._canvas = canvas;
32 if (this._useWebGL) { 32 if (this._useWebGL)
33 if(preserveDrawingBuffer) { 33 {
34 if(preserveDrawingBuffer)
35 {
34 this._glContext = canvas.getContext("experimental-webgl", {preserveDrawingBuffer: true}); 36 this._glContext = canvas.getContext("experimental-webgl", {preserveDrawingBuffer: true});
35 } else { 37 }
38 else
39 {
36 this._glContext = canvas.getContext("experimental-webgl"); 40 this._glContext = canvas.getContext("experimental-webgl");
37 } 41 }
38 } else { 42 }
43 else
44 {
39 this._2DContext = canvas.getContext( "2d" ); 45 this._2DContext = canvas.getContext( "2d" );
40 } 46 }
41 47
@@ -77,6 +83,9 @@ var World = function GLWorld( canvas, use3D, preserveDrawingBuffer ) {
77 // keep a counter for generating node names 83 // keep a counter for generating node names
78 this._nodeCounter = 0; 84 this._nodeCounter = 0;
79 85
86 // for sending notifications to listeners
87 this._notifier = new Notifier();
88
80 /////////////////////////////////////////////////////////////////////// 89 ///////////////////////////////////////////////////////////////////////
81 // Property accessors 90 // Property accessors
82 /////////////////////////////////////////////////////////////////////// 91 ///////////////////////////////////////////////////////////////////////
@@ -119,6 +128,7 @@ var World = function GLWorld( canvas, use3D, preserveDrawingBuffer ) {
119 128
120 // Flag to play/pause animation at authortime 129 // Flag to play/pause animation at authortime
121 this._previewAnimation = true; 130 this._previewAnimation = true;
131
122 //////////////////////////////////////////////////////////////////////////////////// 132 ////////////////////////////////////////////////////////////////////////////////////
123 // RDGE 133 // RDGE
124 // local variables 134 // local variables
@@ -143,7 +153,8 @@ var World = function GLWorld( canvas, use3D, preserveDrawingBuffer ) {
143 this.setCameraMat( camMat ); 153 this.setCameraMat( camMat );
144 154
145 // post-load processing of the scene 155 // post-load processing of the scene
146 this.init = function() { 156 this.init = function()
157 {
147 var ctx1 = RDGE.globals.engine.ctxMan.handleToObject(this._canvas.rdgeCtxHandle), 158 var ctx1 = RDGE.globals.engine.ctxMan.handleToObject(this._canvas.rdgeCtxHandle),
148 ctx2 = RDGE.globals.engine.getContext(); 159 ctx2 = RDGE.globals.engine.getContext();
149 if (ctx1 != ctx2) console.log( "***** different contexts *****" ); 160 if (ctx1 != ctx2) console.log( "***** different contexts *****" );
@@ -201,13 +212,15 @@ var World = function GLWorld( canvas, use3D, preserveDrawingBuffer ) {
201 }; 212 };
202 213
203 // main code for handling user interaction and updating the scene 214 // main code for handling user interaction and updating the scene
204 this.update = function(dt) { 215 this.update = function(dt)
216 {
205 if (!dt) dt = 0.2; 217 if (!dt) dt = 0.2;
206 218
207 dt = 0.01; // use our own internal throttle 219 dt = 0.01; // use our own internal throttle
208 this.elapsed += dt; 220 this.elapsed += dt;
209 221
210 if (this._useWebGL) { 222 if (this._useWebGL)
223 {
211 // changed the global position uniform of light 0, another way to change behavior of a light 224 // changed the global position uniform of light 0, another way to change behavior of a light
212 RDGE.rdgeGlobalParameters.u_light0Pos.set([5 * Math.cos(this.elapsed), 5 * Math.sin(this.elapsed), 20]); 225 RDGE.rdgeGlobalParameters.u_light0Pos.set([5 * Math.cos(this.elapsed), 5 * Math.sin(this.elapsed), 20]);
213 226
@@ -224,35 +237,48 @@ var World = function GLWorld( canvas, use3D, preserveDrawingBuffer ) {
224 }; 237 };
225 238
226 // defining the draw function to control how the scene is rendered 239 // defining the draw function to control how the scene is rendered
227 this.draw = function() { 240 this.draw = function()
228 if (this._useWebGL) { 241 {
242 if (this._useWebGL)
243 {
229 RDGE.globals.engine.setContext( this._canvas.rdgeid ); 244 RDGE.globals.engine.setContext( this._canvas.rdgeid );
230 var ctx = RDGE.globals.engine.getContext(); 245 var ctx = RDGE.globals.engine.getContext();
231 var renderer = ctx.renderer; 246 var renderer = ctx.renderer;
232 if (renderer.unloadedTextureCount <= 0) { 247 if (renderer.unloadedTextureCount <= 0)
248 {
233 renderer.disableCulling(); 249 renderer.disableCulling();
234 renderer._clear(); 250 renderer._clear();
235 this.myScene.render(); 251 this.myScene.render();
236 252
237 if (this._firstRender) { 253 if (this._firstRender)
238 if (this._canvas.task) { 254 {
255 this._notifier.sendNotification( this._notifier.FIRST_RENDER );
256 if (this._canvas.task)
257 {
239 this._firstRender = false; 258 this._firstRender = false;
240 259
241 if (!this.hasAnimatedMaterials() || !this._previewAnimation) { 260 if (!this.hasAnimatedMaterials() || !this._previewAnimation)
261 {
242 this._canvas.task.stop(); 262 this._canvas.task.stop();
243 //this._renderCount = 10; 263 //this._renderCount = 10;
244 } 264 }
245 } 265 }
246 } else if (this._renderCount >= 0) { 266 }
247 if (this._canvas.task) { 267 else if (this._renderCount >= 0)
268 {
269 if (this._canvas.task)
270 {
248 this._renderCount--; 271 this._renderCount--;
249 if (this._renderCount <= 0) { 272 if (this._renderCount <= 0)
273 {
250 this._canvas.task.stop(); 274 this._canvas.task.stop();
251 } 275 }
252 } 276 }
253 } 277 }
254 } 278 }
255 } else { 279 }
280 else
281 {
256 this.render(); 282 this.render();
257 } 283 }
258 }; 284 };
@@ -266,8 +292,10 @@ var World = function GLWorld( canvas, use3D, preserveDrawingBuffer ) {
266// console.log( "GLWorld.onLoadState" ); 292// console.log( "GLWorld.onLoadState" );
267 }; 293 };
268 294
269 this.textureToLoad = function( texture ) { 295 this.textureToLoad = function( texture )
270 if (!texture.previouslyReferenced) { 296 {
297 if (!texture.previouslyReferenced)
298 {
271 var name = texture.lookUpName; 299 var name = texture.lookUpName;
272 texture._world = this; 300 texture._world = this;
273 texture.callback = this.textureMapLoaded; 301 texture.callback = this.textureMapLoaded;
@@ -279,7 +307,8 @@ var World = function GLWorld( canvas, use3D, preserveDrawingBuffer ) {
279 } 307 }
280 }; 308 };
281 309
282 this.textureMapLoaded = function( texture ) { 310 this.textureMapLoaded = function( texture )
311 {
283 var world = texture._world; 312 var world = texture._world;
284 if (!world) { 313 if (!world) {
285 console.log( "**** loaded texture does not have world defined ****" ); 314 console.log( "**** loaded texture does not have world defined ****" );
@@ -289,7 +318,8 @@ var World = function GLWorld( canvas, use3D, preserveDrawingBuffer ) {
289 var name = texture.lookUpName; 318 var name = texture.lookUpName;
290 if (!world._texMapsToLoad[name]) { 319 if (!world._texMapsToLoad[name]) {
291 console.log( "loaded an unregistered texture map: " + name ); 320 console.log( "loaded an unregistered texture map: " + name );
292 } else { 321 }
322 else {
293 //console.log( "loaded a registered texture map: " + name ); 323 //console.log( "loaded a registered texture map: " + name );
294 world._texMapsToLoad[name] = undefined; 324 world._texMapsToLoad[name] = undefined;
295 } 325 }
@@ -316,7 +346,8 @@ var World = function GLWorld( canvas, use3D, preserveDrawingBuffer ) {
316 var world = this._world; 346 var world = this._world;
317 if (!world) { 347 if (!world) {
318 console.log( "**** world not defined for loaded texture map: " + name ); 348 console.log( "**** world not defined for loaded texture map: " + name );
319 } else { 349 }
350 else {
320 world.textureMapLoaded( name ); 351 world.textureMapLoaded( name );
321 } 352 }
322 }; 353 };
@@ -326,7 +357,17 @@ var World = function GLWorld( canvas, use3D, preserveDrawingBuffer ) {
326 var rtnVal = false; 357 var rtnVal = false;
327 if (root) { 358 if (root) {
328 rtnVal = this.hHasAnimatedMaterials( root ); 359 rtnVal = this.hHasAnimatedMaterials( root );
360 this._hasAnimatedMaterials = rtnVal;
329 } 361 }
362 else
363 {
364 // currently...
365 // we set this case to true - cloud materials create a
366 // world with no objects but cloud materials animate.
367 // TODO - find a better way to do this
368 rtnVal = true;
369 this._hasAnimatedMaterials = true;
370 }
330 371
331 return rtnVal; 372 return rtnVal;
332 }; 373 };
@@ -359,6 +400,15 @@ var World = function GLWorld( canvas, use3D, preserveDrawingBuffer ) {
359 return str; 400 return str;
360 }; 401 };
361 402
403 this.addListener = function( obj, callbackFunc, calleeData )
404 {
405 this._notifier.addListener( obj, callbackFunc, calleeData );
406 }
407
408 this.removeListener = function( obj )
409 {