aboutsummaryrefslogtreecommitdiff
path: root/js/lib
diff options
context:
space:
mode:
authorValerio Virgillito2012-03-13 11:15:34 -0700
committerValerio Virgillito2012-03-13 11:15:34 -0700
commitf6b958360d82854bdaf51848e7fd715d1f633179 (patch)
tree80f6c08bb730089bdd3f26310df8d2363f9ba863 /js/lib
parentc24f58c10231c30d3a8a4c9fb9a4f395dd746180 (diff)
parent4d7b86f55c504ee4e8c2460cf6b60cb9a2cf18f0 (diff)
downloadninja-f6b958360d82854bdaf51848e7fd715d1f633179.tar.gz
Merge pull request #105 from joseeight/FileIO-Build-Candidate
File I/O adding webGL/canvas data functionality
Diffstat (limited to 'js/lib')
-rwxr-xr-xjs/lib/NJUtils.js34
-rwxr-xr-xjs/lib/drawing/world.js92
-rwxr-xr-xjs/lib/geom/circle.js8
-rwxr-xr-xjs/lib/geom/geom-obj.js87
-rwxr-xr-xjs/lib/geom/rectangle.js9
-rwxr-xr-xjs/lib/rdge/materials/bump-metal-material.js10
-rw-r--r--js/lib/rdge/materials/deform-material.js2
-rwxr-xr-xjs/lib/rdge/materials/flat-material.js41
-rw-r--r--js/lib/rdge/materials/fly-material.js2
-rw-r--r--js/lib/rdge/materials/julia-material.js2
-rw-r--r--js/lib/rdge/materials/keleidoscope-material.js2
-rwxr-xr-xjs/lib/rdge/materials/linear-gradient-material.js2
-rw-r--r--js/lib/rdge/materials/mandel-material.js2
-rw-r--r--js/lib/rdge/materials/plasma-material.js37
-rw-r--r--js/lib/rdge/materials/pulse-material.js11
-rw-r--r--js/lib/rdge/materials/radial-blur-material.js9
-rwxr-xr-xjs/lib/rdge/materials/radial-gradient-material.js7
-rw-r--r--js/lib/rdge/materials/relief-tunnel-material.js2
-rw-r--r--js/lib/rdge/materials/square-tunnel-material.js2
-rw-r--r--js/lib/rdge/materials/star-material.js2
-rw-r--r--js/lib/rdge/materials/taper-material.js8
-rw-r--r--js/lib/rdge/materials/tunnel-material.js2
-rw-r--r--js/lib/rdge/materials/twist-material.js2
-rw-r--r--js/lib/rdge/materials/twist-vert-material.js6
-rwxr-xr-xjs/lib/rdge/materials/uber-material.js109
-rw-r--r--js/lib/rdge/materials/water-material.js2
-rw-r--r--js/lib/rdge/materials/z-invert-material.js2
27 files changed, 382 insertions, 112 deletions
diff --git a/js/lib/NJUtils.js b/js/lib/NJUtils.js
index e16715a4..4f1082f9 100755
--- a/js/lib/NJUtils.js
+++ b/js/lib/NJUtils.js
@@ -116,7 +116,39 @@ exports.NJUtils = Object.create(Object.prototype, {
116 ///// TODO: Selection and model should be based on the element type 116 ///// TODO: Selection and model should be based on the element type
117 makeModelFromElement: { 117 makeModelFromElement: {
118 value: function(el) { 118 value: function(el) {
119 this.makeElementModel(el, "Div", "block", false); 119 var selection = "div",
120 controller = "block",
121 isShape = false;
122 switch(el.nodeName.toLowerCase())
123 {
124 case "div":
125 break;
126 case "img":
127 selection = "image";
128 controller = "image";
129 break;
130 case "video":
131 selection = "video";
132 controller = "video";
133 break;
134 case "canvas":
135 isShape = el.getAttribute("data-RDGE-id");
136 if(isShape)
137 {
138 // TODO - Need more info about the shape
139 selection = "canvas";
140 controller = "shape";
141 }
142 else
143 {
144 selection = "canvas";
145 controller = "canvas";
146 }
147 break;
148 case "shape":
149 break;
150 }
151 this.makeElementModel(el, selection, controller, isShape);
120 } 152 }
121 }, 153 },
122 154
diff --git a/js/lib/drawing/world.js b/js/lib/drawing/world.js
index 3d6c6fc4..44c9e37d 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()
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,29 @@ 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 if (exportForPublish && this._useWebGL)
751 {
746 exportStr += "scenedata: " + this.myScene.exportJSON() + "endscene\n"; 752 exportStr += "scenedata: " + this.myScene.exportJSON() + "endscene\n";
747 } else { 753
754 // write out all of the objects
755 exportStr += "tree\n";
756 exportStr += this.exportObjects( this._geomRoot );