diff options
author | John Mayhew | 2012-04-02 16:28:39 -0700 |
---|---|---|
committer | John Mayhew | 2012-04-02 16:28:39 -0700 |
commit | b4155fb4c33675a8a7cd37473513718043fdf0ba (patch) | |
tree | 3d8c802473f2395d53d599ec9d8b70b60a4db50c /js/lib/drawing | |
parent | 5ba9aeac94c86049423fd5d4b37b277263939c13 (diff) | |
parent | c6de22bf42be90b403491b5f87b1818d9020310c (diff) | |
download | ninja-b4155fb4c33675a8a7cd37473513718043fdf0ba.tar.gz |
Merge branch 'master' of github.com:Motorola-Mobility/ninja-internal into WorkingBranch
Conflicts:
js/helper-classes/RDGE/rdge-compiled.js
js/helper-classes/RDGE/runtime/GLRuntime.js
js/helper-classes/RDGE/src/core/script/MeshManager.js
js/helper-classes/RDGE/src/core/script/engine.js
js/helper-classes/RDGE/src/core/script/fx/ssao.js
js/helper-classes/RDGE/src/core/script/init_state.js
js/helper-classes/RDGE/src/core/script/run_state.js
js/helper-classes/RDGE/src/core/script/scenegraphNodes.js
js/helper-classes/RDGE/src/core/script/utilities.js
js/helper-classes/RDGE/src/tools/compile-rdge-core.bat
js/helper-classes/RDGE/src/tools/compile-rdge-core.sh
js/helper-classes/RDGE/src/tools/rdge-compiled.js
js/lib/drawing/world.js
js/lib/rdge/materials/bump-metal-material.js
js/lib/rdge/materials/deform-material.js
js/lib/rdge/materials/flat-material.js
js/lib/rdge/materials/fly-material.js
js/lib/rdge/materials/julia-material.js
js/lib/rdge/materials/keleidoscope-material.js
js/lib/rdge/materials/linear-gradient-material.js
js/lib/rdge/materials/mandel-material.js
js/lib/rdge/materials/plasma-material.js
js/lib/rdge/materials/pulse-material.js
js/lib/rdge/materials/radial-blur-material.js
js/lib/rdge/materials/radial-gradient-material.js
js/lib/rdge/materials/relief-tunnel-material.js
js/lib/rdge/materials/square-tunnel-material.js
js/lib/rdge/materials/star-material.js
js/lib/rdge/materials/taper-material.js
js/lib/rdge/materials/tunnel-material.js
js/lib/rdge/materials/twist-material.js
js/lib/rdge/materials/twist-vert-material.js
js/lib/rdge/materials/uber-material.js
js/lib/rdge/materials/water-material.js
js/lib/rdge/materials/z-invert-material.js
js/preloader/Preloader.js
Diffstat (limited to 'js/lib/drawing')
-rwxr-xr-x | js/lib/drawing/world.js | 272 |
1 files changed, 230 insertions, 42 deletions
diff --git a/js/lib/drawing/world.js b/js/lib/drawing/world.js index 7c5fb136..436853bd 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 | /* | ||
10 | var shaderProgramArray = new Array; | ||
11 | var glContextArray = new Array; | ||
12 | var vertexShaderSource = ""; | ||
13 | var fragmentShaderSource = ""; | ||
14 | var rdgeStarted = false; | ||
15 | */ | ||
16 | |||
17 | var nodeCounter = 0; | ||
18 | 7 | ||
19 | var GeomObj = require("js/lib/geom/geom-obj").GeomObj; | 8 | var GeomObj = require("js/lib/geom/geom-obj").GeomObj; |
20 | var Line = require("js/lib/geom/line").Line; | 9 | var Line = require("js/lib/geom/line").Line; |
@@ -22,11 +11,13 @@ var Rectangle = require("js/lib/geom/rectangle").Rectangle; | |||
22 | var Circle = require("js/lib/geom/circle").Circle; | 11 | var Circle = require("js/lib/geom/circle").Circle; |
23 | var MaterialsModel = require("js/models/materials-model").MaterialsModel; | 12 | var MaterialsModel = require("js/models/materials-model").MaterialsModel; |
24 | 13 | ||
14 | var worldCounter = 0; | ||
15 | |||
25 | /////////////////////////////////////////////////////////////////////// | 16 | /////////////////////////////////////////////////////////////////////// |
26 | // Class GLWorld | 17 | // Class GLWorld |
27 | // Manages display in a canvas | 18 | // Manages display in a canvas |
28 | /////////////////////////////////////////////////////////////////////// | 19 | /////////////////////////////////////////////////////////////////////// |
29 | var World = function GLWorld( canvas, use3D ) { | 20 | var World = function GLWorld( canvas, use3D, preserveDrawingBuffer ) { |
30 | /////////////////////////////////////////////////////////////////////// | 21 | /////////////////////////////////////////////////////////////////////// |
31 | // Instance variables | 22 | // Instance variables |
32 | /////////////////////////////////////////////////////////////////////// | 23 | /////////////////////////////////////////////////////////////////////// |
@@ -39,7 +30,11 @@ var World = function GLWorld( canvas, use3D ) { | |||
39 | 30 | ||
40 | this._canvas = canvas; | 31 | this._canvas = canvas; |
41 | if (this._useWebGL) { | 32 | if (this._useWebGL) { |
33 | if(preserveDrawingBuffer) { | ||
34 | this._glContext = canvas.getContext("experimental-webgl", {preserveDrawingBuffer: true}); | ||
35 | } else { | ||
42 | this._glContext = canvas.getContext("experimental-webgl"); | 36 | this._glContext = canvas.getContext("experimental-webgl"); |
37 | } | ||
43 | } else { | 38 | } else { |
44 | this._2DContext = canvas.getContext( "2d" ); | 39 | this._2DContext = canvas.getContext( "2d" ); |
45 | } | 40 | } |
@@ -76,6 +71,12 @@ var World = function GLWorld( canvas, use3D ) { | |||
76 | // no animated materials | 71 | // no animated materials |
77 | this._firstRender = true; | 72 | this._firstRender = true; |
78 | 73 | ||
74 | this._worldCount = worldCounter; | ||
75 | worldCounter++; | ||
76 | |||
77 | // keep a counter for generating node names | ||
78 | this._nodeCounter = 0; | ||
79 | |||
79 | /////////////////////////////////////////////////////////////////////// | 80 | /////////////////////////////////////////////////////////////////////// |
80 | // Property accessors | 81 | // Property accessors |
81 | /////////////////////////////////////////////////////////////////////// | 82 | /////////////////////////////////////////////////////////////////////// |
@@ -116,6 +117,8 @@ var World = function GLWorld( canvas, use3D ) { | |||
116 | 117 | ||
117 | this.getRenderer = function() { return this.renderer; }; | 118 | this.getRenderer = function() { return this.renderer; }; |
118 | 119 | ||
120 | // Flag to play/pause animation at authortime | ||
121 | this._previewAnimation = true; | ||
119 | //////////////////////////////////////////////////////////////////////////////////// | 122 | //////////////////////////////////////////////////////////////////////////////////// |
120 | // RDGE | 123 | // RDGE |
121 | // local variables | 124 | // local variables |
@@ -235,7 +238,7 @@ var World = function GLWorld( canvas, use3D ) { | |||
235 | if (this._canvas.task) { | 238 | if (this._canvas.task) { |
236 | this._firstRender = false; | 239 | this._firstRender = false; |
237 | 240 | ||
238 | if (!this.hasAnimatedMaterials()) { | 241 | if (!this.hasAnimatedMaterials() || !this._previewAnimation) { |
239 | this._canvas.task.stop(); | 242 | this._canvas.task.stop(); |
240 | //this._renderCount = 10; | 243 | //this._renderCount = 10; |
241 | } | 244 | } |
@@ -350,17 +353,19 @@ var World = function GLWorld( canvas, use3D ) { | |||
350 | return false; | 353 | return false; |
351 | }; | 354 | }; |
352 | 355 | ||
353 | 356 | this.generateUniqueNodeID = function() { | |
354 | // END RDGE | 357 | var str = "" + this._nodeCounter; |
355 | //////////////////////////////////////////////////////////////////////////////////// | 358 | this._nodeCounter++; |
359 | return str; | ||
360 | }; | ||
356 | 361 | ||
357 | 362 | ||
358 | // start RDGE passing your runtime object, and false to indicate we don't need a an initialization state | 363 | // start RDGE passing your runtime object, and false to indicate we don't need a an initialization state |
359 | // in the case of a procedurally built scene an init state is not needed for loading data | 364 | // in the case of a procedurally built scene an init state is not needed for loading data |
360 | if (this._useWebGL) { | 365 | if (this._useWebGL) { |
361 | rdgeStarted = true; | 366 | rdgeStarted = true; |
362 | var id = this._canvas.getAttribute( "data-RDGE-id" ); | 367 | this._canvas.rdgeid = this._canvas.getAttribute( "data-RDGE-id" ); |
363 | this._canvas.rdgeid = id; | 368 | RDGE.globals.engine.unregisterCanvas( this._canvas ); |
364 | RDGE.globals.engine.registerCanvas(this._canvas, this); | 369 | RDGE.globals.engine.registerCanvas(this._canvas, this); |
365 | RDGE.RDGEStart( this._canvas ); | 370 | RDGE.RDGEStart( this._canvas ); |
366 | this._canvas.task.stop() | 371 | this._canvas.task.stop() |
@@ -391,7 +396,7 @@ World.prototype.updateObject = function (obj) { | |||
391 | if (nPrims > 0) { | 396 | if (nPrims > 0) { |
392 | ctrTrNode = obj.getTransformNode(); | 397 | ctrTrNode = obj.getTransformNode(); |
393 | if (ctrTrNode == null) { | 398 | if (ctrTrNode == null) { |
394 | ctrTrNode = RDGE.createTransformNode("objRootNode_" + nodeCounter++); | 399 | ctrTrNode = RDGE.createTransformNode("objRootNode_" + this._nodeCounter++); |
395 | this._rootNode.insertAsChild( ctrTrNode ); | 400 | this._rootNode.insertAsChild( ctrTrNode ); |
396 | obj.setTransformNode( ctrTrNode ); | 401 | obj.setTransformNode( ctrTrNode ); |
397 | } | 402 | } |
@@ -401,7 +406,7 @@ World.prototype.updateObject = function (obj) { | |||
401 | }); | 406 | }); |
402 | ctrTrNode.meshes = []; | 407 | ctrTrNode.meshes = []; |
403 | 408 | ||
404 | ctrTrNode.attachMeshNode(this.renderer.id + "_prim_" + nodeCounter++, prims[0]); | 409 | ctrTrNode.attachMeshNode(this.renderer.id + "_prim_" + this._nodeCounter++, prims[0]); |
405 | ctrTrNode.attachMaterial(materialNodes[0]); | 410 | ctrTrNode.attachMaterial(materialNodes[0]); |
406 | } | 411 | } |
407 | 412 | ||
@@ -420,12 +425,12 @@ World.prototype.updateObject = function (obj) { | |||
420 | }); | 425 | }); |
421 | childTrNode.meshes = []; | 426 | childTrNode.meshes = []; |
422 | } else { | 427 | } else { |
423 | childTrNode = RDGE.createTransformNode("objNode_" + nodeCounter++); | 428 | childTrNode = RDGE.createTransformNode("objNode_" + this._nodeCounter++); |
424 | ctrTrNode.insertAsChild(childTrNode); | 429 | ctrTrNode.insertAsChild(childTrNode); |
425 | } | 430 | } |
426 | 431 | ||
427 | // attach the instanced box goe | 432 | // attach the instanced box goe |
428 | childTrNode.attachMeshNode(this.renderer.id + "_prim_" + nodeCounter++, prim); | 433 | childTrNode.attachMeshNode(this.renderer.id + "_prim_" + this._nodeCounter++, prim); |
429 | childTrNode.attachMaterial(materialNodes[i]); | 434 | childTrNode.attachMaterial(materialNodes[i]); |
430 | } | 435 | } |
431 | }; | 436 | }; |
@@ -680,7 +685,7 @@ World.prototype.render = function() { | |||
680 | var root = this.getGeomRoot(); | 685 | var root = this.getGeomRoot(); |
681 | this.hRender( root ); | 686 | this.hRender( root ); |
682 | } else { | 687 | } else { |
683 | RDGE.globals.engine.setContext( this._canvas.rdgeId ); | 688 | RDGE.globals.engine.setContext( this._canvas.rdgeid ); |
684 | //this.draw(); | 689 | //this.draw(); |
685 | this.restartRenderLoop(); | 690 | this.restartRenderLoop(); |
686 | } | 691 | } |
@@ -727,7 +732,87 @@ World.prototype.getShapeFromPoint = function( offsetX, offsetY ) { | |||
727 | } | 732 | } |
728 | }; | 733 | }; |
729 | 734 | ||
730 | World.prototype.export = function() { | 735 | |
736 | |||
737 | World.prototype.exportJSON = function() | ||
738 | { | ||
739 | // world properties | ||
740 | var worldObj = | ||
741 | { | ||
742 | 'version' : 1.1, | ||
743 | 'id' : this.getCanvas().getAttribute( "data-RDGE-id" ), | ||
744 | 'fov' : this._fov, | ||
745 | 'zNear' : this._zNear, | ||
746 | 'zFar' : this._zFar, | ||
747 | 'viewDist' : this._viewDist, | ||
748 | 'webGL' : this._useWebGL | ||
749 | }; | ||
750 | |||
751 | // RDGE scenegraph | ||
752 | if (this._useWebGL) | ||
753 | worldObj.scenedata = this.myScene.exportJSON(); | ||
754 | |||
755 | // object data | ||
756 | var strArray = []; | ||
757 | this.exportObjectsJSON( this._geomRoot, worldObj ); | ||
758 | |||
759 | // You would think that the RDGE export function | ||
760 | // would not be destructive of the data. You would be wrong... | ||
761 | // We need to rebuild everything | ||
762 | if (this._useWebGL) | ||
763 | { | ||
764 | if (worldObj.children && (worldObj.children.length === 1)) | ||
765 | { | ||
766 | this.rebuildTree(this._geomRoot); | ||
767 | this.restartRenderLoop(); | ||
768 | } | ||
769 | } | ||
770 | |||
771 | // convert the object to a string | ||
772 | var jStr = JSON.stringify( worldObj ); | ||
773 | |||
774 | // prepend some version information to the string. | ||
775 | // this string is also used to differentiate between JSON | ||
776 | // and pre-JSON versions of fileIO. | ||
777 | // the ending ';' in the version string is necessary | ||
778 | jStr = "v1.0;" + jStr; | ||
779 |