aboutsummaryrefslogtreecommitdiff
path: root/assets
diff options
context:
space:
mode:
authorNivesh Rajbhandari2012-04-16 16:06:24 -0700
committerNivesh Rajbhandari2012-04-16 16:06:24 -0700
commitc253192a08b499ea7be46fa5438d273e51f7ec5a (patch)
tree18a1f0e3679c0eb993a9dedb537035d3861f49ac /assets
parente19376c54eedd1f1c457ba405b2f110be376a559 (diff)
parent4b900ea5cd6bb77eb30cec8c03b9ec9fa662c1e9 (diff)
downloadninja-c253192a08b499ea7be46fa5438d273e51f7ec5a.tar.gz
Merge branch 'refs/heads/ninja-internal' into WebGLFixes
Diffstat (limited to 'assets')
-rw-r--r--assets/canvas-runtime.js1324
-rw-r--r--assets/descriptor.json4
-rw-r--r--assets/images/paris.pngbin0 -> 4108 bytes
-rw-r--r--assets/images/powderblue.pngbin0 -> 176 bytes
-rw-r--r--assets/images/raiders.pngbin0 -> 5674 bytes
-rwxr-xr-xassets/rdge-compiled.js777
-rw-r--r--assets/shaders/Paris.frag.glsl68
7 files changed, 1218 insertions, 955 deletions
diff --git a/assets/canvas-runtime.js b/assets/canvas-runtime.js
index 655e52fa..ee9f24a4 100644
--- a/assets/canvas-runtime.js
+++ b/assets/canvas-runtime.js
@@ -4,9 +4,12 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot
4(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. 4(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved.
5</copyright> */ 5</copyright> */
6 6
7// namespace for the Ninja Canvas Runtime
8var NinjaCvsRt = NinjaCvsRt || {};
9
7/////////////////////////////////////////////////////////////////////// 10///////////////////////////////////////////////////////////////////////
8//Loading webGL/canvas data 11//Loading webGL/canvas data
9function initWebGl (rootElement, directory) { 12NinjaCvsRt.initWebGl = function (rootElement, directory) {
10 var cvsDataMngr, ninjaWebGlData = JSON.parse((document.querySelectorAll(['script[data-ninja-webgl]'])[0].innerHTML.replace('(', '')).replace(')', '')); 13 var cvsDataMngr, ninjaWebGlData = JSON.parse((document.querySelectorAll(['script[data-ninja-webgl]'])[0].innerHTML.replace('(', '')).replace(')', ''));
11 if (ninjaWebGlData && ninjaWebGlData.data) { 14 if (ninjaWebGlData && ninjaWebGlData.data) {
12 for (var n=0; ninjaWebGlData.data[n]; n++) { 15 for (var n=0; ninjaWebGlData.data[n]; n++) {
@@ -14,61 +17,50 @@ function initWebGl (rootElement, directory) {
14 } 17 }
15 } 18 }
16 //Creating data manager 19 //Creating data manager
17 cvsDataMngr = new CanvasDataManager(); 20 cvsDataMngr = new NinjaCvsRt.CanvasDataManager();
18 //Loading data to canvas(es) 21 //Loading data to canvas(es)
19 cvsDataMngr.loadGLData(rootElement, ninjaWebGlData.data, directory); 22 cvsDataMngr.loadGLData(rootElement, ninjaWebGlData.data, directory);
20} 23};
21 24
22/////////////////////////////////////////////////////////////////////// 25///////////////////////////////////////////////////////////////////////
23// Class ShapeRuntime 26// Class ShapeRuntime
24// Manages runtime shape display 27// Manages runtime shape display
25/////////////////////////////////////////////////////////////////////// 28///////////////////////////////////////////////////////////////////////
26function CanvasDataManager() 29NinjaCvsRt.CanvasDataManager = function ()
27{ 30{
28 this.loadGLData = function(root, valueArray, assetPath ) 31 this.loadGLData = function(root, valueArray, assetPath )
29 { 32 {
30 this._assetPath = assetPath.slice(); 33 if (assetPath)
34 this._assetPath = assetPath.slice();
31 35
32 var value = valueArray; 36 var value = valueArray;
33 var nWorlds = value.length; 37 var nWorlds = value.length;
34 for (var i=0; i<nWorlds; i++) 38 for (var i=0; i<nWorlds; i++)
35 { 39 {
36 var importStr = value[i]; 40 var importStr = value[i];
37 var startIndex = importStr.indexOf( "id: " ); 41
38 if (startIndex >= 0) 42 // there should be some version information in
43 // the form of 'v0.0;' Pull that off. (the trailing ';' should
44 // be in the first 24 characters).
45 var index = importStr.indexOf( ';' );
46 if ((importStr[0] === 'v') && (index < 24))
39 { 47 {
40 var endIndex = importStr.indexOf( "\n", startIndex ); 48 // JSON format. pull off the version info
41 if (endIndex > 0) 49 importStr = importStr.substr( index+1 );
50
51 var jObj = JSON.parse( importStr );
52 var id = jObj.id;
53 if (id)
42 { 54 {
43 var id = importStr.substring( startIndex+4, endIndex );
44 var canvas = this.findCanvasWithID( id, root ); 55 var canvas = this.findCanvasWithID( id, root );
45 if (canvas) 56 if (canvas)
46 { 57 {
47 var rt = new GLRuntime( canvas, importStr, assetPath ); 58 new NinjaCvsRt.GLRuntime( canvas, jObj, assetPath );
48 } 59 }
49 } 60 }
50 } 61 }
51 } 62 }
52 } 63 };
53
54 this.collectGLData = function( elt, dataArray )
55 {
56 if (elt.elementModel && elt.elementModel.shapeModel && elt.elementModel.shapeModel.GLWorld)
57 {
58 var data = elt.elementModel.shapeModel.GLWorld.export( true );
59 dataArray.push( data );
60 }
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 this.collectGLData( child, dataArray );
69 }
70 }
71 }
72 64
73 this.findCanvasWithID = function( id, elt ) 65 this.findCanvasWithID = function( id, elt )
74 { 66 {
@@ -85,21 +77,22 @@ function CanvasDataManager()
85 if (foundElt) return foundElt; 77 if (foundElt) return foundElt;
86 } 78 }
87 } 79 }
88 } 80 };
89} 81};
90 82
91/////////////////////////////////////////////////////////////////////// 83///////////////////////////////////////////////////////////////////////
92// Class GLRuntime 84// Class GLRuntime
93// Manages runtime fora WebGL canvas 85// Manages runtime fora WebGL canvas
94/////////////////////////////////////////////////////////////////////// 86///////////////////////////////////////////////////////////////////////
95function GLRuntime( canvas, importStr, assetPath ) 87NinjaCvsRt.GLRuntime = function ( canvas, jObj, assetPath )
96{ 88{
97 /////////////////////////////////////////////////////////////////////// 89 ///////////////////////////////////////////////////////////////////////
98 // Instance variables 90 // Instance variables
99 /////////////////////////////////////////////////////////////////////// 91 ///////////////////////////////////////////////////////////////////////
100 this._canvas = canvas; 92 this._canvas = canvas;
101 this._context = null; 93 this._context = null;
102 this._importStr = importStr; 94 //this._importStr = importStr;
95 this._jObj = jObj;
103 96
104 this.renderer = null; 97 this.renderer = null;
105 this.myScene = null; 98 this.myScene = null;
@@ -111,6 +104,7 @@ function GLRuntime( canvas, importStr, assetPath )
111 this._initialized = false; 104 this._initialized = false;
112 105
113 this._useWebGL = false; 106 this._useWebGL = false;
107 this._assetPath = undefined;
114 108
115 // view parameters 109 // view parameters
116 this._fov = 45.0; 110 this._fov = 45.0;
@@ -118,75 +112,82 @@ function GLRuntime( canvas, importStr, assetPath )
118 this._zFar = 100.0; 112 this._zFar = 100.0;
119 this._viewDist = 5.0; 113 this._viewDist = 5.0;
120 114
115 this.elapsed = 0;
116
121 this._aspect = canvas.width/canvas.height; 117 this._aspect = canvas.width/canvas.height;
122 118
123 this._geomRoot; 119 this._geomRoot = null;
124 120
125 // all "live" materials 121 // all "live" materials
126 this._materials = []; 122 this._materials = [];
127 123
128 // provide the mapping for the asset directory 124 // provide the mapping for the asset directory
129 this._assetPath = assetPath.slice(); 125 if (assetPath) {
130 if (this._assetPath[this._assetPath.length-1] != '/') 126 this._assetPath = assetPath.slice();
131 this._assetPath += '/'; 127 if (this._assetPath[this._assetPath.length - 1] != '/')
128 this._assetPath += '/';
129 }
130
131 if(this._assetPath !== undefined) {
132 RDGE.globals.engine.setAssetPath(this._assetPath);
133 }
132 134
133 /////////////////////////////////////////////////////////////////////// 135 ///////////////////////////////////////////////////////////////////////
134 // accessors 136 // accessors
135 /////////////////////////////////////////////////////////////////////// 137 ///////////////////////////////////////////////////////////////////////
136 this.getZNear = function() { return this._zNear; } 138 this.getZNear = function() { return this._zNear; };
137 this.getZFar = function() { return this._zFar; } 139 this.getZFar = function() { return this._zFar; };
138 this.getFOV = function() { return this._fov; } 140 this.getFOV = function() { return this._fov; };
139 this.getAspect = function() { return this._aspect; } 141 this.getAspect = function() { return this._aspect; };
140 this.getViewDistance = function() { return this._viewDist; } 142 this.getViewDistance = function() { return this._viewDist; };
141 143
142 this.get2DContext = function() { return this._context; } 144 this.get2DContext = function() { return this._context; };
143 145
144 this.getViewportWidth = function() { return this._canvas.width; } 146 this.getViewportWidth = function() { return this._canvas.width; };
145 this.getViewportHeight = function() { return this._canvas.height; } 147 this.getViewportHeight = function() { return this._canvas.height; };
146 148
147 /////////////////////////////////////////////////////////////////////// 149 ///////////////////////////////////////////////////////////////////////
148 // accessors 150 // accessors
149 /////////////////////////////////////////////////////////////////////// 151 ///////////////////////////////////////////////////////////////////////
150 this.loadScene = function() 152 this.loadScene = function()
151 { 153 {
154 var jObj = this._jObj;
155 if (!jObj.children || (jObj.children.length != 1))
156 throw new Error( "ill-formed JSON for runtime load: " + jObj );