aboutsummaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
authorJose Antonio Marquez2012-03-09 11:01:59 -0800
committerJose Antonio Marquez2012-03-09 11:01:59 -0800
commit82b6b752123022670c422b8a083c93d865c9533a (patch)
tree9d56266ea31c1f9373a70dc1130e17b16098f6db /js
parentd549383abf18a0dc54a990983fb4296602b66120 (diff)
downloadninja-82b6b752123022670c422b8a083c93d865c9533a.tar.gz
Adding webGL I/O runtime functionality
There is a problem that needs to be resolved in the CanvasRuntime.
Diffstat (limited to 'js')
-rwxr-xr-xjs/document/html-document.js89
-rw-r--r--js/lib/rdge/runtime/CanvasRuntime.js1338
-rw-r--r--js/mediators/io-mediator.js12
3 files changed, 44 insertions, 1395 deletions
diff --git a/js/document/html-document.js b/js/document/html-document.js
index b9944d66..aa56fd0e 100755
--- a/js/document/html-document.js
+++ b/js/document/html-document.js
@@ -188,66 +188,49 @@ exports.HTMLDocument = Montage.create(TextDocument, {
188// }, 188// },
189 189
190 glData: { 190 glData: {
191 get: function() 191 get: function() {
192 { 192 //
193 var elt = this.iframe.contentWindow.document.getElementById("UserContent"); 193 var elt = this.iframe.contentWindow.document.getElementById("UserContent");
194 this._glData = null; 194 //
195 if (elt) 195 if (elt) {
196 {
197 this._glData = []; 196 this._glData = [];
198 var path = "assets/"; 197 //if (path) {
199 this.collectGLData( elt, this._glData, path ); 198 //this.collectGLData(elt, this._glData, path);
199 //} else {
200 this.collectGLData(elt, this._glData, "assets/");
201 //}
202 } else {
203 this._glData = null
200 } 204 }
201 205 //
202 return this._glData; 206 return this._glData;
203 }, 207 },
204 208 set: function(value) {
205 set: function(value)
206 {
207 var elt = this.documentRoot; 209 var elt = this.documentRoot;
208 if (elt) 210 if (elt) {
209 { 211 var nWorlds= value.length;
210// var loadForRuntime = false; 212 for (var i=0; i<nWorlds; i++) {
211// if (loadForRuntime) 213 var importStr = value[i];
212// { 214 var startIndex = importStr.indexOf( "id: " );
213// var cdm = new CanvasDataManager(); 215 if (startIndex >= 0) {
214// cdm.loadGLData(elt, value ); 216 var endIndex = importStr.indexOf( "\n", startIndex );
215// } 217 if (endIndex > 0) {
216// else 218 var id = importStr.substring( startIndex+4, endIndex );
217 { 219 if (id) {
218 var nWorlds= value.length; 220 var canvas = this.findCanvasWithID( id, elt );
219 for (var i=0; i<nWorlds; i++) 221 if (canvas) {
220 { 222 if (!canvas.elementModel) {
221 var importStr = value[i]; 223 NJUtils.makeElementModel(canvas, "Canvas", "shape", true);
222 var startIndex = importStr.indexOf( "id: " ); 224 }
223 if (startIndex >= 0) 225 if (canvas.elementModel) {
224 { 226 if (canvas.elementModel.shapeModel.GLWorld) {
225 var endIndex = importStr.indexOf( "\n", startIndex ); 227 canvas.elementModel.shapeModel.GLWorld.clearTree();
226 if (endIndex > 0)
227 {
228 var id = importStr.substring( startIndex+4, endIndex );
229 if (id)
230 {
231 var canvas = this.findCanvasWithID( id, elt );
232 if (canvas)
233 {
234 if (!canvas.elementModel)
235 {
236 NJUtils.makeElementModel(canvas, "Canvas", "shape", true);
237 }
238
239 if (canvas.elementModel)
240 {
241 if (canvas.elementModel.shapeModel.GLWorld)
242 canvas.elementModel.shapeModel.GLWorld.clearTree();
243
244 var index = importStr.indexOf( "webGL: " );
245 var useWebGL = (index >= 0)
246 var world = new GLWorld( canvas, useWebGL );
247 world.import( importStr );
248
249 this.buildShapeModel( canvas.elementModel, world );
250 } 228 }
229 var index = importStr.indexOf( "webGL: " );
230 var useWebGL = (index >= 0)
231 var world = new GLWorld( canvas, useWebGL );
232 world.import( importStr );
233 this.buildShapeModel( canvas.elementModel, world );
251 } 234 }
252 } 235 }
253 } 236 }
diff --git a/js/lib/rdge/runtime/CanvasRuntime.js b/js/lib/rdge/runtime/CanvasRuntime.js
deleted file mode 100644
index d16613ca..00000000
--- a/js/lib/rdge/runtime/CanvasRuntime.js
+++ /dev/null
@@ -1,1338 +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// Class ShapeRuntime
10// Manages runtime shape display
11///////////////////////////////////////////////////////////////////////
12function CanvasDataManager()
13{
14 this.loadGLData = function(root, valueArray )
15 {
16 var value = valueArray;
17 var nWorlds = value.length;
18 for (var i=0; i<nWorlds; i++)
19 {
20 var importStr = value[i];
21 var startIndex = importStr.indexOf( "id: " );
22 if (startIndex >= 0)
23 {
24 var endIndex = importStr.indexOf( "\n", startIndex );
25 if (endIndex > 0)
26 {
27 var id = importStr.substring( startIndex+4, endIndex );
28 var canvas = this.findCanvasWithID( id, root );
29 if (canvas)
30 {
31 var rt = new GLRuntime( canvas, importStr );
32 }
33 }
34 }
35 }
36 }
37
38 this.collectGLData = function( elt, dataArray )
39 {
40 if (elt.elementModel && elt.elementModel.shapeModel && elt.elementModel.shapeModel.GLWorld)
41 {
42 var data = elt.elementModel.shapeModel.GLWorld.export( true );
43 dataArray.push( data );
44 }
45
46 if (elt.children)
47 {
48 var nKids = elt.children.length;
49 for (var i=0; i<nKids; i++)
50 {
51 var child = elt.children[i];
52 this.collectGLData( child, dataArray );
53 }
54 }
55 }
56
57 this.findCanvasWithID = function( id, elt )
58 {
59 var cid = elt.getAttribute( "data-RDGE-id" );
60 if (cid == id) return elt;
61
62 if (elt.children)
63 {
64 var nKids = elt.children.length;
65 for (var i=0; i<nKids; i++)
66 {
67 var child = elt.children[i];
68 var foundElt = this.findCanvasWithID( id, child );
69 if (foundElt) return foundElt;
70 }
71 }
72 }
73}
74
75///////////////////////////////////////////////////////////////////////
76// Class GLRuntime
77// Manages runtime fora WebGL canvas
78///////////////////////////////////////////////////////////////////////
79function GLRuntime( canvas, importStr )
80{
81 ///////////////////////////////////////////////////////////////////////
82 // Instance variables
83 ///////////////////////////////////////////////////////////////////////
84 this._canvas = canvas;
85 this._context = null;
86 this._importStr = importStr;
87
88 this.renderer = null;
89 this.myScene = null;
90 this.light = null;
91 this.light2 = null;
92 this._rootNode = null;
93
94 this._firstRender = true;
95 this._initialized = false;
96
97 this._useWebGL = false;
98
99 // view parameters
100 this._fov = 45.0;
101 this._zNear = 0.1;
102 this._zFar = 100.0;
103 this._viewDist = 5.0;
104
105 this._aspect = canvas.width/canvas.height;
106
107 this._geomRoot;
108
109 // all "live" materials
110 this._materials = [];
111
112 ///////////////////////////////////////////////////////////////////////
113