From 86a801c057fc3b0580d6130be5740c2ee503444f Mon Sep 17 00:00:00 2001 From: hwc487 Date: Fri, 27 Jan 2012 15:52:36 -0800 Subject: updated from old repo --- js/helper-classes/RDGE/GLWorld.js | 211 +++++++++++++++++++++++++++++++++----- 1 file changed, 184 insertions(+), 27 deletions(-) (limited to 'js/helper-classes/RDGE/GLWorld.js') diff --git a/js/helper-classes/RDGE/GLWorld.js b/js/helper-classes/RDGE/GLWorld.js index cc44da50..dd9b6977 100644 --- a/js/helper-classes/RDGE/GLWorld.js +++ b/js/helper-classes/RDGE/GLWorld.js @@ -65,6 +65,11 @@ function GLWorld( canvas, use3D ) this._camera; + // keep a flag indicating whether a render has been completed. + // this allows us to turn off automatic updating if there are + // no animated materials + this._firstRender = true; + /////////////////////////////////////////////////////////////////////// // Property accessors /////////////////////////////////////////////////////////////////////// @@ -103,6 +108,8 @@ function GLWorld( canvas, use3D ) this.isWebGL = function() { return this._useWebGL; } + this.getRenderer = function() { return this.renderer; } + //////////////////////////////////////////////////////////////////////////////////// // RDGE // local variables @@ -114,6 +121,10 @@ function GLWorld( canvas, use3D ) this.strokeShader = null; this.renderer = null; + // keep an array of texture maps that need to be loaded + this._texMapsToLoad = []; + this._allMapsLoaded = true; + // this is the node to which objects get hung this._rootNode; @@ -214,18 +225,149 @@ function GLWorld( canvas, use3D ) { if (this._useWebGL) { - var ctx = g_Engine.getContext(); - //console.log( "RDGE state: " + ctx.ctxStateManager.currentState().name); - - var renderer = ctx.renderer; - renderer.disableCulling(); - this.myScene.render(); + if (this._allMapsLoaded) + { + var ctx = g_Engine.getContext(); + //console.log( "RDGE state: " + ctx.ctxStateManager.currentState().name); + + ///////////////////////////// + var ctx1 = g_Engine.ctxMan.handleToObject(this._canvas.rdgeCtxHandle); + if (ctx1 != ctx) console.log( "***** different contexts (2) *****" ); + var aRenderer = ctx1.renderer; + ////////////////////////////////////////// + + var renderer = ctx.renderer; + if (renderer != aRenderer) console.log( "***** DIFFERENT RENDERERS *****" ); + renderer.disableCulling(); + this.myScene.render(); + + if (this._firstRender) + { + this._firstRender = false; + + if (!this.hasAnimatedMaterials()) + { + this.myScene.render(); + this._canvas.task.stop(); + } + } + } } else { this.render(); } } + + this.onRunState = function() + { + console.log( "GLWorld.onRunState" ); + } + + this.onLoadState = function() + { + console.log( "GLWorld.onLoadState" ); + } + + this.textureToLoad = function( texture ) + { + if (!texture.previouslyReferenced) + { + var name = texture.lookUpName; + texture._world = this; + texture.callback = this.textureMapLoaded; + this._texMapsToLoad[name] = true; + this._allMapsLoaded = false; + + // stop the draw loop until all textures have been loaded + this._canvas.task.stop(); + } + } + + this.textureMapLoaded = function( texture ) + { + var world = texture._world; + if (!world) + { + console.log( "**** loaded texture does not have world defined ****" ); + return; + } + + var name = texture.lookUpName; + if (!world._texMapsToLoad[name]) + { + console.log( "loaded an unregistered texture map: " + name ); + } + else + { + //console.log( "loaded a registered texture map: " + name ); + world._texMapsToLoad[name] = undefined; + } + + // check if all the texture maps are loaded. if so, resume the render loop + world._allMapsLoaded = world.allTextureMapsLoaded(); + if (world._allMapsLoaded) + world._canvas.task.start(); + } + + this.allTextureMapsLoaded = function() + { + for (var name in this._texMapsToLoad) + { + var needsLoad = this._texMapsToLoad[name]; + if (needsLoad) return false; + } + + return true; + } + + this.textureLoadedCallback = function( name ) + { + console.log( "*** material texture loaded: " + name ); + + var world = this._world; + if (!world) + console.log( "**** world not defined for loaded texture map: " + name ); + else + world.textureMapLoaded( name ); + } + + this.hasAnimatedMaterials = function() + { + var root = this.getGeomRoot(); + var rtnVal = false; + if (root) + rtnVal = this.hHasAnimatedMaterials( root ); + + return rtnVal; + } + + this.hHasAnimatedMaterials = function( obj ) + { + if (obj) + { + if (obj.getFillMaterial()) + { + if (obj.getFillMaterial().isAnimated()) return true; + } + + if (obj.getStrokeMaterial()) + { + if (obj.getStrokeMaterial().isAnimated()) return true; + } + + + // do the sibling + var hasAnim = false; + if (obj.getNext()) hasAnim = this.hHasAnimatedMaterials( obj.getNext() ); + if (hasAnim) return true; + if (obj.getChild()) hasAnim = this.hHasAnimatedMaterials( obj.getChild() ); + if (hasAnim) return true; + } + + return false; + } + // END RDGE //////////////////////////////////////////////////////////////////////////////////// @@ -233,23 +375,20 @@ function GLWorld( canvas, use3D ) // start RDGE passing your runtime object, and false to indicate we don't need a an initialization state // in the case of a procedurally built scene an init state is not needed for loading data - //if (this._useWebGL) + if (this._useWebGL) { - if (this._useWebGL) - { - rdgeStarted = true; + rdgeStarted = true; - // TODO - temporary fix for RDGE id's - this._canvas.id = this._canvas.uuid; + // TODO - temporary fix for RDGE id's + this._canvas.id = this._canvas.uuid; - g_Engine.registerCanvas(this._canvas, this); - RDGEStart( this._canvas ); + g_Engine.registerCanvas(this._canvas, this); + RDGEStart( this._canvas ); - //this._canvas.fpsTracker = new fpsTracker( '0' ); - //this._canvas.task = new RDGETask(this._canvas, true); - //this._canvas.task.stop() - //this._canvas.task.start() - } + //this._canvas.fpsTracker = new fpsTracker( '0' ); + this._canvas.task = new RDGETask(this._canvas, false); + this._canvas.task.stop() + //this._canvas.task.start() } } @@ -334,10 +473,6 @@ GLWorld.prototype.addObject = function( obj ) obj.setWorld( this ); - // build the WebGL buffers - if (this._useWebGL) - obj.buildBuffers(); - if (this._geomRoot == null) { this._geomRoot = obj; @@ -349,6 +484,13 @@ GLWorld.prototype.addObject = function( obj ) go.setNext( obj ); obj.setPrev( go ); } + + // build the WebGL buffers + if (this._useWebGL) + { + obj.buildBuffers(); + this.restartRenderLoop(); + } } catch(e) { @@ -356,16 +498,23 @@ GLWorld.prototype.addObject = function( obj ) } } +GLWorld.prototype.restartRenderLoop = function() +{ + this._firstRender = true; + if (this._allMapsLoaded) + this._canvas.task.start(); + else + this._canvas.task.stop(); +} + //append to the list of objects if obj doesn't already exist //if obj exists, then don't add to list of objects -GLWorld.prototype.addIfNewObject = function (obj) { +GLWorld.prototype.addIfNewObject = function (obj) +{ if (!obj) return; try { obj.setWorld(this); - // build the WebGL buffers - if (this._useWebGL) - obj.buildBuffers(); if (this._geomRoot == null) { this._geomRoot = obj; @@ -384,8 +533,16 @@ GLWorld.prototype.addIfNewObject = function (obj) { go.setNext(obj); obj.setPrev(go); + } } + + // build the WebGL buffers + if (this._useWebGL) + { + obj.buildBuffers(); + this.restartRenderLoop(); + } } catch (e) { alert("Exception in GLWorld.addIfNewObject " + e); -- cgit v1.2.3 From 8e43a46e3d79323fe06dc7771bc611a2c3c85c5c Mon Sep 17 00:00:00 2001 From: hwc487 Date: Mon, 30 Jan 2012 16:15:12 -0800 Subject: Renderer startup handling of non-animated materials. Changed zoom from the document bar to keep the location center of the viewable portion of the document fixed. --- js/helper-classes/RDGE/GLWorld.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'js/helper-classes/RDGE/GLWorld.js') diff --git a/js/helper-classes/RDGE/GLWorld.js b/js/helper-classes/RDGE/GLWorld.js index dd9b6977..b84bb585 100644 --- a/js/helper-classes/RDGE/GLWorld.js +++ b/js/helper-classes/RDGE/GLWorld.js @@ -248,9 +248,17 @@ function GLWorld( canvas, use3D ) if (!this.hasAnimatedMaterials()) { this.myScene.render(); - this._canvas.task.stop(); + //this._canvas.task.stop(); + this._renderCount = 3; } } + else if (this._renderCount >= 0) + { + this._renderCount--; + if (this._renderCount == 0) + this._canvas.task.stop(); + } + } } else -- cgit v1.2.3 From b2ce8b819cc85a558d862c04965b7e65a6ce8640 Mon Sep 17 00:00:00 2001 From: hwc487 Date: Wed, 1 Feb 2012 13:05:32 -0800 Subject: changes to allow minimal rendering ofnon-animated materials. --- js/helper-classes/RDGE/GLWorld.js | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) (limited to 'js/helper-classes/RDGE/GLWorld.js') diff --git a/js/helper-classes/RDGE/GLWorld.js b/js/helper-classes/RDGE/GLWorld.js index b84bb585..0dc34034 100644 --- a/js/helper-classes/RDGE/GLWorld.js +++ b/js/helper-classes/RDGE/GLWorld.js @@ -240,6 +240,7 @@ function GLWorld( canvas, use3D ) if (renderer != aRenderer) console.log( "***** DIFFERENT RENDERERS *****" ); renderer.disableCulling(); this.myScene.render(); + console.log( "render" ); if (this._firstRender) { @@ -247,15 +248,15 @@ function GLWorld( canvas, use3D ) if (!this.hasAnimatedMaterials()) { - this.myScene.render(); + //this.myScene.render(); //this._canvas.task.stop(); - this._renderCount = 3; + this._renderCount = 10; } } else if (this._renderCount >= 0) { this._renderCount--; - if (this._renderCount == 0) + if (this._renderCount <= 0) this._canvas.task.stop(); } @@ -270,6 +271,7 @@ function GLWorld( canvas, use3D ) this.onRunState = function() { console.log( "GLWorld.onRunState" ); + this.restartRenderLoop(); } this.onLoadState = function() @@ -387,16 +389,13 @@ function GLWorld( canvas, use3D ) { rdgeStarted = true; - // TODO - temporary fix for RDGE id's - this._canvas.id = this._canvas.uuid; - + this._canvas.rdgeid = this._canvas.uuid; g_Engine.registerCanvas(this._canvas, this); RDGEStart( this._canvas ); //this._canvas.fpsTracker = new fpsTracker( '0' ); - this._canvas.task = new RDGETask(this._canvas, false); + //this._canvas.task = new RDGETask(this._canvas, false); this._canvas.task.stop() - //this._canvas.task.start() } } @@ -508,11 +507,16 @@ GLWorld.prototype.addObject = function( obj ) GLWorld.prototype.restartRenderLoop = function() { + console.log( "restartRenderLoop" ); + this._firstRender = true; - if (this._allMapsLoaded) - this._canvas.task.start(); - else - this._canvas.task.stop(); + if (this._canvas.task) + { + if (this._allMapsLoaded) + this._canvas.task.start(); + else + this._canvas.task.stop(); + } } //append to the list of objects if obj doesn't already exist @@ -563,7 +567,7 @@ GLWorld.prototype.clearTree = function() { var root = this._rootNode; root.children = new Array(); - g_Engine.unregisterCanvas( this._canvas.id ) + g_Engine.unregisterCanvas( this._canvas.rdgeid ) this.update( 0 ); this.draw(); @@ -805,7 +809,7 @@ GLWorld.prototype.getShapeFromPoint = function( offsetX, offsetY ) GLWorld.prototype.export = function() { var exportStr = "GLWorld 1.0\n"; - exportStr += "id: " + this._canvas.id + "\n"; + exportStr += "id: " + this._canvas.rdgeid + "\n"; exportStr += "fov: " + this._fov + "\n"; exportStr += "zNear: " + this._zNear + "\n"; exportStr += "zFar: " + this._zFar + "\n"; -- cgit v1.2.3 From 4222db97e353fb65fab787ba5927d16d9fa4e1f7 Mon Sep 17 00:00:00 2001 From: hwc487 Date: Wed, 1 Feb 2012 16:18:26 -0800 Subject: Removed a console log and set the Plasma material to animating. --- js/helper-classes/RDGE/GLWorld.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'js/helper-classes/RDGE/GLWorld.js') diff --git a/js/helper-classes/RDGE/GLWorld.js b/js/helper-classes/RDGE/GLWorld.js index 0dc34034..819f89db 100644 --- a/js/helper-classes/RDGE/GLWorld.js +++ b/js/helper-classes/RDGE/GLWorld.js @@ -240,7 +240,7 @@ function GLWorld( canvas, use3D ) if (renderer != aRenderer) console.log( "***** DIFFERENT RENDERERS *****" ); renderer.disableCulling(); this.myScene.render(); - console.log( "render" ); + //console.log( "render" ); if (this._firstRender) { @@ -510,6 +510,7 @@ GLWorld.prototype.restartRenderLoop = function() console.log( "restartRenderLoop" ); this._firstRender = true; + this._renderCount = -1; if (this._canvas.task) { if (this._allMapsLoaded) -- cgit v1.2.3