aboutsummaryrefslogtreecommitdiff
path: root/js/helper-classes/RDGE/GLWorld.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/helper-classes/RDGE/GLWorld.js')
-rwxr-xr-xjs/helper-classes/RDGE/GLWorld.js46
1 files changed, 32 insertions, 14 deletions
diff --git a/js/helper-classes/RDGE/GLWorld.js b/js/helper-classes/RDGE/GLWorld.js
index 8017207f..ce5f0516 100755
--- a/js/helper-classes/RDGE/GLWorld.js
+++ b/js/helper-classes/RDGE/GLWorld.js
@@ -13,7 +13,6 @@ var fragmentShaderSource = "";
13 13
14var rdgeStarted = false; 14var rdgeStarted = false;
15 15
16var nodeCounter = 0;
17var worldCounter = 0; 16var worldCounter = 0;
18 17
19 18
@@ -74,6 +73,10 @@ function GLWorld( canvas, use3D )
74 this._worldCount = worldCounter; 73 this._worldCount = worldCounter;
75 worldCounter++; 74 worldCounter++;
76 75
76 // keep a counter for generating node names
77 this._nodeCounter = 0;
78
79
77 /////////////////////////////////////////////////////////////////////// 80 ///////////////////////////////////////////////////////////////////////
78 // Property accessors 81 // Property accessors
79 /////////////////////////////////////////////////////////////////////// 82 ///////////////////////////////////////////////////////////////////////
@@ -376,10 +379,12 @@ function GLWorld( canvas, use3D )
376 return false; 379 return false;
377 } 380 }
378 381
379 382 this.generateUniqueNodeID = function()
380 // END RDGE 383 {
381 //////////////////////////////////////////////////////////////////////////////////// 384 var str = String( this._nodeCounter );
382 385 this._nodeCounter++;
386 return str;
387 }
383 388
384 // start RDGE passing your runtime object, and false to indicate we don't need a an initialization state 389 // start RDGE passing your runtime object, and false to indicate we don't need a an initialization state
385 // in the case of a procedurally built scene an init state is not needed for loading data 390 // in the case of a procedurally built scene an init state is not needed for loading data
@@ -418,7 +423,7 @@ GLWorld.prototype.updateObject = function (obj)
418 ctrTrNode = obj.getTransformNode(); 423 ctrTrNode = obj.getTransformNode();
419 if (ctrTrNode == null) 424 if (ctrTrNode == null)
420 { 425 {
421 ctrTrNode = createTransformNode("objRootNode_" + nodeCounter++); 426 ctrTrNode = createTransformNode("objRootNode_" + this._nodeCounter++);
422 this._rootNode.insertAsChild( ctrTrNode ); 427 this._rootNode.insertAsChild( ctrTrNode );
423 obj.setTransformNode( ctrTrNode ); 428 obj.setTransformNode( ctrTrNode );
424 } 429 }
@@ -428,7 +433,7 @@ GLWorld.prototype.updateObject = function (obj)
428 }); 433 });
429 ctrTrNode.meshes = []; 434 ctrTrNode.meshes = [];
430 435
431 ctrTrNode.attachMeshNode(this.renderer.id + "_prim_" + nodeCounter++, prims[0]); 436 ctrTrNode.attachMeshNode(this.renderer.id + "_prim_" + this._nodeCounter++, prims[0]);
432 ctrTrNode.attachMaterial(materialNodes[0]); 437 ctrTrNode.attachMaterial(materialNodes[0]);
433 } 438 }
434 439
@@ -451,12 +456,12 @@ GLWorld.prototype.updateObject = function (obj)
451 } 456 }
452 else 457 else
453 { 458 {
454 childTrNode = createTransformNode("objNode_" + nodeCounter++); 459 childTrNode = createTransformNode("objNode_" + this._nodeCounter++);
455 ctrTrNode.insertAsChild(childTrNode); 460 ctrTrNode.insertAsChild(childTrNode);
456 } 461 }
457 462
458 // attach the instanced box goe 463 // attach the instanced box goe
459 childTrNode.attachMeshNode(this.renderer.id + "_prim_" + nodeCounter++, prim); 464 childTrNode.attachMeshNode(this.renderer.id + "_prim_" + this._nodeCounter++, prim);
460 childTrNode.attachMaterial(materialNodes[i]); 465 childTrNode.attachMaterial(materialNodes[i]);
461 } 466 }
462} 467}
@@ -811,7 +816,7 @@ GLWorld.prototype.getShapeFromPoint = function( offsetX, offsetY )
811 } 816 }
812} 817}
813 818
814GLWorld.prototype.export = function() 819GLWorld.prototype.export = function( exportForPublish )
815{ 820{
816 var exportStr = "GLWorld 1.0\n"; 821 var exportStr = "GLWorld 1.0\n";
817 var id = this.getCanvas().getAttribute( "data-RDGE-id" ); 822 var id = this.getCanvas().getAttribute( "data-RDGE-id" );
@@ -821,20 +826,28 @@ GLWorld.prototype.export = function()
821 exportStr += "zNear: " + this._zNear + "\n"; 826 exportStr += "zNear: " + this._zNear + "\n";
822 exportStr += "zFar: " + this._zFar + "\n"; 827 exportStr += "zFar: " + this._zFar + "\n";
823 exportStr += "viewDist: " + this._viewDist + "\n"; 828 exportStr += "viewDist: " + this._viewDist + "\n";
829 if (this._useWebGL)
830 exportStr += "webGL: true\n";
824 831
825 // we need 2 export modes: One for save/restore, one for publish. 832 // we need 2 export modes: One for save/restore, one for publish.
826 // hardcoding for now 833 // hardcoding for now
827 var exportForPublish = false; 834 //var exportForPublish = false;
835 if (!exportForPublish) exportForPublish = false;
828 exportStr += "publish: " + exportForPublish + "\n"; 836 exportStr += "publish: " + exportForPublish + "\n";
829 837
830 if (exportForPublish) 838 if (exportForPublish && this._useWebGL)
831 { 839 {
832 exportStr += "scenedata: " + this.myScene.exportJSON() + "endscene\n"; 840 exportStr += "scenedata: " + this.myScene.exportJSON() + "endscene\n";
841
842 // write out all of the objects
843 exportStr += "tree\n";
844 exportStr += this.exportObjects( this._geomRoot );
845 exportStr += "endtree\n";
833 } 846 }
834 else 847 else
835 { 848 {
836 // output the material library 849 // output the material library
837 exportStr += MaterialsLibrary.export(); 850 //exportStr += MaterialsLibrary.export(); // THIS NEEDS TO BE DONE AT THE DOC LEVEL
838 851
839 // write out all of the objects 852 // write out all of the objects
840 exportStr += "tree\n"; 853 exportStr += "tree\n";
@@ -902,14 +915,19 @@ GLWorld.prototype.import = function( importStr )
902 rdgeStr = rdgeStr.substr( 0, endIndex ); 915 rdgeStr = rdgeStr.substr( 0, endIndex );
903 916
904 this.myScene.importJSON( rdgeStr ); 917 this.myScene.importJSON( rdgeStr );
918
919 this.importObjects( importStr, this._rootNode );
905 } 920 }
906 else 921 else
907 { 922 {
908 // load the material library 923 // load the material library
909 importStr = MaterialsLibrary.import( importStr ); 924 //importStr = MaterialsLibrary.import( importStr );
910 925
911 // import the objects 926 // import the objects
912 this.importObjects( importStr, this._rootNode ); 927 this.importObjects( importStr, this._rootNode );
928
929 // render using canvas 2D
930 this.render();
913 } 931 }
914} 932}
915 933