diff options
author | hwc487 | 2012-02-29 15:23:28 -0800 |
---|---|---|
committer | hwc487 | 2012-02-29 15:23:28 -0800 |
commit | 07c48708a99b94a220c043ad5951a331bbd4fc2d (patch) | |
tree | 6fdf01f3d0fca0cf5835246bed21d6ae1816ce88 /js/helper-classes | |
parent | 347fc28227d822e9fea3fa823fae79cf14ea041c (diff) | |
download | ninja-07c48708a99b94a220c043ad5951a331bbd4fc2d.tar.gz |
WebGL file I/O
Diffstat (limited to 'js/helper-classes')
-rwxr-xr-x | js/helper-classes/RDGE/GLRectangle.js | 8 | ||||
-rwxr-xr-x | js/helper-classes/RDGE/GLWorld.js | 5 | ||||
-rw-r--r-- | js/helper-classes/RDGE/runtime/CanvasDataManager.js | 10 | ||||
-rw-r--r-- | js/helper-classes/RDGE/runtime/GLRuntime.js | 87 |
4 files changed, 69 insertions, 41 deletions
diff --git a/js/helper-classes/RDGE/GLRectangle.js b/js/helper-classes/RDGE/GLRectangle.js index a801d3c4..f44350df 100755 --- a/js/helper-classes/RDGE/GLRectangle.js +++ b/js/helper-classes/RDGE/GLRectangle.js | |||
@@ -274,10 +274,10 @@ function GLRectangle() | |||
274 | brRadius = -z*(r-l)/(2.0*zn)*brRadiusNDC; | 274 | brRadius = -z*(r-l)/(2.0*zn)*brRadiusNDC; |
275 | 275 | ||
276 | // stroke | 276 | // stroke |
277 | var strokeMaterial = this.makeStrokeMaterial(); | 277 | // var strokeMaterial = this.makeStrokeMaterial(); |
278 | var strokePrim = this.createStroke([x,y], 2*xFill, 2*yFill, strokeSize, tlRadius, blRadius, brRadius, trRadius, strokeMaterial); | 278 | // var strokePrim = this.createStroke([x,y], 2*xFill, 2*yFill, strokeSize, tlRadius, blRadius, brRadius, trRadius, strokeMaterial); |
279 | this._primArray.push( strokePrim ); | 279 | // this._primArray.push( strokePrim ); |
280 | this._materialNodeArray.push( strokeMaterial.getMaterialNode() ); | 280 | // this._materialNodeArray.push( strokeMaterial.getMaterialNode() ); |
281 | 281 | ||
282 | // fill | 282 | // fill |
283 | tlRadius -= strokeSize; if (tlRadius < 0) tlRadius = 0.0; | 283 | tlRadius -= strokeSize; if (tlRadius < 0) tlRadius = 0.0; |
diff --git a/js/helper-classes/RDGE/GLWorld.js b/js/helper-classes/RDGE/GLWorld.js index 8017207f..0ab3c242 100755 --- a/js/helper-classes/RDGE/GLWorld.js +++ b/js/helper-classes/RDGE/GLWorld.js | |||
@@ -811,7 +811,7 @@ GLWorld.prototype.getShapeFromPoint = function( offsetX, offsetY ) | |||
811 | } | 811 | } |
812 | } | 812 | } |
813 | 813 | ||
814 | GLWorld.prototype.export = function() | 814 | GLWorld.prototype.export = function( exportForPublish ) |
815 | { | 815 | { |
816 | var exportStr = "GLWorld 1.0\n"; | 816 | var exportStr = "GLWorld 1.0\n"; |
817 | var id = this.getCanvas().getAttribute( "data-RDGE-id" ); | 817 | var id = this.getCanvas().getAttribute( "data-RDGE-id" ); |
@@ -824,7 +824,8 @@ GLWorld.prototype.export = function() | |||
824 | 824 | ||
825 | // we need 2 export modes: One for save/restore, one for publish. | 825 | // we need 2 export modes: One for save/restore, one for publish. |
826 | // hardcoding for now | 826 | // hardcoding for now |
827 | var exportForPublish = false; | 827 | //var exportForPublish = false; |
828 | if (!exportForPublish) exportForPublish = false; | ||
828 | exportStr += "publish: " + exportForPublish + "\n"; | 829 | exportStr += "publish: " + exportForPublish + "\n"; |
829 | 830 | ||
830 | if (exportForPublish) | 831 | if (exportForPublish) |
diff --git a/js/helper-classes/RDGE/runtime/CanvasDataManager.js b/js/helper-classes/RDGE/runtime/CanvasDataManager.js index 4985fc9a..46d944a1 100644 --- a/js/helper-classes/RDGE/runtime/CanvasDataManager.js +++ b/js/helper-classes/RDGE/runtime/CanvasDataManager.js | |||
@@ -29,9 +29,10 @@ function CanvasDataManager() | |||
29 | var canvas = this.findCanvasWithID( id, root ); | 29 | var canvas = this.findCanvasWithID( id, root ); |
30 | if (canvas) | 30 | if (canvas) |
31 | { | 31 | { |
32 | var loadForAuthoring = true; | 32 | //var loadForAuthoring = true; |
33 | var index = importStr.indexOf( "scenedata: " ); | 33 | var index = importStr.indexOf( "scenedata: " ); |
34 | if (index >= 0) loadForAuthoring = false; | 34 | //if (index >= 0) loadForAuthoring = false; |
35 | var loadForAuthoring = false; | ||
35 | 36 | ||
36 | if (loadForAuthoring) | 37 | if (loadForAuthoring) |
37 | { | 38 | { |
@@ -64,7 +65,7 @@ function CanvasDataManager() | |||
64 | { | 65 | { |
65 | if (elt.elementModel && elt.elementModel.shapeModel && elt.elementModel.shapeModel.GLWorld) | 66 | if (elt.elementModel && elt.elementModel.shapeModel && elt.elementModel.shapeModel.GLWorld) |
66 | { | 67 | { |
67 | var data = elt.elementModel.shapeModel.GLWorld.export(); | 68 | var data = elt.elementModel.shapeModel.GLWorld.export( true ); |
68 | dataArray.push( data ); | 69 | dataArray.push( data ); |
69 | } | 70 | } |
70 | 71 | ||
@@ -90,7 +91,8 @@ function CanvasDataManager() | |||
90 | for (var i=0; i<nKids; i++) | 91 | for (var i=0; i<nKids; i++) |
91 | { | 92 | { |
92 | var child = elt.children[i]; | 93 | var child = elt.children[i]; |
93 | this.findCanvasWithID( id, child ); | 94 | var foundElt = this.findCanvasWithID( id, child ); |
95 | if (foundElt) return foundElt; | ||
94 | } | 96 | } |
95 | } | 97 | } |
96 | } | 98 | } |
diff --git a/js/helper-classes/RDGE/runtime/GLRuntime.js b/js/helper-classes/RDGE/runtime/GLRuntime.js index 5c99be02..33186174 100644 --- a/js/helper-classes/RDGE/runtime/GLRuntime.js +++ b/js/helper-classes/RDGE/runtime/GLRuntime.js | |||
@@ -25,14 +25,24 @@ function GLRuntime( canvas, importStr ) | |||
25 | this._rootNode = null; | 25 | this._rootNode = null; |
26 | 26 | ||
27 | this._firstRender = true; | 27 | this._firstRender = true; |
28 | this._initialized = false; | ||
29 | |||
30 | // view parameters | ||
31 | this._fov = 45.0; | ||
32 | this._zNear = 0.1; | ||
33 | this._zFar = 100.0; | ||
34 | this._viewDist = 5.0; | ||
35 | |||
36 | this._aspect = canvas.width/canvas.height; | ||
28 | 37 | ||
29 | /////////////////////////////////////////////////////////////////////// | 38 | /////////////////////////////////////////////////////////////////////// |
30 | // initialization code | 39 | // accessors |
31 | /////////////////////////////////////////////////////////////////////// | 40 | /////////////////////////////////////////////////////////////////////// |
32 | var id = canvas.getAttribute( "data-RDGE-id" ); | 41 | this.getZNear = function() { return this._zNear; } |
33 | canvas.rdgeid = id; | 42 | this.getZFar = function() { return this._zFar; } |
34 | g_Engine.registerCanvas(canvas, this); | 43 | this.getFOV = function() { return this._fov; } |
35 | RDGEStart( canvas ); | 44 | this.getAspect = function() { return this._aspect; } |
45 | this.getViewDistance = function() { return this._viewDist; } | ||
36 | 46 | ||
37 | this.loadScene = function() | 47 | this.loadScene = function() |
38 | { | 48 | { |
@@ -72,8 +82,7 @@ function GLRuntime( canvas, importStr ) | |||
72 | 82 | ||
73 | // create an empty scene graph | 83 | // create an empty scene graph |
74 | this.myScene = new SceneGraph(); | 84 | this.myScene = new SceneGraph(); |
75 | this.loadScene(); | 85 | |
76 | |||
77 | /* | 86 | /* |
78 | // create some lights | 87 | // create some lights |
79 | // light 1 | 88 | // light 1 |
@@ -104,54 +113,70 @@ function GLRuntime( canvas, importStr ) | |||
104 | */ | 113 | */ |
105 | 114 | ||
106 | // load the scene graph data | 115 | // load the scene graph data |
116 | this.loadScene(); | ||
107 | 117 | ||
108 | // Add the scene to the engine - necessary if you want the engine to draw for you | 118 | // Add the scene to the engine - necessary if you want the engine to draw for you |
109 | var name = "myScene" + this._canvas.getAttribute( "data-RDGE-id" ); | 119 | //var name = "myScene" + this._canvas.getAttribute( "data-RDGE-id" ); |
110 | g_Engine.AddScene(name, this.myScene); | 120 | //g_Engine.AddScene(name, this.myScene); |
121 | |||
122 | this._initialized = true; | ||
111 | } | 123 | } |
112 | 124 | ||
113 | // main code for handling user interaction and updating the scene | 125 | // main code for handling user interaction and updating the scene |
114 | this.update = function(dt) | 126 | this.update = function(dt) |
115 | { | 127 | { |
116 | if (!dt) dt = 0.2; | 128 | if (this._initialized) |
129 | { | ||
130 | if (!dt) dt = 0.2; | ||
117 | 131 | ||
118 | dt = 0.01; // use our own internal throttle | 132 | dt = 0.01; // use our own internal throttle |
119 | this.elapsed += dt; | 133 | this.elapsed += dt; |
120 | 134 | ||
121 | // changed the global position uniform of light 0, another way to change behavior of a light | 135 | // changed the global position uniform of light 0, another way to change behavior of a light |
122 | rdgeGlobalParameters.u_light0Pos.set( [5*Math.cos(this.elapsed), 5*Math.sin(this.elapsed), 20]); | 136 | //rdgeGlobalParameters.u_light0Pos.set( [5*Math.cos(this.elapsed), 5*Math.sin(this.elapsed), 20]); |
123 | 137 | ||
124 | // orbit the light nodes around the boxes | 138 | // orbit the light nodes around the boxes |
125 | this.light.setPosition([1.2*Math.cos(this.elapsed*2.0), 1.2*Math.sin(this.elapsed*2.0), 1.2*Math.cos(this.elapsed*2.0)]); | 139 | //this.light.setPosition([1.2*Math.cos(this.elapsed*2.0), 1.2*Math.sin(this.elapsed*2.0), 1.2*Math.cos(this.elapsed*2.0)]); |
126 | this.light2.setPosition([-1.2*Math.cos(this.elapsed*2.0), 1.2*Math.sin(this.elapsed*2.0), -1.2*Math.cos(this.elapsed)]); | 140 | //this.light2.setPosition([-1.2*Math.cos(this.elapsed*2.0), 1.2*Math.sin(this.elapsed*2.0), -1.2*Math.cos(this.elapsed)]); |
127 | 141 | ||
128 | // now update all the nodes in the scene | 142 | // now update all the nodes in the scene |
129 | this.myScene.update(dt); | 143 | this.myScene.update(dt); |
144 | } | ||
130 | } | 145 | } |
131 | 146 | ||
132 | // defining the draw function to control how the scene is rendered | 147 | // defining the draw function to control how the scene is rendered |
133 | this.draw = function() | 148 | this.draw = function() |
134 | { | 149 | { |
135 | g_Engine.setContext( this._canvas.rdgeid ); | 150 | if (this._initialized) |
136 | |||
137 | var ctx = g_Engine.getContext(); | ||
138 | var renderer = ctx.renderer; | ||
139 | if (renderer.unloadedTextureCount <= 0) | ||
140 | { | 151 | { |
141 | renderer.disableCulling(); | 152 | g_Engine.setContext( this._canvas.rdgeid ); |
142 | renderer._clear(); | ||
143 | this.myScene.render(); | ||
144 | 153 | ||
145 | if (this._firstRender) | 154 | var ctx = g_Engine.getContext(); |
155 | var renderer = ctx.renderer; | ||
156 | if (renderer.unloadedTextureCount <= 0) | ||
146 | { | 157 | { |
147 | if (this._canvas.task) | 158 | renderer.disableCulling(); |
159 | renderer._clear(); | ||
160 |