From aec849d91e4b697d496b9ede28b5d89cf2283781 Mon Sep 17 00:00:00 2001 From: Nivesh Rajbhandari Date: Tue, 7 Feb 2012 14:18:13 -0800 Subject: id's must start with a letter, so our workaround for using uuid for RDGE canvas id's won't work because they often start with a number. Signed-off-by: Nivesh Rajbhandari --- js/helper-classes/RDGE/GLWorld.js | 2 +- 1 file changed, 1 insertion(+), 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 cc44da50..59f0bda0 100644 --- a/js/helper-classes/RDGE/GLWorld.js +++ b/js/helper-classes/RDGE/GLWorld.js @@ -240,7 +240,7 @@ function GLWorld( canvas, use3D ) rdgeStarted = true; // TODO - temporary fix for RDGE id's - this._canvas.id = this._canvas.uuid; + this._canvas.id = "rdge_" + this._canvas.uuid; g_Engine.registerCanvas(this._canvas, this); RDGEStart( this._canvas ); -- cgit v1.2.3 From 191cb96b3b4e1e5aa805211e5ab8dbd6aa075881 Mon Sep 17 00:00:00 2001 From: Nivesh Rajbhandari Date: Thu, 9 Feb 2012 10:09:13 -0800 Subject: Merging WebGL changes that allow users to modify different shape instances. Also, merging in changes that improve rendering performance by not updating static materials. Signed-off-by: Nivesh Rajbhandari --- js/helper-classes/RDGE/GLWorld.js | 238 +++++++++++++++++++++++++++++++++----- 1 file changed, 212 insertions(+), 26 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 59f0bda0..e6e7f466 100644 --- a/js/helper-classes/RDGE/GLWorld.js +++ b/js/helper-classes/RDGE/GLWorld.js @@ -14,6 +14,7 @@ var fragmentShaderSource = ""; var rdgeStarted = false; var nodeCounter = 0; +var worldCounter = 0; /////////////////////////////////////////////////////////////////////// @@ -65,6 +66,14 @@ 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; + + this._worldCount = worldCounter; + worldCounter++; + /////////////////////////////////////////////////////////////////////// // Property accessors /////////////////////////////////////////////////////////////////////// @@ -103,6 +112,8 @@ function GLWorld( canvas, use3D ) this.isWebGL = function() { return this._useWebGL; } + this.getRenderer = function() { return this.renderer; } + //////////////////////////////////////////////////////////////////////////////////// // RDGE // local variables @@ -114,6 +125,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; @@ -136,6 +151,7 @@ function GLWorld( canvas, use3D ) ctx2 = g_Engine.getContext(); if (ctx1 != ctx2) console.log( "***** different contexts *****" ); this.renderer = ctx1.renderer; + this.renderer._world = this; // create a camera, set its perspective, and then point it at the origin var cam = new camera(); @@ -214,18 +230,160 @@ function GLWorld( canvas, use3D ) { if (this._useWebGL) { + g_Engine.setContext( this._canvas.uuid ); 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; - renderer.disableCulling(); - this.myScene.render(); + if (renderer != aRenderer) + { + console.log( "***** DIFFERENT RENDERERS *****" ); + renderer = aRenderer; + } + + if (renderer.unloadedTextureCount <= 0) + { + renderer.disableCulling(); + //console.log( "GLWorld.draw " + renderer._world._worldCount ); + this.myScene.render(); + + if (this._firstRender) + { + this._firstRender = false; + + if (!this.hasAnimatedMaterials()) + { + //this.myScene.render(); + this._canvas.task.stop(); + //this._renderCount = 10; + } + } + else if (this._renderCount >= 0) + { + this._renderCount--; + if (this._renderCount <= 0) + this._canvas.task.stop(); + } + } } else { this.render(); } } + + this.onRunState = function() + { + console.log( "GLWorld.onRunState" ); + this.restartRenderLoop(); + } + + 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 +391,18 @@ 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 = "rdge_" + 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, 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() } } @@ -334,10 +487,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 +498,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 +512,35 @@ GLWorld.prototype.addObject = function( obj ) } } +GLWorld.prototype.restartRenderLoop = function() +{ + //console.log( "restartRenderLoop" ); + + this._firstRender = true; + this._renderCount = -1; + if (this._canvas.task) + { + if (this._allMapsLoaded) + { + //console.log( "starting task" ); + this._canvas.task.start(); + } + else + { + //console.log( "stopping task" ); + 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 +559,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); @@ -398,7 +581,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(); @@ -586,7 +769,10 @@ GLWorld.prototype.render = function() } else { - this.draw(); + console.log( "GLWorld.render, " + this._worldCount ); + g_Engine.setContext( this._canvas.uuid ); + //this.draw(); + this.restartRenderLoop(); } } @@ -640,7 +826,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 a757d4d0064e0f09bb1a99651b8493514cbc4999 Mon Sep 17 00:00:00 2001 From: Nivesh Rajbhandari Date: Thu, 9 Feb 2012 16:03:33 -0800 Subject: Removing some console logs. I kept in the ones that signify error cases. Signed-off-by: Nivesh Rajbhandari --- js/helper-classes/RDGE/GLWorld.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 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 e6e7f466..f9081248 100644 --- a/js/helper-classes/RDGE/GLWorld.js +++ b/js/helper-classes/RDGE/GLWorld.js @@ -276,13 +276,13 @@ function GLWorld( canvas, use3D ) this.onRunState = function() { - console.log( "GLWorld.onRunState" ); +// console.log( "GLWorld.onRunState" ); this.restartRenderLoop(); } this.onLoadState = function() { - console.log( "GLWorld.onLoadState" ); +// console.log( "GLWorld.onLoadState" ); } this.textureToLoad = function( texture ) @@ -339,7 +339,7 @@ function GLWorld( canvas, use3D ) this.textureLoadedCallback = function( name ) { - console.log( "*** material texture loaded: " + name ); +// console.log( "*** material texture loaded: " + name ); var world = this._world; if (!world) @@ -769,7 +769,7 @@ GLWorld.prototype.render = function() } else { - console.log( "GLWorld.render, " + this._worldCount ); +// console.log( "GLWorld.render, " + this._worldCount ); g_Engine.setContext( this._canvas.uuid ); //this.draw(); this.restartRenderLoop(); @@ -809,7 +809,7 @@ GLWorld.prototype.getShapeFromPoint = function( offsetX, offsetY ) var go = this._geomRoot; if(go.collidesWithPoint(x,y)) { - console.log("collision found"); +// console.log("collision found"); return go; } while (go.getNext()) @@ -817,7 +817,7 @@ GLWorld.prototype.getShapeFromPoint = function( offsetX, offsetY ) go = go.getNext(); if(go.collidesWithPoint(x,y)) { - console.log("collision found"); +// console.log("collision found"); return go; } } -- cgit v1.2.3 From 9e40945a5bf4330d1088b56b8011ee625b1adab9 Mon Sep 17 00:00:00 2001 From: Nivesh Rajbhandari Date: Fri, 10 Feb 2012 10:23:48 -0800 Subject: Support export/import of GLLine data. Signed-off-by: Nivesh Rajbhandari --- js/helper-classes/RDGE/GLWorld.js | 6 +++++- 1 file changed, 5 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 f9081248..c8327064 100644 --- a/js/helper-classes/RDGE/GLWorld.js +++ b/js/helper-classes/RDGE/GLWorld.js @@ -973,7 +973,11 @@ GLWorld.prototype.importObject = function( objStr, parentNode ) obj.import( objStr ); break; - case 3: // line - not implemented + case 3: // line + obj = new GLLine(); + obj.import( objStr ); + break; + default: throw new Error( "Unrecognized object type: " + type ); break; -- cgit v1.2.3