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/GLWorld.js | 5 +- js/helper-classes/RDGE/Materials/PulseMaterial.js | 3 + js/helper-classes/RDGE/Materials/WaterMaterial.js | 2 +- js/helper-classes/RDGE/runtime/GLRuntime.js | 54 +++++++++++++++-- js/helper-classes/RDGE/runtime/RuntimeGeomObj.js | 27 +++++++-- js/helper-classes/RDGE/runtime/RuntimeMaterial.js | 74 +++++++++++++++++++++++ 6 files changed, 153 insertions(+), 12 deletions(-) (limited to 'js/helper-classes/RDGE') diff --git a/js/helper-classes/RDGE/GLWorld.js b/js/helper-classes/RDGE/GLWorld.js index d9e91404..3a779b92 100755 --- a/js/helper-classes/RDGE/GLWorld.js +++ b/js/helper-classes/RDGE/GLWorld.js @@ -840,7 +840,7 @@ GLWorld.prototype.export = function( exportForPublish ) if (!exportForPublish) exportForPublish = false; exportStr += "publish: " + exportForPublish + "\n"; - if (exportForPublish) + if (exportForPublish && this._useWebGL) { exportStr += "scenedata: " + this.myScene.exportJSON() + "endscene\n"; @@ -930,6 +930,9 @@ GLWorld.prototype.import = function( importStr ) // import the objects this.importObjects( importStr, this._rootNode ); + + // render using canvas 2D + this.render(); } } diff --git a/js/helper-classes/RDGE/Materials/PulseMaterial.js b/js/helper-classes/RDGE/Materials/PulseMaterial.js index 28f2a430..b0fbd998 100644 --- a/js/helper-classes/RDGE/Materials/PulseMaterial.js +++ b/js/helper-classes/RDGE/Materials/PulseMaterial.js @@ -185,6 +185,9 @@ function PulseMaterial() // every material needs the base type and instance name var exportStr = "material: " + this.getShaderName() + "\n"; exportStr += "name: " + this.getName() + "\n"; + + var texMapName = this._propValues[this._propNames[0]]; + exportStr += "texture: " + texMapName; // every material needs to terminate like this exportStr += "endMaterial\n"; diff --git a/js/helper-classes/RDGE/Materials/WaterMaterial.js b/js/helper-classes/RDGE/Materials/WaterMaterial.js index 9ece3b45..49761c58 100644 --- a/js/helper-classes/RDGE/Materials/WaterMaterial.js +++ b/js/helper-classes/RDGE/Materials/WaterMaterial.js @@ -22,7 +22,7 @@ function WaterMaterial() this._name = "WaterMaterial"; this._shaderName = "water"; - this._texMap = 'assets/images/rocky-normal.jpg'; + this._texMap = 'assets/images/rocky-normal.jpg\n'; this._time = 0.0; this._dTime = 0.01; 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