aboutsummaryrefslogtreecommitdiff
path: root/js/helper-classes/RDGE
diff options
context:
space:
mode:
Diffstat (limited to 'js/helper-classes/RDGE')
-rw-r--r--js/helper-classes/RDGE/runtime/CanvasDataManager.js75
-rw-r--r--js/helper-classes/RDGE/runtime/GLRuntime.js348
-rw-r--r--js/helper-classes/RDGE/runtime/RuntimeGeomObj.js611
-rw-r--r--js/helper-classes/RDGE/runtime/RuntimeMaterial.js282
4 files changed, 0 insertions, 1316 deletions
diff --git a/js/helper-classes/RDGE/runtime/CanvasDataManager.js b/js/helper-classes/RDGE/runtime/CanvasDataManager.js
deleted file mode 100644
index efbfe4db..00000000
--- a/js/helper-classes/RDGE/runtime/CanvasDataManager.js
+++ /dev/null
@@ -1,75 +0,0 @@
1/* <copyright>
2This file contains proprietary software owned by Motorola Mobility, Inc.<br/>
3No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/>
4(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved.
5</copyright> */
6
7
8
9///////////////////////////////////////////////////////////////////////
10// Class ShapeRuntime
11// Manages runtime shape display
12///////////////////////////////////////////////////////////////////////
13function CanvasDataManager()
14{
15 this.loadGLData = function(root, valueArray, NinjaUtils)
16 {
17 var value = valueArray;
18 var nWorlds = value.length;
19 for (var i=0; i<nWorlds; i++)
20 {
21 var importStr = value[i];
22 var startIndex = importStr.indexOf( "id: " );
23 if (startIndex >= 0)
24 {
25 var endIndex = importStr.indexOf( "\n", startIndex );
26 if (endIndex > 0)
27 {
28 var id = importStr.substring( startIndex+4, endIndex );
29 var canvas = this.findCanvasWithID( id, root );
30 if (canvas)
31 {
32 var rt = new GLRuntime( canvas, importStr );
33 }
34 }
35 }
36 }
37 }
38
39 this.collectGLData = function( elt, dataArray )
40 {
41 if (elt.elementModel && elt.elementModel.shapeModel && elt.elementModel.shapeModel.GLWorld)
42 {
43 var data = elt.elementModel.shapeModel.GLWorld.export( true );
44 dataArray.push( data );
45 }
46
47 if (elt.children)
48 {
49 var nKids = elt.children.length;
50 for (var i=0; i<nKids; i++)
51 {
52 var child = elt.children[i];
53 this.collectGLData( child, dataArray );
54 }
55 }
56 }
57
58 this.findCanvasWithID = function( id, elt )
59 {
60 var cid = elt.getAttribute( "data-RDGE-id" );
61 if (cid == id) return elt;
62
63 if (elt.children)
64 {
65 var nKids = elt.children.length;
66 for (var i=0; i<nKids; i++)
67 {
68 var child = elt.children[i];
69 var foundElt = this.findCanvasWithID( id, child );
70 if (foundElt) return foundElt;
71 }
72 }
73 }
74}
75
diff --git a/js/helper-classes/RDGE/runtime/GLRuntime.js b/js/helper-classes/RDGE/runtime/GLRuntime.js
deleted file mode 100644
index 58cb4e33..00000000
--- a/js/helper-classes/RDGE/runtime/GLRuntime.js
+++ /dev/null
@@ -1,348 +0,0 @@
1/* <copyright>
2This file contains proprietary software owned by Motorola Mobility, Inc.<br/>
3No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/>
4(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved.
5</copyright> */
6
7
8
9///////////////////////////////////////////////////////////////////////
10// Class GLRuntime
11// Manages runtime fora WebGL canvas
12///////////////////////////////////////////////////////////////////////
13function GLRuntime( canvas, importStr )
14{
15 ///////////////////////////////////////////////////////////////////////
16 // Instance variables
17 ///////////////////////////////////////////////////////////////////////
18 this._canvas = canvas;
19 this._context = null;
20 this._importStr = importStr;
21
22 this.renderer = null;
23 this.myScene = null;
24 this.light = null;
25 this.light2 = null;
26 this._rootNode = null;
27
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 = [];
45
46 ///////////////////////////////////////////////////////////////////////
47 // accessors
48 ///////////////////////////////////////////////////////////////////////
49 this.getZNear = function() { return this._zNear; }
50 this.getZFar = function() { return this._zFar; }
51 this.getFOV = function() { return this._fov; }
52 this.getAspect = function() { return this._aspect; }
53 this.getViewDistance = function() { return this._viewDist; }
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 ///////////////////////////////////////////////////////////////////////
63 this.loadScene = function()
64 {
65 // parse the data
66 // the GL runtime must start with a "sceneData: "
67 var index = importStr.indexOf( "scenedata: " );
68 if (index >= 0)
69 {
70 this._useWebGL = true;
71
72 var rdgeStr = importStr.substr( index+11 );
73 var endIndex = rdgeStr.indexOf( "endscene\n" );
74 if (endIndex < 0) throw new Error( "ill-formed WebGL data" );
75 var len = endIndex - index + 11;
76 rdgeStr = rdgeStr.substr( 0, endIndex );
77
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();
88 }
89 }
90
91 this.init = function()
92 {
93 var ctx1 = g_Engine.ctxMan.handleToObject(this._canvas.rdgeCtxHandle),
94 ctx2 = g_Engine.getContext();
95 if (ctx1 != ctx2) console.log( "***** different contexts *****" );
96 this.renderer = ctx1.renderer;
97
98 // create a camera, set its perspective, and then point it at the origin
99 var cam = new camera();
100 this._camera = cam;
101 cam.setPerspective(this.getFOV(), this.getAspect(), this.getZNear(), this.getZFar());
102 cam.setLookAt([0, 0, this.getViewDistance()], [0, 0, 0], vec3.up());
103
104 // make this camera the active camera
105 this.renderer.cameraManager().setActiveCamera(cam);
106
107 // change clear color
108 this.renderer.setClearColor([1.0, 1.0, 1.0, 0.0]);
109
110 // create an empty scene graph
111 this.myScene = new SceneGraph();
112
113 // load the scene graph data
114 this.loadScene();
115
116 // Add the scene to the engine - necessary if you want the engine to draw for you
117 var name = "myScene" + this._canvas.getAttribute( "data-RDGE-id" );
118 g_Engine.AddScene(name, this.myScene);
119
120 this._initialized = true;
121 }
122
123 // main code for handling user interaction and updating the scene
124 this.update = function(dt)
125 {
126 if (this._initialized)
127 {
128 if (!dt) dt = 0.2;
129
130 dt = 0.01; // use our own internal throttle
131 this.elapsed += dt;
132
133 // changed the global position uniform of light 0, another way to change behavior of a light
134 rdgeGlobalParameters.u_light0Pos.set( [5*Math.cos(this.elapsed), 5*Math.sin(this.elapsed), 20]);
135
136 // orbit the light nodes around the boxes
137 //this.light.setPosition([1.2*Math.cos(this.elapsed*2.0), 1.2*Math.sin(this.elapsed*2.0), 1.2*Math.cos(this.elapsed*2.0)]);
138 //this.light2.setPosition([-1.2*Math.cos(this.elapsed*2.0), 1.2*Math.sin(this.elapsed*2.0), -1.2*Math.cos(this.elapsed)]);