aboutsummaryrefslogtreecommitdiff
path: root/js/helper-classes/backup-delete/GLWorld.js
diff options
context:
space:
mode:
authorPushkar Joshi2012-03-13 11:36:11 -0700
committerPushkar Joshi2012-03-13 11:36:11 -0700
commit6023f7c8258e660388ee33730601f1161f9299e9 (patch)
tree632484428b398f71b8481aa8e30180895ff2483c /js/helper-classes/backup-delete/GLWorld.js
parent76f2021618c0a6a99a1b855233e353e84ca99467 (diff)
parent4ad1650f629e7e345eade52ed6dadc233b27cc45 (diff)
downloadninja-6023f7c8258e660388ee33730601f1161f9299e9.tar.gz
Merge branch 'pentool' into brushtool
Diffstat (limited to 'js/helper-classes/backup-delete/GLWorld.js')
-rwxr-xr-xjs/helper-classes/backup-delete/GLWorld.js71
1 files changed, 43 insertions, 28 deletions
diff --git a/js/helper-classes/backup-delete/GLWorld.js b/js/helper-classes/backup-delete/GLWorld.js
index 8017207f..c8bc4c1c 100755
--- a/js/helper-classes/backup-delete/GLWorld.js
+++ b/js/helper-classes/backup-delete/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";
@@ -892,24 +905,26 @@ GLWorld.prototype.import = function( importStr )
892 905
893 // determine if the data was written for export (no Ninja objects) 906 // determine if the data was written for export (no Ninja objects)
894 // or for save/restore 907 // or for save/restore
895 var index = importStr.indexOf( "scenedata: " ); 908 //var index = importStr.indexOf( "scenedata: " );
896 if (index >= 0) 909 var index = importStr.indexOf( "webGL: " );
910 this._useWebGL = (index >= 0)
911 if (this._useWebGL)
897 { 912 {
898 var rdgeStr = importStr.substr( index+11 ); 913 // start RDGE
899 var endIndex = rdgeStr.indexOf( "endscene\n" ); 914 rdgeStarted = true;
900 if (endIndex < 0) throw new Error( "ill-formed WebGL data" ); 915 var id = this._canvas.getAttribute( "data-RDGE-id" );
901 var len = endIndex - index + 11; 916 this._canvas.rdgeid = id;
902 rdgeStr = rdgeStr.substr( 0, endIndex ); 917 g_Engine.registerCanvas(this._canvas, this);
903 918 RDGEStart( this._canvas );
904 this.myScene.importJSON( rdgeStr ); 919 this._canvas.task.stop()
905 } 920 }
906 else
907 {
908 // load the material library
909 importStr = MaterialsLibrary.import( importStr );
910 921
911 // import the objects 922 this.importObjects( importStr, this._rootNode );
912 this.importObjects( importStr, this._rootNode ); 923
924 if (!this._useWebGL)
925 {
926 // render using canvas 2D
927 this.render();
913 } 928 }
914} 929}
915 930