aboutsummaryrefslogtreecommitdiff
path: root/js/helper-classes/RDGE/runtime
diff options
context:
space:
mode:
Diffstat (limited to 'js/helper-classes/RDGE/runtime')
-rw-r--r--js/helper-classes/RDGE/runtime/GLRuntime.js54
-rw-r--r--js/helper-classes/RDGE/runtime/RuntimeGeomObj.js27
-rw-r--r--js/helper-classes/RDGE/runtime/RuntimeMaterial.js74
3 files changed, 145 insertions, 10 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
diff --git a/js/helper-classes/RDGE/runtime/RuntimeGeomObj.js b/js/helper-classes/RDGE/runtime/RuntimeGeomObj.js
index da941b56..2539abc1 100644
--- a/js/helper-classes/RDGE/runtime/RuntimeGeomObj.js
+++ b/js/helper-classes/RDGE/runtime/RuntimeGeomObj.js
@@ -37,7 +37,10 @@ function RuntimeGeomObj()
37 // Property accessors 37 // Property accessors
38 /////////////////////////////////////////////////////////////////////// 38 ///////////////////////////////////////////////////////////////////////
39 39
40 this.geomType = function() { return this.GEOM_TYPE_UNDEFINED; } 40 this.geomType = function() { return this.GEOM_TYPE_UNDEFINED; }
41
42 this.setWorld = function(w) { this._world = w; }
43 this.getWorld = function() { return this._world; }
41 44
42 /////////////////////////////////////////////////////////////////////// 45 ///////////////////////////////////////////////////////////////////////
43 // Methods 46 // Methods
@@ -76,8 +79,22 @@ function RuntimeGeomObj()
76 var materialType = getPropertyFromString( "material: ", importStr ); 79 var materialType = getPropertyFromString( "material: ", importStr );
77 switch (materialType) 80 switch (materialType)
78 { 81 {
79 case "flat": mat = new RuntimeFlatMaterial(); break; 82 case "flat": mat = new RuntimeFlatMaterial(); break;
80 case "pulse": mat = new RuntimePulseMaterial(); break; 83
84 case "radialGradient":
85 case "linearGradient": mat = new RuntimeLinearGradientMaterial(); break;
86
87 case "water":
88 case "tunnel":
89 case "reliefTunnel":
90 case "squareTunnel":
91 case "twist":
92 case "fly":
93 case "julia":
94 case "mandel":
95 case "star":
96 case "zinvert":
97 case "pulse": mat = new RuntimePulseMaterial(); break;
81 98
82 default: 99 default:
83 console.log( "material type: " + materialType + " is not supported" ); 100 console.log( "material type: " + materialType + " is not supported" );
@@ -146,8 +163,8 @@ function RuntimeRectangle()
146 { 163 {
147 // various declarations 164 // various declarations
148 var pt, rad, ctr, startPt, bPts; 165 var pt, rad, ctr, startPt, bPts;
149 var width = Math.round(this.getWidth()), 166 var width = Math.round(this._width),
150 height = Math.round(this.getHeight()); 167 height = Math.round(this._height);
151 168
152 pt = [inset, inset]; // top left corner 169 pt = [inset, inset]; // top left corner
153 170
diff --git a/js/helper-classes/RDGE/runtime/RuntimeMaterial.js b/js/helper-classes/RDGE/runtime/RuntimeMaterial.js
index 2ba3006e..5fe29f93 100644
--- a/js/helper-classes/RDGE/runtime/RuntimeMaterial.js
+++ b/js/helper-classes/RDGE/runtime/RuntimeMaterial.js
@@ -90,6 +90,7 @@ function RuntimePulseMaterial()
90 90
91 this.import = function( importStr ) 91 this.import = function( importStr )
92 { 92 {
93 this._texMap = getPropertyFromString( "texture: ", importStr );
93 } 94 }
94 95
95 this.init = function() 96 this.init = function()
@@ -137,4 +138,77 @@ function RuntimePulseMaterial()
137 } 138 }
138} 139}
139 140
141function RuntimeRadialGradientMaterial()
142{
143 // inherit the members of RuntimeMaterial
144 this.inheritedFrom = RuntimeMaterial;
145 this.inheritedFrom();
146
147 // setup default values
148 this._color1 = [0.25,0,0,1]; this._colorStop1 = 0.0;
149 this._color2 = [0,0.25,0,1]; this._colorStop2 = 0.3;
150 this._color3 = [0,0.25,0,1]; this._colorStop3 = 0.6;
151 this._color4 = [0,0.25,0,1]; this._colorStop4 = 1.0;
152
153 this.init = function()
154 {
155 var material = this._materialNode;
156 if (material)
157 {
158 var technique = material.shaderProgram.default;
159 var renderer = g_Engine.getContext().renderer;
160 if (renderer && technique)
161 {
162 if (this._shader && this._shader.default)
163 {