From cad4d6cb3f667f6174ec05cecead675b244285b9 Mon Sep 17 00:00:00 2001 From: hwc487 Date: Mon, 5 Mar 2012 04:51:31 -0800 Subject: Added more materials/canvas2D drawing to runtime. --- js/helper-classes/RDGE/runtime/GLRuntime.js | 54 +++++++++++++++-- js/helper-classes/RDGE/runtime/RuntimeGeomObj.js | 27 +++++++-- js/helper-classes/RDGE/runtime/RuntimeMaterial.js | 74 +++++++++++++++++++++++ 3 files changed, 145 insertions(+), 10 deletions(-) (limited to 'js/helper-classes/RDGE/runtime') 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 ) // Instance variables /////////////////////////////////////////////////////////////////////// this._canvas = canvas; + this._context = null; this._importStr = importStr; this.renderer = null; @@ -27,6 +28,8 @@ function GLRuntime( canvas, importStr ) this._firstRender = true; this._initialized = false; + this._useWebGL = false; + // view parameters this._fov = 45.0; this._zNear = 0.1; @@ -49,6 +52,14 @@ function GLRuntime( canvas, importStr ) this.getAspect = function() { return this._aspect; } this.getViewDistance = function() { return this._viewDist; } + this.get2DContext = function() { return this._context; } + + this.getViewportWidth = function() { return this._canvas.width; } + this.getViewportHeight = function() { return this._canvas.height; } + + /////////////////////////////////////////////////////////////////////// + // accessors + /////////////////////////////////////////////////////////////////////// this.loadScene = function() { // parse the data @@ -56,6 +67,8 @@ function GLRuntime( canvas, importStr ) var index = importStr.indexOf( "scenedata: " ); if (index >= 0) { + this._useWebGL = true; + var rdgeStr = importStr.substr( index+11 ); var endIndex = rdgeStr.indexOf( "endscene\n" ); if (endIndex < 0) throw new Error( "ill-formed WebGL data" ); @@ -67,6 +80,12 @@ function GLRuntime( canvas, importStr ) this.linkMaterials( this._geomRoot ); this.initMaterials(); } + else + { + this._context = this._canvas.getContext( "2d" ); + this.importObjects( importStr ); + this.render(); + } } this.init = function() @@ -230,6 +249,7 @@ function GLRuntime( canvas, importStr ) this.addObject = function( obj, parent ) { if (!obj) return; + obj.setWorld( this ); if (parent == null) this._geomRoot = obj; @@ -290,11 +310,35 @@ function GLRuntime( canvas, importStr ) } } - // start RDGE - var id = canvas.getAttribute( "data-RDGE-id" ); - canvas.rdgeid = id; - g_Engine.registerCanvas(canvas, this); - RDGEStart( canvas ); + this.render = function( obj ) + { + if (!obj) obj = this._geomRoot; + obj.render(); + + if (obj.children) + { + var nKids = obj.children.length; + for (var i=0; i