aboutsummaryrefslogtreecommitdiff
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
parentd549383abf18a0dc54a990983fb4296602b66120 (diff)
downloadninja-82b6b752123022670c422b8a083c93d865c9533a.tar.gz
Adding webGL I/O runtime functionality
There is a problem that needs to be resolved in the CanvasRuntime.
-rw-r--r--assets/CanvasDataManager.js83
-rw-r--r--assets/CanvasRuntime.js (renamed from js/lib/rdge/runtime/CanvasRuntime.js)0
-rw-r--r--assets/descriptor.json2
-rwxr-xr-xjs/document/html-document.js89
-rw-r--r--js/mediators/io-mediator.js12
5 files changed, 45 insertions, 141 deletions
diff --git a/assets/CanvasDataManager.js b/assets/CanvasDataManager.js
deleted file mode 100644
index 8afc9de0..00000000
--- a/assets/CanvasDataManager.js
+++ /dev/null
@@ -1,83 +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
8var GeomObj = require("js/lib/geom/geom-obj").GeomObj;
9var ShapePrimitive = require("js/lib/geom/shape-primitive").ShapePrimitive;
10var MaterialsModel = require("js/models/materials-model").MaterialsModel;
11var GLRuntime = require("js/lib/rdge/runtime/GLRuntime").GLRuntime;
12
13///////////////////////////////////////////////////////////////////////
14// Class ShapeRuntime
15// Manages runtime shape display
16///////////////////////////////////////////////////////////////////////
17var CanvasDataManager = function CanvasDataManager()
18{
19 this.loadGLData = function(root, valueArray )
20 {
21 var value = valueArray;
22 var nWorlds = value.length;
23 for (var i=0; i<nWorlds; i++)
24 {
25 var importStr = value[i];
26 var startIndex = importStr.indexOf( "id: " );
27 if (startIndex >= 0)
28 {
29 var endIndex = importStr.indexOf( "\n", startIndex );
30 if (endIndex > 0)
31 {
32 var id = importStr.substring( startIndex+4, endIndex );
33 var canvas = this.findCanvasWithID( id, root );
34 if (canvas)
35 {
36 var rt = new GLRuntime( canvas, importStr );
37 }
38 }
39 }
40 }
41 }
42
43 this.collectGLData = function( elt, dataArray )
44 {
45 if (elt.elementModel && elt.elementModel.shapeModel && elt.elementModel.shapeModel.GLWorld)
46 {
47 var data = elt.elementModel.shapeModel.GLWorld.export( true );
48 dataArray.push( data );
49 }
50
51 if (elt.children)
52 {
53 var nKids = elt.children.length;
54 for (var i=0; i<nKids; i++)
55 {
56 var child = elt.children[i];
57 this.collectGLData( child, dataArray );
58 }
59 }
60 }
61
62 this.findCanvasWithID = function( id, elt )
63 {
64 var cid = elt.getAttribute( "data-RDGE-id" );
65 if (cid == id) return elt;
66
67 if (elt.children)
68 {
69 var nKids = elt.children.length;
70 for (var i=0; i<nKids; i++)
71 {
72 var child = elt.children[i];
73 var foundElt = this.findCanvasWithID( id, child );
74 if (foundElt) return foundElt;
75 }
76 }
77 }
78}
79
80
81if (typeof exports === "object") {
82 exports.CanvasDataManager = CanvasDataManager;
83}
diff --git a/js/lib/rdge/runtime/CanvasRuntime.js b/assets/CanvasRuntime.js
index d16613ca..d16613ca 100644
--- a/js/lib/rdge/runtime/CanvasRuntime.js
+++ b/assets/CanvasRuntime.js
diff --git a/assets/descriptor.json b/assets/descriptor.json
index c3a3d934..fb56d208 100644
--- a/assets/descriptor.json
+++ b/assets/descriptor.json
@@ -4,7 +4,7 @@
4 "root": "/assets/", 4 "root": "/assets/",
5 "directories": [{"name": "images"}, {"name": "shaders"}], 5 "directories": [{"name": "images"}, {"name": "shaders"}],
6 "files": [ 6 "files": [
7 "CanvasDataManager.js", 7 "CanvasRuntime.js",
8 "images/black.png", 8 "images/black.png",
9 "images/blue.png", 9 "images/blue.png",
10 "images/BoxB2_AO.png", 10 "images/BoxB2_AO.png",
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/mediators/io-mediator.js b/js/mediators/io-mediator.js
index c22d95be..277b3a1b 100644
--- a/js/mediators/io-mediator.js
+++ b/js/mediators/io-mediator.js
@@ -389,7 +389,7 @@ exports.IoMediator = Montage.create(Component, {
389 if (!webgllibtag) { 389 if (!webgllibtag) {
390 webgllibtag = template.document.content.document.createElement('script'); 390 webgllibtag = template.document.content.document.createElement('script');
391 webgllibtag.setAttribute('type', 'text/javascript'); 391 webgllibtag.setAttribute('type', 'text/javascript');
392 webgllibtag.setAttribute('src', rdgeDirName+'/CanvasDataManager.js'); 392 webgllibtag.setAttribute('src', rdgeDirName+'/CanvasRuntime.js');
393 webgllibtag.setAttribute('data-ninja-webgl-lib', 'true'); 393 webgllibtag.setAttribute('data-ninja-webgl-lib', 'true');
394 template.document.content.document.head.appendChild(webgllibtag); 394 template.document.content.document.head.appendChild(webgllibtag);
395 } 395 }