diff options
Diffstat (limited to 'js/helper-classes/RDGE/runtime/GLRuntime.js')
-rw-r--r-- | js/helper-classes/RDGE/runtime/GLRuntime.js | 54 |
1 files changed, 49 insertions, 5 deletions
diff --git a/js/helper-classes/RDGE/runtime/GLRuntime.js b/js/helper-classes/RDGE/runtime/GLRuntime.js index d86506ad..e0fff4a8 100644 --- a/js/helper-classes/RDGE/runtime/GLRuntime.js +++ b/js/helper-classes/RDGE/runtime/GLRuntime.js | |||
@@ -16,6 +16,7 @@ function GLRuntime( canvas, importStr ) | |||
16 | // Instance variables | 16 | // Instance variables |
17 | /////////////////////////////////////////////////////////////////////// | 17 | /////////////////////////////////////////////////////////////////////// |
18 | this._canvas = canvas; | 18 | this._canvas = canvas; |
19 | this._context = null; | ||
19 | this._importStr = importStr; | 20 | this._importStr = importStr; |
20 | 21 | ||
21 | this.renderer = null; | 22 | this.renderer = null; |
@@ -27,6 +28,8 @@ function GLRuntime( canvas, importStr ) | |||
27 | this._firstRender = true; | 28 | this._firstRender = true; |
28 | this._initialized = false; | 29 | this._initialized = false; |
29 | 30 | ||
31 | this._useWebGL = false; | ||
32 | |||
30 | // view parameters | 33 | // view parameters |
31 | this._fov = 45.0; | 34 | this._fov = 45.0; |
32 | this._zNear = 0.1; | 35 | this._zNear = 0.1; |
@@ -49,6 +52,14 @@ function GLRuntime( canvas, importStr ) | |||
49 | this.getAspect = function() { return this._aspect; } | 52 | this.getAspect = function() { return this._aspect; } |
50 | this.getViewDistance = function() { return this._viewDist; } | 53 | this.getViewDistance = function() { return this._viewDist; } |
51 | 54 | ||
55 | this.get2DContext = function() { return this._context; } | ||
56 | |||
57 | this.getViewportWidth = function() { return this._canvas.width; } | ||
58 | this.getViewportHeight = function() { return this._canvas.height; } | ||
59 | |||
60 | /////////////////////////////////////////////////////////////////////// | ||
61 | // accessors | ||
62 | /////////////////////////////////////////////////////////////////////// | ||
52 | this.loadScene = function() | 63 | this.loadScene = function() |
53 | { | 64 | { |
54 | // parse the data | 65 | // parse the data |
@@ -56,6 +67,8 @@ function GLRuntime( canvas, importStr ) | |||
56 | var index = importStr.indexOf( "scenedata: " ); | 67 | var index = importStr.indexOf( "scenedata: " ); |
57 | if (index >= 0) | 68 | if (index >= 0) |
58 | { | 69 | { |
70 | this._useWebGL = true; | ||
71 | |||
59 | var rdgeStr = importStr.substr( index+11 ); | 72 | var rdgeStr = importStr.substr( index+11 ); |
60 | var endIndex = rdgeStr.indexOf( "endscene\n" ); | 73 | var endIndex = rdgeStr.indexOf( "endscene\n" ); |
61 | if (endIndex < 0) throw new Error( "ill-formed WebGL data" ); | 74 | if (endIndex < 0) throw new Error( "ill-formed WebGL data" ); |
@@ -67,6 +80,12 @@ function GLRuntime( canvas, importStr ) | |||
67 | this.linkMaterials( this._geomRoot ); | 80 | this.linkMaterials( this._geomRoot ); |
68 | this.initMaterials(); | 81 | this.initMaterials(); |
69 | } | 82 | } |
83 | else | ||
84 | { | ||
85 | this._context = this._canvas.getContext( "2d" ); | ||
86 | this.importObjects( importStr ); | ||
87 | this.render(); | ||
88 | } | ||
70 | } | 89 | } |
71 | 90 | ||
72 | this.init = function() | 91 | this.init = function() |
@@ -230,6 +249,7 @@ function GLRuntime( canvas, importStr ) | |||
230 | this.addObject = function( obj, parent ) | 249 | this.addObject = function( obj, parent ) |
231 | { | 250 | { |
232 | if (!obj) return; | 251 | if (!obj) return; |
252 | obj.setWorld( this ); | ||
233 | 253 | ||
234 | if (parent == null) | 254 | if (parent == null) |
235 | this._geomRoot = obj; | 255 | this._geomRoot = obj; |
@@ -290,11 +310,35 @@ function GLRuntime( canvas, importStr ) | |||
290 | } | 310 | } |
291 | } | 311 | } |
292 | 312 | ||
293 | // start RDGE | 313 | this.render = function( obj ) |
294 | var id = canvas.getAttribute( "data-RDGE-id" ); | 314 | { |
295 | canvas.rdgeid = id; | 315 | if (!obj) obj = this._geomRoot; |
296 | g_Engine.registerCanvas(canvas, this); | 316 | obj.render(); |
297 | RDGEStart( canvas ); | 317 | |
318 | if (obj.children) | ||
319 | { | ||
320 | var nKids = obj.children.length; | ||
321 | for (var i=0; i<nKids; i++) | ||
322 | { | ||
323 | var child = obj.children[i]; | ||
324 | if (child) | ||
325 | this.render( child ); | ||
326 | } | ||
327 | } | ||
328 | } | ||
329 | |||
330 | // start RDGE or load Canvas 2D objects | ||
331 | if (this._useWebGL) | ||
332 | { | ||
333 | var id = canvas.getAttribute( "data-RDGE-id" ); | ||
334 | canvas.rdgeid = id; | ||
335 | g_Engine.registerCanvas(canvas, this); | ||
336 | RDGEStart( canvas ); | ||
337 | } | ||
338 | else | ||
339 | { | ||
340 | this.loadScene(); | ||
341 | } | ||
298 | } | 342 | } |
299 | 343 | ||
300 | 344 | ||