aboutsummaryrefslogtreecommitdiff
path: root/js/lib/drawing
diff options
context:
space:
mode:
Diffstat (limited to 'js/lib/drawing')
-rwxr-xr-xjs/lib/drawing/world.js113
1 files changed, 76 insertions, 37 deletions
diff --git a/js/lib/drawing/world.js b/js/lib/drawing/world.js
index 3d6c6fc4..cffd0083 100755
--- a/js/lib/drawing/world.js
+++ b/js/lib/drawing/world.js
@@ -4,17 +4,6 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot
4(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. 4(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved.
5</copyright> */ 5</copyright> */
6 6
7// Useless Global variables.
8// TODO: Remove this as soon as QE test pass
9/*
10var shaderProgramArray = new Array;
11var glContextArray = new Array;
12var vertexShaderSource = "";
13var fragmentShaderSource = "";
14var rdgeStarted = false;
15*/
16
17var nodeCounter = 0;
18 7
19var GeomObj = require("js/lib/geom/geom-obj").GeomObj; 8var GeomObj = require("js/lib/geom/geom-obj").GeomObj;
20var Line = require("js/lib/geom/line").Line; 9var Line = require("js/lib/geom/line").Line;
@@ -22,6 +11,8 @@ var Rectangle = require("js/lib/geom/rectangle").Rectangle;
22var Circle = require("js/lib/geom/circle").Circle; 11var Circle = require("js/lib/geom/circle").Circle;
23var MaterialsModel = require("js/models/materials-model").MaterialsModel; 12var MaterialsModel = require("js/models/materials-model").MaterialsModel;
24 13
14var worldCounter = 0;
15
25/////////////////////////////////////////////////////////////////////// 16///////////////////////////////////////////////////////////////////////
26// Class GLWorld 17// Class GLWorld
27// Manages display in a canvas 18// Manages display in a canvas
@@ -76,6 +67,12 @@ var World = function GLWorld( canvas, use3D ) {
76 // no animated materials 67 // no animated materials
77 this._firstRender = true; 68 this._firstRender = true;
78 69
70 this._worldCount = worldCounter;
71 worldCounter++;
72
73 // keep a counter for generating node names
74 this._nodeCounter = 0;
75
79 /////////////////////////////////////////////////////////////////////// 76 ///////////////////////////////////////////////////////////////////////
80 // Property accessors 77 // Property accessors
81 /////////////////////////////////////////////////////////////////////// 78 ///////////////////////////////////////////////////////////////////////
@@ -350,9 +347,12 @@ var World = function GLWorld( canvas, use3D ) {
350 return false; 347 return false;
351 }; 348 };
352 349
353 350 this.generateUniqueNodeID = function()
354 // END RDGE 351 {
355 //////////////////////////////////////////////////////////////////////////////////// 352 var str = "" + this._nodeCounter;
353 this._nodeCounter++;
354 return str;
355 }
356 356
357 357
358 // start RDGE passing your runtime object, and false to indicate we don't need a an initialization state 358 // start RDGE passing your runtime object, and false to indicate we don't need a an initialization state
@@ -391,7 +391,7 @@ World.prototype.updateObject = function (obj) {
391 if (nPrims > 0) { 391 if (nPrims > 0) {
392 ctrTrNode = obj.getTransformNode(); 392 ctrTrNode = obj.getTransformNode();
393 if (ctrTrNode == null) { 393 if (ctrTrNode == null) {
394 ctrTrNode = createTransformNode("objRootNode_" + nodeCounter++); 394 ctrTrNode = createTransformNode("objRootNode_" + this._nodeCounter++);
395 this._rootNode.insertAsChild( ctrTrNode ); 395 this._rootNode.insertAsChild( ctrTrNode );
396 obj.setTransformNode( ctrTrNode ); 396 obj.setTransformNode( ctrTrNode );
397 } 397 }
@@ -401,7 +401,7 @@ World.prototype.updateObject = function (obj) {
401 }); 401 });
402 ctrTrNode.meshes = []; 402 ctrTrNode.meshes = [];
403 403
404 ctrTrNode.attachMeshNode(this.renderer.id + "_prim_" + nodeCounter++, prims[0]); 404 ctrTrNode.attachMeshNode(this.renderer.id + "_prim_" + this._nodeCounter++, prims[0]);
405 ctrTrNode.attachMaterial(materialNodes[0]); 405 ctrTrNode.attachMaterial(materialNodes[0]);
406 } 406 }
407 407
@@ -420,12 +420,12 @@ World.prototype.updateObject = function (obj) {
420 }); 420 });
421 childTrNode.meshes = []; 421 childTrNode.meshes = [];
422 } else { 422 } else {
423 childTrNode = createTransformNode("objNode_" + nodeCounter++); 423 childTrNode = createTransformNode("objNode_" + this._nodeCounter++);
424 ctrTrNode.insertAsChild(childTrNode); 424 ctrTrNode.insertAsChild(childTrNode);
425 } 425 }
426 426
427 // attach the instanced box goe 427 // attach the instanced box goe
428 childTrNode.attachMeshNode(this.renderer.id + "_prim_" + nodeCounter++, prim); 428 childTrNode.attachMeshNode(this.renderer.id + "_prim_" + this._nodeCounter++, prim);
429 childTrNode.attachMaterial(materialNodes[i]); 429 childTrNode.attachMaterial(materialNodes[i]);
430 } 430 }
431}; 431};
@@ -727,7 +727,8 @@ World.prototype.getShapeFromPoint = function( offsetX, offsetY ) {
727 } 727 }
728}; 728};
729 729
730World.prototype.export = function() { 730World.prototype.export = function( imagePath )
731{
731 var exportStr = "GLWorld 1.0\n"; 732 var exportStr = "GLWorld 1.0\n";
732 var id = this.getCanvas().getAttribute( "data-RDGE-id" ); 733 var id = this.getCanvas().getAttribute( "data-RDGE-id" );
733 exportStr += "id: " + id + "\n"; 734 exportStr += "id: " + id + "\n";
@@ -736,17 +737,36 @@ World.prototype.export = function() {
736 exportStr += "zNear: " + this._zNear + "\n"; 737 exportStr += "zNear: " + this._zNear + "\n";
737 exportStr += "zFar: " + this._zFar + "\n"; 738 exportStr += "zFar: " + this._zFar + "\n";
738 exportStr += "viewDist: " + this._viewDist + "\n"; 739 exportStr += "viewDist: " + this._viewDist + "\n";
740 if (this._useWebGL)
741 exportStr += "webGL: true\n";
739 742
740 // we need 2 export modes: One for save/restore, one for publish. 743 // we need 2 export modes: One for save/restore, one for publish.
741 // hardcoding for now 744 // hardcoding for now
742 var exportForPublish = false; 745 //var exportForPublish = false;
746 //if (!exportForPublish) exportForPublish = false;
747 var exportForPublish = true;
743 exportStr += "publish: " + exportForPublish + "\n"; 748 exportStr += "publish: " + exportForPublish + "\n";
744 749
745 if (exportForPublish) { 750 // the relative path for local assets needs to be modified to
751 // the path specified by argument 'imagePath'. Save that path
752 // so exporting functions can call newPath = world.cleansePath( oldPath );
753 this._imagePath = imagePath.slice();
754 var endchar = this._imagePath[this._imagePath.length-1]
755 if (endchar != '/') this._imagePath += '/';
756
757 if (exportForPublish && this._useWebGL)
758 {
746 exportStr += "scenedata: " + this.myScene.exportJSON() + "endscene\n"; 759 exportStr += "scenedata: " + this.myScene.exportJSON() + "endscene\n";
747 } else { 760
761 // write out all of the objects
762 exportStr += "tree\n";
763 exportStr += this.exportObjects( this._geomRoot );
764 exportStr += "endtree\n";
765 }
766 else
767 {
748 // output the material library 768 // output the material library
749 exportStr += MaterialsModel.exportMaterials(); 769 //exportStr += MaterialsLibrary.export(); // THIS NEEDS TO BE DONE AT THE DOC LEVEL
750 770
751 // write out all of the objects 771 // write out all of the objects
752 exportStr += "tree\n"; 772 exportStr += "tree\n";
@@ -800,21 +820,26 @@ World.prototype.import = function( importStr ) {
800 820
801 // determine if the data was written for export (no Ninja objects) 821 // determine if the data was written for export (no Ninja objects)
802 // or for save/restore 822 // or for save/restore
803 var index = importStr.indexOf( "scenedata: " ); 823 //var index = importStr.indexOf( "scenedata: " );
804 if (index >= 0) { 824 var index = importStr.indexOf( "webGL: " );
805 var rdgeStr = importStr.substr( index+11 ); 825 this._useWebGL = (index >= 0)
806 var endIndex = rdgeStr.indexOf( "endscene\n" ); 826 if (this._useWebGL)
807 if (endIndex < 0) throw new Error( "ill-formed WebGL data" ); 827 {
808 var len = endIndex - index + 11; 828 // start RDGE
809 rdgeStr = rdgeStr.substr( 0, endIndex ); 829 rdgeStarted = true;
810 830 var id = this._canvas.getAttribute( "data-RDGE-id" );
811 this.myScene.importJSON( rdgeStr ); 831 this._canvas.rdgeid = id;
812 } else { 832 g_Engine.registerCanvas(this._canvas, this);
813 // load the material library 833 RDGEStart( this._canvas );
814 importStr = MaterialsModel.importMaterials( importStr ); 834 this._canvas.task.stop()
835 }
836
837 this.importObjects( importStr, this._rootNode );
815 838
816 // import the objects 839 if (!this._useWebGL)
817 this.importObjects( importStr, this._rootNode ); 840 {
841 // render using canvas 2D
842 this.render();
818 } 843 }
819}; 844};
820 845
@@ -912,6 +937,20 @@ World.prototype.importSubObject = function( objStr, parentNode ) {
912 return trNode; 937 return trNode;
913}; 938};
914 939
940World.prototype.cleansePath = function( url )
941{
942 //this._imagePath
943 var searchStr = "assets/";
944 var index = url.indexOf( searchStr );
945 var rtnPath = url;
946 if (index >= 0)
947 {
948 rtnPath = url.substr( index + searchStr.length );
949 rtnPath = this._imagePath + rtnPath;
950 }
951 return rtnPath;
952}
953
915if (typeof exports === "object") { 954if (typeof exports === "object") {
916 exports.World = World; 955 exports.World = World;
917} \ No newline at end of file 956} \ No newline at end of file