diff options
Diffstat (limited to 'assets')
-rw-r--r-- | assets/canvas-runtime.js | 199 | ||||
-rwxr-xr-x | assets/rdge-compiled.js | 777 |
2 files changed, 425 insertions, 551 deletions
diff --git a/assets/canvas-runtime.js b/assets/canvas-runtime.js index f53a4ef6..b4563ea5 100644 --- a/assets/canvas-runtime.js +++ b/assets/canvas-runtime.js | |||
@@ -19,7 +19,7 @@ function initWebGl (rootElement, directory) { | |||
19 | cvsDataMngr = new CanvasDataManager(); | 19 | cvsDataMngr = new CanvasDataManager(); |
20 | //Loading data to canvas(es) | 20 | //Loading data to canvas(es) |
21 | cvsDataMngr.loadGLData(rootElement, ninjaWebGlData.data, directory); | 21 | cvsDataMngr.loadGLData(rootElement, ninjaWebGlData.data, directory); |
22 | } | 22 | }; |
23 | 23 | ||
24 | /////////////////////////////////////////////////////////////////////// | 24 | /////////////////////////////////////////////////////////////////////// |
25 | // Class ShapeRuntime | 25 | // Class ShapeRuntime |
@@ -59,7 +59,7 @@ function CanvasDataManager() | |||
59 | } | 59 | } |
60 | } | 60 | } |
61 | } | 61 | } |
62 | } | 62 | }; |
63 | 63 | ||
64 | this.collectGLData = function( elt, dataArray ) | 64 | this.collectGLData = function( elt, dataArray ) |
65 | { | 65 | { |
@@ -78,7 +78,7 @@ function CanvasDataManager() | |||
78 | this.collectGLData( child, dataArray ); | 78 | this.collectGLData( child, dataArray ); |
79 | } | 79 | } |
80 | } | 80 | } |
81 | } | 81 | }; |
82 | 82 | ||
83 | this.findCanvasWithID = function( id, elt ) | 83 | this.findCanvasWithID = function( id, elt ) |
84 | { | 84 | { |
@@ -95,8 +95,8 @@ function CanvasDataManager() | |||
95 | if (foundElt) return foundElt; | 95 | if (foundElt) return foundElt; |
96 | } | 96 | } |
97 | } | 97 | } |
98 | } | 98 | }; |
99 | } | 99 | }; |
100 | 100 | ||
101 | /////////////////////////////////////////////////////////////////////// | 101 | /////////////////////////////////////////////////////////////////////// |
102 | // Class GLRuntime | 102 | // Class GLRuntime |
@@ -149,16 +149,16 @@ function GLRuntime( canvas, jObj, assetPath ) | |||
149 | /////////////////////////////////////////////////////////////////////// | 149 | /////////////////////////////////////////////////////////////////////// |
150 | // accessors | 150 | // accessors |
151 | /////////////////////////////////////////////////////////////////////// | 151 | /////////////////////////////////////////////////////////////////////// |
152 | this.getZNear = function() { return this._zNear; } | 152 | this.getZNear = function() { return this._zNear; }; |
153 | this.getZFar = function() { return this._zFar; } | 153 | this.getZFar = function() { return this._zFar; }; |
154 | this.getFOV = function() { return this._fov; } | 154 | this.getFOV = function() { return this._fov; }; |
155 | this.getAspect = function() { return this._aspect; } | 155 | this.getAspect = function() { return this._aspect; }; |
156 | this.getViewDistance = function() { return this._viewDist; } | 156 | this.getViewDistance = function() { return this._viewDist; }; |
157 | 157 | ||
158 | this.get2DContext = function() { return this._context; } | 158 | this.get2DContext = function() { return this._context; }; |
159 | 159 | ||
160 | this.getViewportWidth = function() { return this._canvas.width; } | 160 | this.getViewportWidth = function() { return this._canvas.width; }; |
161 | this.getViewportHeight = function() { return this._canvas.height; } | 161 | this.getViewportHeight = function() { return this._canvas.height; }; |
162 | 162 | ||
163 | /////////////////////////////////////////////////////////////////////// | 163 | /////////////////////////////////////////////////////////////////////// |
164 | // accessors | 164 | // accessors |
@@ -188,20 +188,20 @@ function GLRuntime( canvas, jObj, assetPath ) | |||
188 | this.importObjects( root ); | 188 | this.importObjects( root ); |
189 | this.render(); | 189 | this.render(); |
190 | } | 190 | } |
191 | } | 191 | }; |
192 | 192 | ||
193 | this.init = function() | 193 | this.init = function() |
194 | { | 194 | { |
195 | var ctx1 = g_Engine.ctxMan.handleToObject(this._canvas.rdgeCtxHandle), | 195 | var ctx1 = RDGE.globals.engine.ctxMan.handleToObject(this._canvas.rdgeCtxHandle), |
196 | ctx2 = g_Engine.getContext(); | 196 | ctx2 = RDGE.globals.engine.getContext(); |
197 | if (ctx1 != ctx2) console.log( "***** different contexts *****" ); | 197 | if (ctx1 != ctx2) console.log( "***** different contexts *****" ); |
198 | this.renderer = ctx1.renderer; | 198 | this.renderer = ctx1.renderer; |
199 | 199 | ||
200 | // create a camera, set its perspective, and then point it at the origin | 200 | // create a camera, set its perspective, and then point it at the origin |
201 | var cam = new camera(); | 201 | var cam = new RDGE.camera(); |
202 | this._camera = cam; | 202 | this._camera = cam; |
203 | cam.setPerspective(this.getFOV(), this.getAspect(), this.getZNear(), this.getZFar()); | 203 | cam.setPerspective(this.getFOV(), this.getAspect(), this.getZNear(), this.getZFar()); |
204 | cam.setLookAt([0, 0, this.getViewDistance()], [0, 0, 0], vec3.up()); | 204 | cam.setLookAt([0, 0, this.getViewDistance()], [0, 0, 0], RDGE.vec3.up()); |
205 | 205 | ||
206 | // make this camera the active camera | 206 | // make this camera the active camera |
207 | this.renderer.cameraManager().setActiveCamera(cam); | 207 | this.renderer.cameraManager().setActiveCamera(cam); |
@@ -210,17 +210,17 @@ function GLRuntime( canvas, jObj, assetPath ) | |||
210 | this.renderer.setClearColor([1.0, 1.0, 1.0, 0.0]); | 210 | this.renderer.setClearColor([1.0, 1.0, 1.0, 0.0]); |
211 | 211 | ||
212 | // create an empty scene graph | 212 | // create an empty scene graph |
213 | this.myScene = new SceneGraph(); | 213 | this.myScene = new RDGE.SceneGraph(); |
214 | 214 | ||
215 | // load the scene graph data | 215 | // load the scene graph data |
216 | this.loadScene(); | 216 | this.loadScene(); |
217 | 217 | ||
218 | // Add the scene to the engine - necessary if you want the engine to draw for you | 218 | // Add the scene to the engine - necessary if you want the engine to draw for you |
219 | var name = "myScene" + this._canvas.getAttribute( "data-RDGE-id" ); | 219 | var name = "myScene" + this._canvas.getAttribute( "data-RDGE-id" ); |
220 | g_Engine.AddScene(name, this.myScene); | 220 | RDGE.globals.engine.AddScene(name, this.myScene); |
221 | 221 | ||
222 | this._initialized = true; | 222 | this._initialized = true; |
223 | } | 223 | }; |
224 | 224 | ||
225 | // main code for handling user interaction and updating the scene | 225 | // main code for handling user interaction and updating the scene |
226 | this.update = function(dt) | 226 | this.update = function(dt) |
@@ -233,7 +233,7 @@ function GLRuntime( canvas, jObj, assetPath ) | |||
233 | this.elapsed += dt; | 233 | this.elapsed += dt; |
234 | 234 | ||
235 | // changed the global position uniform of light 0, another way to change behavior of a light | 235 | // changed the global position uniform of light 0, another way to change behavior of a light |
236 | rdgeGlobalParameters.u_light0Pos.set( [5*Math.cos(this.elapsed), 5*Math.sin(this.elapsed), 20]); | 236 | RDGE.rdgeGlobalParameters.u_light0Pos.set( [5*Math.cos(this.elapsed), 5*Math.sin(this.elapsed), 20]); |
237 | 237 | ||
238 | // orbit the light nodes around the boxes | 238 | // orbit the light nodes around the boxes |
239 | if (this.light ) 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)]); | 239 | if (this.light ) 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)]); |
@@ -244,7 +244,7 @@ function GLRuntime( canvas, jObj, assetPath ) | |||
244 | // now update all the nodes in the scene | 244 | // now update all the nodes in the scene |
245 | this.myScene.update(dt); | 245 | this.myScene.update(dt); |
246 | } | 246 | } |
247 | } | 247 | }; |
248 | 248 | ||
249 | this.updateMaterials = function() | 249 | this.updateMaterials = function() |
250 | { | 250 | { |
@@ -254,16 +254,16 @@ function GLRuntime( canvas, jObj, assetPath ) | |||
254 | var mat = this._materials[i]; | 254 | var mat = this._materials[i]; |
255 | mat.update(); | 255 | mat.update(); |
256 | } | 256 | } |
257 | } | 257 | }; |
258 | 258 | ||
259 | // defining the draw function to control how the scene is rendered | 259 | // defining the draw function to control how the scene is rendered |
260 | this.draw = function() | 260 | this.draw = function() |
261 | { | 261 | { |
262 | if (this._initialized) | 262 | if (this._initialized) |
263 | { | 263 | { |
264 | g_Engine.setContext( this._canvas.rdgeid ); | 264 | RDGE.globals.engine.setContext( this._canvas.rdgeid ); |
265 | 265 | ||
266 | var ctx = g_Engine.getContext(); | 266 | var ctx = RDGE.globals.engine.getContext(); |
267 | var renderer = ctx.renderer; | 267 | var renderer = ctx.renderer; |
268 | if (renderer.unloadedTextureCount <= 0) | 268 | if (renderer.unloadedTextureCount <= 0) |
269 | { | 269 | { |
@@ -281,7 +281,7 @@ function GLRuntime( canvas, jObj, assetPath ) | |||
281 | } | 281 | } |
282 | } | 282 | } |
283 | } | 283 | } |
284 | } | 284 | }; |
285 | 285 | ||
286 | this.importObjects = function( jObj, parent ) | 286 | this.importObjects = function( jObj, parent ) |
287 | { | 287 | { |
@@ -298,7 +298,7 @@ function GLRuntime( canvas, jObj, assetPath ) | |||
298 | this.importObjects( child, gObj ); | 298 | this.importObjects( child, gObj ); |
299 | } | 299 | } |
300 | } | 300 | } |
301 | } | 301 | }; |
302 | 302 | ||
303 | this.importObject = function( jObj, parent ) | 303 | this.importObject = function( jObj, parent ) |
304 | { | 304 | { |
@@ -330,7 +330,7 @@ function GLRuntime( canvas, jObj, assetPath ) | |||
330 | this.addObject( obj, parent ); | 330 | this.addObject( obj, parent ); |
331 | 331 | ||
332 | return obj; | 332 | return obj; |
333 | } | 333 | }; |
334 | 334 | ||
335 | this.addObject = function( obj, parent ) | 335 | this.addObject = function( obj, parent ) |
336 | { | 336 | { |
@@ -341,7 +341,7 @@ function GLRuntime( canvas, jObj, assetPath ) | |||
341 | this._geomRoot = obj; | 341 | this._geomRoot = obj; |
342 | else | 342 | else |
343 | parent.addChild( obj ); | 343 | parent.addChild( obj ); |
344 | } | 344 | }; |
345 | 345 | ||
346 | this.linkLights = function() | 346 | this.linkLights = function() |
347 | { | 347 | { |
@@ -351,7 +351,7 @@ function GLRuntime( canvas, jObj, assetPath ) | |||
351 | this.light = matNode.lightChannel[1]; | 351 | this.light = matNode.lightChannel[1]; |
352 | this.light2 = matNode.lightChannel[2]; | 352 | this.light2 = matNode.lightChannel[2]; |
353 | } | 353 | } |
354 | } | 354 | }; |
355 | 355 | ||
356 | this.linkMaterials = function( obj ) | 356 | this.linkMaterials = function( obj ) |
357 | { | 357 | { |
@@ -372,7 +372,7 @@ function GLRuntime( canvas, jObj, assetPath ) | |||
372 | this._materials.push( mat ); | 372 | this._materials.push( mat ); |
373 | } |