aboutsummaryrefslogtreecommitdiff
path: root/js/lib/drawing
diff options
context:
space:
mode:
Diffstat (limited to 'js/lib/drawing')
-rwxr-xr-xjs/lib/drawing/world.js64
1 files changed, 32 insertions, 32 deletions
diff --git a/js/lib/drawing/world.js b/js/lib/drawing/world.js
index 5a054224..436853bd 100755
--- a/js/lib/drawing/world.js
+++ b/js/lib/drawing/world.js
@@ -33,7 +33,7 @@ var World = function GLWorld( canvas, use3D, preserveDrawingBuffer ) {
33 if(preserveDrawingBuffer) { 33 if(preserveDrawingBuffer) {
34 this._glContext = canvas.getContext("experimental-webgl", {preserveDrawingBuffer: true}); 34 this._glContext = canvas.getContext("experimental-webgl", {preserveDrawingBuffer: true});
35 } else { 35 } else {
36 this._glContext = canvas.getContext("experimental-webgl"); 36 this._glContext = canvas.getContext("experimental-webgl");
37 } 37 }
38 } else { 38 } else {
39 this._2DContext = canvas.getContext( "2d" ); 39 this._2DContext = canvas.getContext( "2d" );
@@ -144,45 +144,45 @@ var World = function GLWorld( canvas, use3D, preserveDrawingBuffer ) {
144 144
145 // post-load processing of the scene 145 // post-load processing of the scene
146 this.init = function() { 146 this.init = function() {
147 var ctx1 = g_Engine.ctxMan.handleToObject(this._canvas.rdgeCtxHandle), 147 var ctx1 = RDGE.globals.engine.ctxMan.handleToObject(this._canvas.rdgeCtxHandle),
148 ctx2 = g_Engine.getContext(); 148 ctx2 = RDGE.globals.engine.getContext();
149 if (ctx1 != ctx2) console.log( "***** different contexts *****" ); 149 if (ctx1 != ctx2) console.log( "***** different contexts *****" );
150 this.renderer = ctx1.renderer; 150 this.renderer = ctx1.renderer;
151 this.renderer._world = this; 151 this.renderer._world = this;
152 152
153 // create a camera, set its perspective, and then point it at the origin 153 // create a camera, set its perspective, and then point it at the origin
154 var cam = new camera(); 154 var cam = new RDGE.camera();
155 this._camera = cam; 155 this._camera = cam;
156 cam.setPerspective(this.getFOV(), this.getAspect(), this.getZNear(), this.getZFar()); 156 cam.setPerspective(this.getFOV(), this.getAspect(), this.getZNear(), this.getZFar());
157 cam.setLookAt([0, 0, this.getViewDistance()], [0, 0, 0], vec3.up()); 157 cam.setLookAt([0, 0, this.getViewDistance()], [0, 0, 0], RDGE.vec3.up());
158 158
159 // make this camera the active camera 159 // make this camera the active camera
160 this.renderer.cameraManager().setActiveCamera(cam); 160 this.renderer.cameraManager().setActiveCamera(cam);
161 161
162 // change clear color 162 // change clear color
163 //this.renderer.setClearFlags(g_Engine.getContext().DEPTH_BUFFER_BIT); 163 //this.renderer.setClearFlags(RDGE.globals.engine.getContext().DEPTH_BUFFER_BIT);
164 this.renderer.setClearColor([0.0, 0.0, 0.0, 0.0]); 164 this.renderer.setClearColor([0.0, 0.0, 0.0, 0.0]);
165 //this.renderer.NinjaWorld = this; 165 //this.renderer.NinjaWorld = this;
166 166
167 // create an empty scene graph 167 // create an empty scene graph
168 this.myScene = new SceneGraph(); 168 this.myScene = new RDGE.SceneGraph();
169 169
170 // create some lights 170 // create some lights
171 // light 1 171 // light 1
172 this.light = createLightNode("myLight"); 172 this.light = RDGE.createLightNode("myLight");
173 this.light.setPosition([0,0,1.2]); 173 this.light.setPosition([0,0,1.2]);
174 this.light.setDiffuseColor([0.75,0.9,1.0,1.0]); 174 this.light.setDiffuseColor([0.75,0.9,1.0,1.0]);
175 175
176 // light 2 176 // light 2
177 this.light2 = createLightNode("myLight2"); 177 this.light2 = RDGE.createLightNode("myLight2");
178 this.light2.setPosition([-0.5,0,1.2]); 178 this.light2.setPosition([-0.5,0,1.2]);
179 this.light2.setDiffuseColor([1.0,0.9,0.75,1.0]); 179 this.light2.setDiffuseColor([1.0,0.9,0.75,1.0]);
180 180
181 // create a light transform 181 // create a light transform
182 var lightTr = createTransformNode("lightTr"); 182 var lightTr = RDGE.createTransformNode("lightTr");
183 183
184 // create and attach a material - materials hold the light data 184 // create and attach a material - materials hold the light data
185 lightTr.attachMaterial(createMaterialNode("lights")); 185 lightTr.attachMaterial(RDGE.createMaterialNode("lights"));
186 186
187 // enable light channels 1, 2 - channel 0 is used by the default shader 187 // enable light channels 1, 2 - channel 0 is used by the default shader
188 lightTr.materialNode.enableLightChannel(1, this.light); 188 lightTr.materialNode.enableLightChannel(1, this.light);
@@ -195,9 +195,9 @@ var World = function GLWorld( canvas, use3D, preserveDrawingBuffer ) {
195 this.myScene.addNode(lightTr); 195 this.myScene.addNode(lightTr);
196 196
197 // Add the scene to the engine - necessary if you want the engine to draw for you 197 // Add the scene to the engine - necessary if you want the engine to draw for you
198 //g_Engine.AddScene("myScene" + this._canvas.id, this.myScene); 198 //RDGE.globals.engine.AddScene("myScene" + this._canvas.id, this.myScene);
199 var name = this._canvas.getAttribute( "data-RDGE-id" ); 199 var name = this._canvas.getAttribute( "data-RDGE-id" );
200 g_Engine.AddScene("myScene" + name, this.myScene); 200 RDGE.globals.engine.AddScene("myScene" + name, this.myScene);
201 }; 201 };
202 202
203 // main code for handling user interaction and updating the scene 203 // main code for handling user interaction and updating the scene
@@ -209,7 +209,7 @@ var World = function GLWorld( canvas, use3D, preserveDrawingBuffer ) {
209 209
210 if (this._useWebGL) { 210 if (this._useWebGL) {
211 // changed the global position uniform of light 0, another way to change behavior of a light 211 // changed the global position uniform of light 0, another way to change behavior of a light
212 rdgeGlobalParameters.u_light0Pos.set( [5*Math.cos(this.elapsed), 5*Math.sin(this.elapsed), 20]); 212 RDGE.rdgeGlobalParameters.u_light0Pos.set([5 * Math.cos(this.elapsed), 5 * Math.sin(this.elapsed), 20]);
213 213
214 // orbit the light nodes around the boxes 214 // orbit the light nodes around the boxes
215 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)]); 215 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)]);
@@ -226,8 +226,8 @@ var World = function GLWorld( canvas, use3D, preserveDrawingBuffer ) {
226 // defining the draw function to control how the scene is rendered 226 // defining the draw function to control how the scene is rendered
227 this.draw = function() { 227 this.draw = function() {
228 if (this._useWebGL) { 228 if (this._useWebGL) {
229 g_Engine.setContext( this._canvas.rdgeid ); 229 RDGE.globals.engine.setContext( this._canvas.rdgeid );
230 var ctx = g_Engine.getContext(); 230 var ctx = RDGE.globals.engine.getContext();
231 var renderer = ctx.renderer; 231 var renderer = ctx.renderer;
232 if (renderer.unloadedTextureCount <= 0) { 232 if (renderer.unloadedTextureCount <= 0) {
233 renderer.disableCulling(); 233 renderer.disableCulling();
@@ -364,10 +364,10 @@ var World = function GLWorld( canvas, use3D, preserveDrawingBuffer ) {
364 // in the case of a procedurally built scene an init state is not needed for loading data 364 // in the case of a procedurally built scene an init state is not needed for loading data
365 if (this._useWebGL) { 365 if (this._useWebGL) {
366 rdgeStarted = true; 366 rdgeStarted = true;
367 this._canvas.rdgeid = this._canvas.getAttribute( "data-RDGE-id" ); 367 this._canvas.rdgeid = this._canvas.getAttribute( "data-RDGE-id" );
368 g_Engine.unregisterCanvas( this._canvas ) 368 RDGE.globals.engine.unregisterCanvas( this._canvas );
369 g_Engine.registerCanvas(this._canvas, this); 369 RDGE.globals.engine.registerCanvas(this._canvas, this);
370 RDGEStart( this._canvas ); 370 RDGE.RDGEStart( this._canvas );
371 this._canvas.task.stop() 371 this._canvas.task.stop()
372 } 372 }
373}; 373};
@@ -396,13 +396,13 @@ World.prototype.updateObject = function (obj) {
396 if (nPrims > 0) { 396 if (nPrims > 0) {
397 ctrTrNode = obj.getTransformNode(); 397 ctrTrNode = obj.getTransformNode();
398 if (ctrTrNode == null) { 398 if (ctrTrNode == null) {
399 ctrTrNode = createTransformNode("objRootNode_" + this._nodeCounter++); 399 ctrTrNode = RDGE.createTransformNode("objRootNode_" + this._nodeCounter++);
400 this._rootNode.insertAsChild( ctrTrNode ); 400 this._rootNode.insertAsChild( ctrTrNode );
401 obj.setTransformNode( ctrTrNode ); 401 obj.setTransformNode( ctrTrNode );
402 } 402 }
403 403
404 ctrTrNode.meshes.forEach(function(thisMesh) { 404 ctrTrNode.meshes.forEach(function(thisMesh) {
405 g_meshMan.deleteMesh(thisMesh.mesh.name); 405 RDGE.globals.meshMan.deleteMesh(thisMesh.mesh.name);
406 }); 406 });
407 ctrTrNode.meshes = []; 407 ctrTrNode.meshes = [];
408 408
@@ -421,11 +421,11 @@ World.prototype.updateObject = function (obj) {
421 childTrNode = children[i-1].transformNode; 421 childTrNode = children[i-1].transformNode;
422 422
423 childTrNode.meshes.forEach(function(thisMesh) { 423 childTrNode.meshes.forEach(function(thisMesh) {
424 g_meshMan.deleteMesh(thisMesh.mesh.name); 424 RDGE.globals.meshMan.deleteMesh(thisMesh.mesh.name);
425 }); 425 });
426 childTrNode.meshes = []; 426 childTrNode.meshes = [];
427 } else { 427 } else {
428 childTrNode = createTransformNode("objNode_" + this._nodeCounter++); 428 childTrNode = RDGE.createTransformNode("objNode_" + this._nodeCounter++);
429 ctrTrNode.insertAsChild(childTrNode); 429 ctrTrNode.insertAsChild(childTrNode);
430 } 430 }
431 431
@@ -527,7 +527,7 @@ World.prototype.clearTree = function() {
527 if (this._useWebGL) { 527 if (this._useWebGL) {
528 var root = this._rootNode; 528 var root = this._rootNode;
529 root.children = new Array(); 529 root.children = new Array();
530 g_Engine.unregisterCanvas( this._canvas.rdgeid ) 530 RDGE.globals.engine.unregisterCanvas( this._canvas.rdgeid )
531 531
532 this.update( 0 ); 532 this.update( 0 );
533 this.draw(); 533 this.draw();
@@ -662,9 +662,9 @@ World.prototype.setMVMatrix = function() {
662 gl.uniformMatrix4fv(this._shaderProgram.mvMatrixUniform, false, new Float32Array(mvMatrix)); 662 gl.uniformMatrix4fv(this._shaderProgram.mvMatrixUniform, false, new Float32Array(mvMatrix));
663 663
664 var normalMatrix = mat3.create(); 664 var normalMatrix = mat3.create();
665 // mat4.toInverseMat3(mvMatrix, normalMatrix); 665 // RDGE.mat4.toInverseMat3(mvMatrix, normalMatrix);
666 // mat4.toInverseMat3(new Float32Array(mvMatrix.flatten()), normalMatrix); 666 // RDGE.mat4.toInverseMat3(new Float32Array(mvMatrix.flatten()), normalMatrix);
667 mat4.toInverseMat3(new Float32Array(mvMatrix), normalMatrix); 667 RDGE.mat4.toInverseMat3(new Float32Array(mvMatrix), normalMatrix);
668 mat3.transpose(normalMatrix); 668 mat3.transpose(normalMatrix);
669 gl.uniformMatrix3fv(this._shaderProgram.nMatrixUniform, false, normalMatrix); 669 gl.uniformMatrix3fv(this._shaderProgram.nMatrixUniform, false, normalMatrix);
670 } 670 }
@@ -685,7 +685,7 @@ World.prototype.render = function() {
685 var root = this.getGeomRoot(); 685 var root = this.getGeomRoot();
686 this.hRender( root ); 686 this.hRender( root );
687 } else { 687 } else {
688 g_Engine.setContext( this._canvas.rdgeid ); 688 RDGE.globals.engine.setContext( this._canvas.rdgeid );
689 //this.draw(); 689 //this.draw();
690 this.restartRenderLoop(); 690 this.restartRenderLoop();
691 } 691 }
@@ -1083,16 +1083,16 @@ World.prototype.importSubObject = function( objStr, parentNode ) {
1083 i0 += 10; 1083 i0 += 10;
1084 var matText = objStr.substr( i0, i1 - i0 ); 1084 var matText = objStr.substr( i0, i1 - i0 );
1085 var shaderDef = JSON.parse( matText ); 1085 var shaderDef = JSON.parse( matText );
1086 var shader = new jshader(); 1086 var shader = new RDGE.jshader();
1087 shader.def = shaderDef; 1087 shader.def = shaderDef;
1088 shader.init(); 1088 shader.init();
1089 1089
1090 // set the shader for this material 1090 // set the shader for this material
1091