From fdeed8051c3af538d28ca3bc599121cea483c22c Mon Sep 17 00:00:00 2001 From: Valerio Virgillito Date: Thu, 22 Mar 2012 15:47:56 -0700 Subject: Squashed commit of the following GL integration Signed-off-by: Valerio Virgillito --- js/lib/drawing/world.js | 147 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 147 insertions(+) (limited to 'js/lib/drawing') diff --git a/js/lib/drawing/world.js b/js/lib/drawing/world.js index 049145ce..07a2c3ae 100755 --- a/js/lib/drawing/world.js +++ b/js/lib/drawing/world.js @@ -363,6 +363,7 @@ var World = function GLWorld( canvas, use3D, preserveDrawingBuffer ) { if (this._useWebGL) { rdgeStarted = true; this._canvas.rdgeid = this._canvas.getAttribute( "data-RDGE-id" ); + g_Engine.unregisterCanvas( this._canvas ) g_Engine.registerCanvas(this._canvas, this); RDGEStart( this._canvas ); this._canvas.task.stop() @@ -729,6 +730,72 @@ World.prototype.getShapeFromPoint = function( offsetX, offsetY ) { } }; +World.prototype.exportJSON = function() +{ + // world properties + var worldObj = + { + 'version' : 1.1, + 'id' : this.getCanvas().getAttribute( "data-RDGE-id" ), + 'fov' : this._fov, + 'zNear' : this._zNear, + 'zFar' : this._zFar, + 'viewDist' : this._viewDist, + 'webGL' : this._useWebGL + }; + + // RDGE scenegraph + if (this._useWebGL) + worldObj.scenedata = this.myScene.exportJSON(); + + // object data + var strArray = []; + this.exportObjectsJSON( this._geomRoot, worldObj ); + + // You would think that the RDGE export function + // would not be destructive of the data. You would be wrong... + // We need to rebuild everything + if (this._useWebGL) + { + var root = this._rootNode; + root.children = new Array(); + if (worldObj.children && (worldObj.children.length === 1)) + { + this.init(); + this._geomRoot = undefined; + this.importObjectsJSON( worldObj.children[0] ); + } + } + + // convert the object to a string + var jStr = JSON.stringify( worldObj ); + + // prepend some version information to the string. + // this string is also used to differentiate between JSON + // and pre-JSON versions of fileIO. + // the ending ';' in the version string is necessary + jStr = "v1.0;" + jStr; + + return jStr; +} + +World.prototype.exportObjectsJSON = function( obj, parentObj ) +{ + if (!obj) return; + + var jObj = obj.exportJSON(); + if (!parentObj.children) parentObj.children = []; + parentObj.children.push( jObj ); + + if (obj.getChild()) { + this.exportObjectsJSON( obj.getChild (), jObj ); + } + + if (obj.getNext()) + this.exportObjectsJSON( obj.getNext(), parentObj ); +} + +/* World.prototype.export = function() { var exportStr = "GLWorld 1.0\n"; @@ -791,6 +858,7 @@ World.prototype.exportObjects = function( obj ) { return rtnStr; }; +*/ World.prototype.findTransformNodeByMaterial = function( materialNode, trNode ) { //if (trNode == null) trNode = this._ctrNode; @@ -810,6 +878,85 @@ World.prototype.findTransformNodeByMaterial = function( materialNode, trNode ) return rtnNode; }; +World.prototype.importJSON = function( jObj ) +{ + if (jObj.webGL) + { + // start RDGE + rdgeStarted = true; + var id = this._canvas.getAttribute( "data-RDGE-id" ); + this._canvas.rdgeid = id; + g_Engine.registerCanvas(this._canvas, this); + RDGEStart( this._canvas ); + this._canvas.task.stop() + } + + // import the objects + // there should be exactly one child of the parent object + if (jObj.children && (jObj.children.length === 1)) + this.importObjectsJSON( jObj.children[0] ); + else + throw new Error ("unrecoverable canvas import error - inconsistent root object: " + jObj.children ); + + if (!this._useWebGL) + { + // render using canvas 2D + this.render(); + } + else + this.restartRenderLoop(); +} + +World.prototype.importObjectsJSON = function( jObj, parentGeomObj ) +{ + // read the next object + var gObj = this.importObjectJSON( jObj, parentGeomObj ); + + // determine if we have children + if (jObj.children) + { + var nKids = ojObjbj.chilodren.length; + for (var i=0; i --- js/lib/drawing/world.js | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'js/lib/drawing') diff --git a/js/lib/drawing/world.js b/js/lib/drawing/world.js index 07a2c3ae..b87c6272 100755 --- a/js/lib/drawing/world.js +++ b/js/lib/drawing/world.js @@ -117,6 +117,8 @@ var World = function GLWorld( canvas, use3D, preserveDrawingBuffer ) { this.getRenderer = function() { return this.renderer; }; + // Flag to play/pause animation at authortime + this._previewAnimation = true; //////////////////////////////////////////////////////////////////////////////////// // RDGE // local variables @@ -475,6 +477,10 @@ World.prototype.restartRenderLoop = function() { if (this._allMapsLoaded) { //console.log( "starting task" ); this._canvas.task.start(); + if(!this._previewAnimation) { + //render only once if authortime animation is turned off + this._canvas.task.stop(); + } } else { //console.log( "stopping task" ); this._canvas.task.stop(); -- cgit v1.2.3 From 86770d0dba6b137e651cbf5c8d240856be65857c Mon Sep 17 00:00:00 2001 From: hwc487 Date: Fri, 23 Mar 2012 14:59:51 -0700 Subject: Fixed a problem switching from 3D to 2D and back to 3D. --- js/lib/drawing/world.js | 2 ++ 1 file changed, 2 insertions(+) (limited to 'js/lib/drawing') diff --git a/js/lib/drawing/world.js b/js/lib/drawing/world.js index b87c6272..73273adc 100755 --- a/js/lib/drawing/world.js +++ b/js/lib/drawing/world.js @@ -736,6 +736,8 @@ World.prototype.getShapeFromPoint = function( offsetX, offsetY ) { } }; + + World.prototype.exportJSON = function() { // world properties -- cgit v1.2.3