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/CanvasDataManager.js33
-rw-r--r--js/helper-classes/RDGE/runtime/GLRuntime.js303
-rw-r--r--js/helper-classes/RDGE/runtime/RuntimeGeomObj.js611
-rw-r--r--js/helper-classes/RDGE/runtime/RuntimeMaterial.js282
4 files changed, 1144 insertions, 85 deletions
diff --git a/js/helper-classes/RDGE/runtime/CanvasDataManager.js b/js/helper-classes/RDGE/runtime/CanvasDataManager.js
index 4985fc9a..efbfe4db 100644
--- a/js/helper-classes/RDGE/runtime/CanvasDataManager.js
+++ b/js/helper-classes/RDGE/runtime/CanvasDataManager.js
@@ -12,7 +12,7 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot
12/////////////////////////////////////////////////////////////////////// 12///////////////////////////////////////////////////////////////////////
13function CanvasDataManager() 13function CanvasDataManager()
14{ 14{
15 this.loadGLData = function(root, valueArray) 15 this.loadGLData = function(root, valueArray, NinjaUtils)
16 { 16 {
17 var value = valueArray; 17 var value = valueArray;
18 var nWorlds = value.length; 18 var nWorlds = value.length;
@@ -29,31 +29,7 @@ function CanvasDataManager()
29 var canvas = this.findCanvasWithID( id, root ); 29 var canvas = this.findCanvasWithID( id, root );
30 if (canvas) 30 if (canvas)
31 { 31 {
32 var loadForAuthoring = true; 32 var rt = new GLRuntime( canvas, importStr );
33 var index = importStr.indexOf( "scenedata: " );
34 if (index >= 0) loadForAuthoring = false;
35
36 if (loadForAuthoring)
37 {
38 if (!canvas.elementModel)
39 {
40 NJUtils.makeElementModel(canvas, "Canvas", "shape", true);
41 }
42
43 if (canvas.elementModel)
44 {
45 if (canvas.elementModel.shapeModel.GLWorld)
46 canvas.elementModel.shapeModel.GLWorld.clearTree();
47
48 var world = new GLWorld( canvas );
49 canvas.elementModel.shapeModel.GLWorld = world;
50 world.import( importStr );
51 }
52 }
53 else
54 {
55 var rt = new GLRuntime( canvas, importStr );
56 }
57 } 33 }
58 } 34 }
59 } 35 }
@@ -64,7 +40,7 @@ function CanvasDataManager()
64 { 40 {
65 if (elt.elementModel && elt.elementModel.shapeModel && elt.elementModel.shapeModel.GLWorld) 41 if (elt.elementModel && elt.elementModel.shapeModel && elt.elementModel.shapeModel.GLWorld)
66 { 42 {
67 var data = elt.elementModel.shapeModel.GLWorld.export(); 43 var data = elt.elementModel.shapeModel.GLWorld.export( true );
68 dataArray.push( data ); 44 dataArray.push( data );
69 } 45 }
70 46
@@ -90,7 +66,8 @@ function CanvasDataManager()
90 for (var i=0; i<nKids; i++) 66 for (var i=0; i<nKids; i++)
91 { 67 {
92 var child = elt.children[i]; 68 var child = elt.children[i];
93 this.findCanvasWithID( id, child ); 69 var foundElt = this.findCanvasWithID( id, child );
70 if (foundElt) return foundElt;
94 } 71 }
95 } 72 }
96 } 73 }
diff --git a/js/helper-classes/RDGE/runtime/GLRuntime.js b/js/helper-classes/RDGE/runtime/GLRuntime.js
index 5c99be02..58cb4e33 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;
@@ -25,15 +26,40 @@ function GLRuntime( canvas, importStr )
25 this._rootNode = null; 26 this._rootNode = null;
26 27
27 this._firstRender = true; 28 this._firstRender = true;
29 this._initialized = false;
30
31 this._useWebGL = false;
32
33 // view parameters
34 this._fov = 45.0;
35 this._zNear = 0.1;
36 this._zFar = 100.0;
37 this._viewDist = 5.0;
38
39 this._aspect = canvas.width/canvas.height;
40
41 this._geomRoot;
42
43 // all "live" materials
44 this._materials = [];
28 45
29 /////////////////////////////////////////////////////////////////////// 46 ///////////////////////////////////////////////////////////////////////
30 // initialization code 47 // accessors
31 /////////////////////////////////////////////////////////////////////// 48 ///////////////////////////////////////////////////////////////////////
32 var id = canvas.getAttribute( "data-RDGE-id" ); 49 this.getZNear = function() { return this._zNear; }
33 canvas.rdgeid = id; 50 this.getZFar = function() { return this._zFar; }
34 g_Engine.registerCanvas(canvas, this); 51 this.getFOV = function() { return this._fov; }
35 RDGEStart( canvas ); 52 this.getAspect = function() { return this._aspect; }
53 this.getViewDistance = function() { return this._viewDist; }
54
55 this.get2DContext = function() { return this._context; }
36 56
57 this.getViewportWidth = function() { return this._canvas.width; }
58 this.getViewportHeight = function() { return this._canvas.height; }
59
60 ///////////////////////////////////////////////////////////////////////
61 // accessors
62 ///////////////////////////////////////////////////////////////////////
37 this.loadScene = function() 63 this.loadScene = function()
38 { 64 {
39 // parse the data 65 // parse the data
@@ -41,6 +67,8 @@ function GLRuntime( canvas, importStr )
41 var index = importStr.indexOf( "scenedata: " ); 67 var index = importStr.indexOf( "scenedata: " );
42 if (index >= 0) 68 if (index >= 0)
43 { 69 {
70 this._useWebGL = true;
71
44 var rdgeStr = importStr.substr( index+11 ); 72 var rdgeStr = importStr.substr( index+11 );
45 var endIndex = rdgeStr.indexOf( "endscene\n" ); 73 var endIndex = rdgeStr.indexOf( "endscene\n" );
46 if (endIndex < 0) throw new Error( "ill-formed WebGL data" ); 74 if (endIndex < 0) throw new Error( "ill-formed WebGL data" );
@@ -48,6 +76,15 @@ function GLRuntime( canvas, importStr )
48 rdgeStr = rdgeStr.substr( 0, endIndex ); 76 rdgeStr = rdgeStr.substr( 0, endIndex );
49 77
50 this.myScene.importJSON( rdgeStr ); 78 this.myScene.importJSON( rdgeStr );
79 this.importObjects( importStr );
80 this.linkMaterials( this._geomRoot );
81 this.initMaterials();
82 }
83 else
84 {
85 this._context = this._canvas.getContext( "2d" );
86 this.importObjects( importStr );
87 this.render();
51 } 88 }
52 } 89 }
53 90
@@ -72,86 +109,238 @@ function GLRuntime( canvas, importStr )
72 109
73 // create an empty scene graph 110 // create an empty scene graph
74 this.myScene = new SceneGraph(); 111 this.myScene = new SceneGraph();
75 this.loadScene();
76
77 /*
78 // create some lights
79 // light 1
80 this.light = createLightNode("myLight");
81 this.light.setPosition([0,0,1.2]);
82 this.light.setDiffuseColor([0.75,0.9,1.0,1.0]);
83
84 // light 2
85 this.light2 = createLightNode("myLight2");
86 this.light2.setPosition([-0.5,0,1.2]);
87 this.light2.setDiffuseColor([1.0,0.9,0.75,1.0]);
88
89 // create a light transform
90 var lightTr = createTransformNode("lightTr");
91
92 // create and attach a material - materials hold the light data
93 lightTr.attachMaterial(createMaterialNode("lights"));
94
95 // enable light channels 1, 2 - channel 0 is used by the default shader
96 lightTr.materialNode.enableLightChannel(1, this.light);
97 lightTr.materialNode.enableLightChannel(2, this.light2);
98
99 // all added objects are parented to the light node
100 this._rootNode = lightTr;
101
102 // add the light node to the scene
103 this.myScene.addNode(lightTr);
104 */
105 112
106 // load the scene graph data 113 // load the scene graph data
114 this.loadScene();
107 115
108 // Add the scene to the engine - necessary if you want the engine to draw for you 116 // Add the scene to the engine - necessary if you want the engine to draw for you
109 var name = "myScene" + this._canvas.getAttribute( "data-RDGE-id" );