diff options
Diffstat (limited to 'js/helper-classes/RDGE/GLWorld.js')
-rw-r--r-- | js/helper-classes/RDGE/GLWorld.js | 219 |
1 files changed, 192 insertions, 27 deletions
diff --git a/js/helper-classes/RDGE/GLWorld.js b/js/helper-classes/RDGE/GLWorld.js index cc44da50..b84bb585 100644 --- a/js/helper-classes/RDGE/GLWorld.js +++ b/js/helper-classes/RDGE/GLWorld.js | |||
@@ -65,6 +65,11 @@ function GLWorld( canvas, use3D ) | |||
65 | 65 | ||
66 | this._camera; | 66 | this._camera; |
67 | 67 | ||
68 | // keep a flag indicating whether a render has been completed. | ||
69 | // this allows us to turn off automatic updating if there are | ||
70 | // no animated materials | ||
71 | this._firstRender = true; | ||
72 | |||
68 | /////////////////////////////////////////////////////////////////////// | 73 | /////////////////////////////////////////////////////////////////////// |
69 | // Property accessors | 74 | // Property accessors |
70 | /////////////////////////////////////////////////////////////////////// | 75 | /////////////////////////////////////////////////////////////////////// |
@@ -103,6 +108,8 @@ function GLWorld( canvas, use3D ) | |||
103 | 108 | ||
104 | this.isWebGL = function() { return this._useWebGL; } | 109 | this.isWebGL = function() { return this._useWebGL; } |
105 | 110 | ||
111 | this.getRenderer = function() { return this.renderer; } | ||
112 | |||
106 | //////////////////////////////////////////////////////////////////////////////////// | 113 | //////////////////////////////////////////////////////////////////////////////////// |
107 | // RDGE | 114 | // RDGE |
108 | // local variables | 115 | // local variables |
@@ -114,6 +121,10 @@ function GLWorld( canvas, use3D ) | |||
114 | this.strokeShader = null; | 121 | this.strokeShader = null; |
115 | this.renderer = null; | 122 | this.renderer = null; |
116 | 123 | ||
124 | // keep an array of texture maps that need to be loaded | ||
125 | this._texMapsToLoad = []; | ||
126 | this._allMapsLoaded = true; | ||
127 | |||
117 | // this is the node to which objects get hung | 128 | // this is the node to which objects get hung |
118 | this._rootNode; | 129 | this._rootNode; |
119 | 130 | ||
@@ -214,18 +225,157 @@ function GLWorld( canvas, use3D ) | |||
214 | { | 225 | { |
215 | if (this._useWebGL) | 226 | if (this._useWebGL) |
216 | { | 227 | { |
217 | var ctx = g_Engine.getContext(); | 228 | if (this._allMapsLoaded) |
218 | //console.log( "RDGE state: " + ctx.ctxStateManager.currentState().name); | 229 | { |
219 | 230 | var ctx = g_Engine.getContext(); | |
220 | var renderer = ctx.renderer; | 231 | //console.log( "RDGE state: " + ctx.ctxStateManager.currentState().name); |
221 | renderer.disableCulling(); | 232 | |
222 | this.myScene.render(); | 233 | ///////////////////////////// |
234 | var ctx1 = g_Engine.ctxMan.handleToObject(this._canvas.rdgeCtxHandle); | ||
235 | if (ctx1 != ctx) console.log( "***** different contexts (2) *****" ); | ||
236 | var aRenderer = ctx1.renderer; | ||
237 | ////////////////////////////////////////// | ||
238 | |||
239 | var renderer = ctx.renderer; | ||
240 | if (renderer != aRenderer) console.log( "***** DIFFERENT RENDERERS *****" ); | ||
241 | renderer.disableCulling(); | ||
242 | this.myScene.render(); | ||
243 | |||
244 | if (this._firstRender) | ||
245 | { | ||
246 | this._firstRender = false; | ||
247 | |||
248 | if (!this.hasAnimatedMaterials()) | ||
249 | { | ||
250 | this.myScene.render(); | ||
251 | //this._canvas.task.stop(); | ||
252 | this._renderCount = 3; | ||
253 | } | ||
254 | } | ||
255 | else if (this._renderCount >= 0) | ||
256 | { | ||
257 | this._renderCount--; | ||
258 | if (this._renderCount == 0) | ||
259 | this._canvas.task.stop(); | ||
260 | } | ||
261 | |||
262 | } | ||
223 | } | 263 | } |
224 | else | 264 | else |
225 | { | 265 | { |
226 | this.render(); | 266 | this.render(); |
227 | } | 267 | } |
228 | } | 268 | } |
269 | |||
270 | this.onRunState = function() | ||
271 | { | ||
272 | console.log( "GLWorld.onRunState" ); | ||
273 | } | ||
274 | |||
275 | this.onLoadState = function() | ||
276 | { | ||
277 | console.log( "GLWorld.onLoadState" ); | ||
278 | } | ||
279 | |||
280 | this.textureToLoad = function( texture ) | ||
281 | { | ||
282 | if (!texture.previouslyReferenced) | ||
283 | { | ||
284 | var name = texture.lookUpName; | ||
285 | texture._world = this; | ||
286 | texture.callback = this.textureMapLoaded; | ||
287 | this._texMapsToLoad[name] = true; | ||
288 | this._allMapsLoaded = false; | ||
289 | |||
290 | // stop the draw loop until all textures have been loaded | ||
291 | this._canvas.task.stop(); | ||
292 | } | ||
293 | } | ||
294 | |||
295 | this.textureMapLoaded = function( texture ) | ||
296 | { | ||
297 | var world = texture._world; | ||
298 | if (!world) | ||
299 | { | ||
300 | console.log( "**** loaded texture does not have world defined ****" ); | ||
301 | return; | ||
302 | } | ||
303 | |||
304 | var name = texture.lookUpName; | ||
305 | if (!world._texMapsToLoad[name]) | ||
306 | { | ||
307 | console.log( "loaded an unregistered texture map: " + name ); | ||
308 | } | ||
309 | else | ||
310 | { | ||
311 | //console.log( "loaded a registered texture map: " + name ); | ||
312 | world._texMapsToLoad[name] = undefined; | ||
313 | } | ||
314 | |||
315 | // check if all the texture maps are loaded. if so, resume the render loop | ||
316 | world._allMapsLoaded = world.allTextureMapsLoaded(); | ||
317 | if (world._allMapsLoaded) | ||
318 | world._canvas.task.start(); | ||
319 | } | ||
320 | |||
321 | this.allTextureMapsLoaded = function() | ||
322 | { | ||
323 | for (var name in this._texMapsToLoad) | ||
324 | { | ||
325 | var needsLoad = this._texMapsToLoad[name]; | ||
326 | if (needsLoad) return false; | ||
327 | } | ||
328 | |||
329 | return true; | ||
330 | } | ||
331 | |||
332 | this.textureLoadedCallback = function( name ) | ||
333 | { | ||
334 | console.log( "*** material texture loaded: " + name ); | ||
335 | |||
336 | var world = this._world; | ||
337 | if (!world) | ||
338 | console.log( "**** world not defined for loaded texture map: " + name ); | ||
339 | else | ||
340 | world.textureMapLoaded( name ); | ||
341 | } | ||
342 | |||
343 | this.hasAnimatedMaterials = function() | ||
344 | { | ||
345 | var root = this.getGeomRoot(); | ||
346 | var rtnVal = false; | ||
347 | if (root) | ||
348 | rtnVal = this.hHasAnimatedMaterials( root ); | ||
349 | |||
350 | return rtnVal; | ||
351 | } | ||
352 | |||
353 | this.hHasAnimatedMaterials = function( obj ) | ||
354 | { | ||
355 | if (obj) | ||
356 | { | ||
357 | if (obj.getFillMaterial()) | ||
358 | { | ||
359 | if (obj.getFillMaterial().isAnimated()) return true; | ||
360 | } | ||
361 | |||
362 | if (obj.getStrokeMaterial()) | ||
363 | { | ||
364 | if (obj.getStrokeMaterial().isAnimated()) return true; | ||
365 | } | ||
366 | |||
367 | |||
368 | // do the sibling | ||
369 | var hasAnim = false; | ||
370 | if (obj.getNext()) hasAnim = this.hHasAnimatedMaterials( obj.getNext() ); | ||
371 | if (hasAnim) return true; | ||
372 | if (obj.getChild()) hasAnim = this.hHasAnimatedMaterials( obj.getChild() ); | ||
373 | if (hasAnim) return true; | ||
374 | } | ||
375 | |||
376 | return false; | ||
377 | } | ||
378 | |||
229 | 379 | ||
230 | // END RDGE | 380 | // END RDGE |
231 | //////////////////////////////////////////////////////////////////////////////////// | 381 | //////////////////////////////////////////////////////////////////////////////////// |
@@ -233,23 +383,20 @@ function GLWorld( canvas, use3D ) | |||
233 | 383 | ||
234 | // start RDGE passing your runtime object, and false to indicate we don't need a an initialization state | 384 | // start RDGE passing your runtime object, and false to indicate we don't need a an initialization state |
235 | // in the case of a procedurally built scene an init state is not needed for loading data | 385 | // in the case of a procedurally built scene an init state is not needed for loading data |
236 | //if (this._useWebGL) | 386 | if (this._useWebGL) |
237 | { | 387 | { |
238 | if (this._useWebGL) | 388 | rdgeStarted = true; |
239 | { | ||
240 | rdgeStarted = true; | ||
241 | 389 | ||
242 | // TODO - temporary fix for RDGE id's | 390 | // TODO - temporary fix for RDGE id's |
243 | this._canvas.id = this._canvas.uuid; | 391 | this._canvas.id = this._canvas.uuid; |
244 | 392 | ||
245 | g_Engine.registerCanvas(this._canvas, this); | 393 | g_Engine.registerCanvas(this._canvas, this); |
246 | RDGEStart( this._canvas ); | 394 | RDGEStart( this._canvas ); |
247 | 395 | ||