aboutsummaryrefslogtreecommitdiff
path: root/assets/canvas-runtime.js
diff options
context:
space:
mode:
Diffstat (limited to 'assets/canvas-runtime.js')
-rw-r--r--assets/canvas-runtime.js3381
1 files changed, 1766 insertions, 1615 deletions
diff --git a/assets/canvas-runtime.js b/assets/canvas-runtime.js
index af860b95..ef1d01a9 100644
--- a/assets/canvas-runtime.js
+++ b/assets/canvas-runtime.js
@@ -56,60 +56,60 @@ NinjaCvsRt.initWebGl = function (rootElement, directory, data) {
56/////////////////////////////////////////////////////////////////////// 56///////////////////////////////////////////////////////////////////////
57NinjaCvsRt.CanvasDataManager = Object.create(Object.prototype, { 57NinjaCvsRt.CanvasDataManager = Object.create(Object.prototype, {
58 58
59 loadGLData: { 59 loadGLData: {
60 value: function(root, valueArray, assetPath) { 60 value: function(root, valueArray, assetPath) {
61 if (assetPath) 61 if (assetPath)
62 this._assetPath = assetPath.slice(); 62 this._assetPath = assetPath.slice();
63 63
64 var value = valueArray; 64 var value = valueArray;
65 var nWorlds = value.length; 65 var nWorlds = value.length;
66 for (var i=0; i<nWorlds; i++) 66 for (var i=0; i<nWorlds; i++)
67 { 67 {
68 var importStr = value[i]; 68 var importStr = value[i];
69 69
70 // there should be some version information in 70 // there should be some version information in
71 // the form of 'v0.0;' Pull that off. (the trailing ';' should 71 // the form of 'v0.0;' Pull that off. (the trailing ';' should
72 // be in the first 24 characters). 72 // be in the first 24 characters).
73 var index = importStr.indexOf( ';' ); 73 var index = importStr.indexOf( ';' );
74 if ((importStr[0] === 'v') && (index < 24)) 74 if ((importStr[0] === 'v') && (index < 24))
75 { 75 {
76 // JSON format. pull off the version info 76 // JSON format. pull off the version info
77 importStr = importStr.substr( index+1 ); 77 importStr = importStr.substr( index+1 );
78 78
79 var jObj = JSON.parse( importStr ); 79 var jObj = JSON.parse( importStr );
80 var id = jObj.id; 80 var id = jObj.id;
81 if (id) 81 if (id)
82 { 82 {
83 var canvas = this.findCanvasWithID( id, root ); 83 var canvas = this.findCanvasWithID( id, root );
84 if (canvas) 84 if (canvas)
85 { 85 {
86// new NinjaCvsRt.GLRuntime( canvas, jObj, assetPath ); 86// new NinjaCvsRt.GLRuntime( canvas, jObj, assetPath );
87 var glRt = Object.create(NinjaCvsRt.GLRuntime, {}); 87 var glRt = Object.create(NinjaCvsRt.GLRuntime, {});
88 glRt.renderWorld(canvas, jObj, this._assetPath); 88 glRt.renderWorld(canvas, jObj, this._assetPath);
89 } 89 }
90 } 90 }
91 } 91 }
92 } 92 }
93 } 93 }
94 }, 94 },
95 95
96 findCanvasWithID: { 96 findCanvasWithID: {
97 value: function(id, elt) { 97 value: function(id, elt) {
98 var cid = elt.getAttribute( "data-RDGE-id" ); 98 var cid = elt.getAttribute( "data-RDGE-id" );
99 if (cid == id) return elt; 99 if (cid == id) return elt;
100 100
101 if (elt.children) 101 if (elt.children)
102 { 102 {
103 var nKids = elt.children.length; 103 var nKids = elt.children.length;
104 for (var i=0; i<nKids; i++) 104 for (var i=0; i<nKids; i++)
105 { 105 {
106 var child = elt.children[i]; 106 var child = elt.children[i];
107 var foundElt = this.findCanvasWithID( id, child ); 107 var foundElt = this.findCanvasWithID( id, child );
108 if (foundElt) return foundElt; 108 if (foundElt) return foundElt;
109 } 109 }
110 } 110 }
111 } 111 }
112 } 112 }
113}); 113});
114 114
115/////////////////////////////////////////////////////////////////////// 115///////////////////////////////////////////////////////////////////////
@@ -117,394 +117,394 @@ NinjaCvsRt.CanvasDataManager = Object.create(Object.prototype, {
117// Manages runtime fora WebGL canvas 117// Manages runtime fora WebGL canvas
118/////////////////////////////////////////////////////////////////////// 118///////////////////////////////////////////////////////////////////////
119NinjaCvsRt.GLRuntime = Object.create(Object.prototype, { 119NinjaCvsRt.GLRuntime = Object.create(Object.prototype, {
120 /////////////////////////////////////////////////////////////////////// 120 ///////////////////////////////////////////////////////////////////////
121 // Instance variables 121 // Instance variables
122 /////////////////////////////////////////////////////////////////////// 122 ///////////////////////////////////////////////////////////////////////
123 _canvas: { value: null, writable: true }, 123 _canvas: { value: null, writable: true },
124 _context : { value: null, writable: true }, 124 _context : { value: null, writable: true },
125 //this._importStr = importStr; 125 //this._importStr = importStr;
126 _jObj: { value: null, writable: true }, 126 _jObj: { value: null, writable: true },
127 127
128 _renderer: { value: null, writable: true }, 128 _renderer: { value: null, writable: true },
129 myScene: { value: null, writable: true }, 129 myScene: { value: null, writable: true },
130 light: { value: null, writable: true }, 130 light: { value: null, writable: true },
131 light2: { value: null, writable: true }, 131 light2: { value: null, writable: true },
132 _rootNode: { value: null, writable: true }, 132 _rootNode: { value: null, writable: true },
133 133
134 _firstRender: { value: true, writable: true }, 134 _firstRender: { value: true, writable: true },
135 _renderCount: { value: -1, writable: true }, 135 _renderCount: { value: -1, writable: true },
136 _initialized: { value: false, writable: true }, 136 _initialized: { value: false, writable: true },
137 137
138 _useWebGL: { value: false, writable: true }, 138 _useWebGL: { value: false, writable: true },
139 _assetPath: { value: undefined, writable: true }, 139 _assetPath: { value: undefined, writable: true },
140 140
141 // view parameters 141 // view parameters
142 _fov: { value: 45.0, writable: true }, 142 _fov: { value: 45.0, writable: true },
143 _zNear: { value: 0.1, writable: true }, 143 _zNear: { value: 0.1, writable: true },
144 _zFar: { value: 100.0, writable: true }, 144 _zFar: { value: 100.0, writable: true },
145 _viewDist: { value: 5.0, writable: true }, 145 _viewDist: { value: 5.0, writable: true },
146 146
147 elapsed: { value: 0, writable: true }, 147 elapsed: { value: 0, writable: true },
148 148
149 _aspect: { value: 1, writable: true }, 149 _aspect: { value: 1, writable: true },
150 150
151 //this._geomRoot = null; 151 //this._geomRoot = null;
152 _rootChildren: { value: [], writable: true }, 152 _rootChildren: { value: [], writable: true },
153 153
154 // all "live" materials 154 // all "live" materials
155 _materials: { value: [], writable: true }, 155 _materials: { value: [], writable: true },
156 156
157 renderWorld: { 157 renderWorld: {
158 value: function(canvas, jObj, assetPath) { 158 value: function(canvas, jObj, assetPath) {
159 this._materials = []; 159 this._materials = [];
160 this._rootChildren = []; 160 this._rootChildren = [];
161 this._canvas = canvas; 161 this._canvas = canvas;
162 this._aspect = this._canvas.width/this._canvas.height; 162 this._aspect = this._canvas.width/this._canvas.height;
163 163
164 this._jObj= jObj; 164 this._jObj= jObj;
165 165
166 // provide the mapping for the asset directory 166 // provide the mapping for the asset directory
167 if (assetPath) { 167 if (assetPath) {
168 this._assetPath = assetPath.slice(); 168 this._assetPath = assetPath.slice();
169 if (this._assetPath[this._assetPath.length - 1] != '/') 169 if (this._assetPath[this._assetPath.length - 1] != '/')
170 this._assetPath += '/'; 170 this._assetPath += '/';
171 } 171 }
172 172
173 if(this._assetPath !== undefined) { 173 if(this._assetPath !== undefined) {
174 RDGE.globals.engine.setAssetPath(this._assetPath); 174 RDGE.globals.engine.setAssetPath(this._assetPath);
175 } 175 }
176 176
177 // start RDGE or load Canvas 2D objects 177 // start RDGE or load Canvas 2D objects
178 if (jObj.scenedata) this._useWebGL = true; 178 if (jObj.scenedata) this._useWebGL = true;
179 if (this._useWebGL) 179 if (this._useWebGL)
180 { 180 {
181 var id = this._canvas.getAttribute( "data-RDGE-id" ); 181 var id = this._canvas.getAttribute( "data-RDGE-id" );
182 this._canvas.rdgeid = id; 182 this._canvas.rdgeid = id;
183 RDGE.globals.engine.registerCanvas(this._canvas, this); 183 RDGE.globals.engine.registerCanvas(this._canvas, this);
184 RDGE.RDGEStart( this._canvas ); 184 RDGE.RDGEStart( this._canvas );
185 } 185 }
186 else 186 else
187 { 187 {
188 this.loadScene(); 188 this.loadScene();
189 } 189 }
190 } 190 }
191 }, 191 },
192 192
193 /////////////////////////////////////////////////////////////////////// 193 ///////////////////////////////////////////////////////////////////////
194 // accessors 194 // accessors
195 /////////////////////////////////////////////////////////////////////// 195 ///////////////////////////////////////////////////////////////////////
196 getZNear: { value: function() { return this._zNear; }}, 196 getZNear: { value: function() { return this._zNear; }},
197 getZFar: { value: function() { return this._zFar; }}, 197 getZFar: { value: function() { return this._zFar; }},
198 getFOV: { value: function() { return this._fov; }}, 198 getFOV: { value: function() { return this._fov; }},
199 getAspect: { value: function() { return this._aspect; }}, 199 getAspect: { value: function() { return this._aspect; }},
200 getViewDistance: { value: function() { return this._viewDist; }