From 648ee61ae84216d0236e0dbc211addc13b2cfa3a Mon Sep 17 00:00:00 2001 From: Kris Kowal Date: Fri, 6 Jul 2012 11:52:06 -0700 Subject: Expand tabs --- js/lib/NJUtils.js | 102 +- js/lib/drawing/world.js | 1238 ++++++++++----------- js/lib/geom/circle.js | 216 ++-- js/lib/geom/geom-obj.js | 40 +- js/lib/geom/line.js | 68 +- js/lib/geom/rectangle.js | 1132 +++++++++---------- js/lib/geom/shape-primitive.js | 336 +++--- js/lib/math/matrix.js | 68 +- js/lib/rdge/materials/bump-metal-material.js | 154 +-- js/lib/rdge/materials/cloud-material.js | 704 ++++++------ js/lib/rdge/materials/deform-material.js | 88 +- js/lib/rdge/materials/flag-material.js | 160 +-- js/lib/rdge/materials/flat-material.js | 60 +- js/lib/rdge/materials/fly-material.js | 136 +-- js/lib/rdge/materials/julia-material.js | 128 +-- js/lib/rdge/materials/keleidoscope-material.js | 136 +-- js/lib/rdge/materials/linear-gradient-material.js | 214 ++-- js/lib/rdge/materials/mandel-material.js | 130 +-- js/lib/rdge/materials/material-parser.js | 4 +- js/lib/rdge/materials/material.js | 574 +++++----- js/lib/rdge/materials/plasma-material.js | 160 +-- js/lib/rdge/materials/pulse-material.js | 308 ++--- js/lib/rdge/materials/radial-blur-material.js | 84 +- js/lib/rdge/materials/radial-gradient-material.js | 170 +-- js/lib/rdge/materials/relief-tunnel-material.js | 84 +- js/lib/rdge/materials/square-tunnel-material.js | 84 +- js/lib/rdge/materials/star-material.js | 100 +- js/lib/rdge/materials/taper-material.js | 56 +- js/lib/rdge/materials/tunnel-material.js | 86 +- js/lib/rdge/materials/twist-material.js | 84 +- js/lib/rdge/materials/twist-vert-material.js | 290 ++--- js/lib/rdge/materials/uber-material.js | 262 ++--- js/lib/rdge/materials/water-material.js | 272 ++--- js/lib/rdge/materials/z-invert-material.js | 102 +- js/lib/rdge/texture.js | 600 +++++----- 35 files changed, 4215 insertions(+), 4215 deletions(-) (limited to 'js/lib') diff --git a/js/lib/NJUtils.js b/js/lib/NJUtils.js index 1406ad98..e924e1b8 100755 --- a/js/lib/NJUtils.js +++ b/js/lib/NJUtils.js @@ -65,9 +65,9 @@ exports.NJUtils = Montage.create(Component, { children : { value : function(el, filter) { var f = filter || function(item) { - return item.nodeType === 1; - }; - return this.toArray(el.childNodes).filter(f); + return item.nodeType === 1; + }; + return this.toArray(el.childNodes).filter(f); } }, @@ -185,54 +185,54 @@ exports.NJUtils = Montage.create(Component, { }, queryParentSelector : { - value: function(el, strSelector) { - // queryParentSelector: - // Given a DOM element el (required), walk up the DOM tree - // and find the first parent that matches selector strSelector (required). - // Returns: The element that matches, or false if there is no match - // or if insufficient parameters are supplied. - - if ((typeof(el) === "undefined") || (typeof(strSelector) === "undefined")) { - // Parameters are required, m'kay? - return false; - } else if ((typeof(el) !== "object") || (typeof(strSelector) !== "string" )) { - // You also have to use the right parameters. - return false; - } - - // First, get an empty clone of the parent. - var myParent = el.parentNode; - var clone = myParent.cloneNode(false); - if (clone === null) { - return false; - } - - // If we're at the top of the DOM, our clone will be an htmlDocument. - // htmlDocument has no tagName. - if (typeof(clone.tagName) !== "undefined") { - // create a bogus div to use as a base for querySelector - var temp = document.createElement("div"); - - // Append the clone to the bogus div - temp.appendChild(clone); - - // Now we can use querySelector! Sweet. - var selectorTest = temp.querySelector(strSelector); - - // What has querySelector returned? - if (selectorTest === null) { - // No match, so recurse. - return this.queryParentSelector(myParent, strSelector); - } else { - // Match! Return the element. - return myParent; - } - } else { - // We're at the top of the DOM so we're done. - return false; - } - } - + value: function(el, strSelector) { + // queryParentSelector: + // Given a DOM element el (required), walk up the DOM tree + // and find the first parent that matches selector strSelector (required). + // Returns: The element that matches, or false if there is no match + // or if insufficient parameters are supplied. + + if ((typeof(el) === "undefined") || (typeof(strSelector) === "undefined")) { + // Parameters are required, m'kay? + return false; + } else if ((typeof(el) !== "object") || (typeof(strSelector) !== "string" )) { + // You also have to use the right parameters. + return false; + } + + // First, get an empty clone of the parent. + var myParent = el.parentNode; + var clone = myParent.cloneNode(false); + if (clone === null) { + return false; + } + + // If we're at the top of the DOM, our clone will be an htmlDocument. + // htmlDocument has no tagName. + if (typeof(clone.tagName) !== "undefined") { + // create a bogus div to use as a base for querySelector + var temp = document.createElement("div"); + + // Append the clone to the bogus div + temp.appendChild(clone); + + // Now we can use querySelector! Sweet. + var selectorTest = temp.querySelector(strSelector); + + // What has querySelector returned? + if (selectorTest === null) { + // No match, so recurse. + return this.queryParentSelector(myParent, strSelector); + } else { + // Match! Return the element. + return myParent; + } + } else { + // We're at the top of the DOM so we're done. + return false; + } + } + }, // Returns the numerical value and unit string from a string. diff --git a/js/lib/drawing/world.js b/js/lib/drawing/world.js index fb70d18c..b20b0a5d 100755 --- a/js/lib/drawing/world.js +++ b/js/lib/drawing/world.js @@ -46,66 +46,66 @@ var World = function GLWorld( canvas, use3D, preserveDrawingBuffer ) { // Instance variables /////////////////////////////////////////////////////////////////////// - // flag to do the drawing with WebGL + // flag to do the drawing with WebGL this._useWebGL = false; if(use3D) { this._useWebGL = use3D; } this._canvas = canvas; - if (this._useWebGL) - { + if (this._useWebGL) + { if(preserveDrawingBuffer) - { + { this._glContext = canvas.getContext("experimental-webgl", {preserveDrawingBuffer: true}); } - else - { - this._glContext = canvas.getContext("experimental-webgl"); + else + { + this._glContext = canvas.getContext("experimental-webgl"); } } - else - { - this._2DContext = canvas.getContext( "2d" ); + else + { + this._2DContext = canvas.getContext( "2d" ); } - this._viewportWidth = canvas.width; + this._viewportWidth = canvas.width; this._viewportHeight = canvas.height; - // view parameters - this._fov = 45.0; - this._zNear = 0.1; - this._zFar = 100.0; - this._viewDist = 5.0; + // view parameters + this._fov = 45.0; + this._zNear = 0.1; + this._zFar = 100.0; + this._viewDist = 5.0; - // default light parameters - this._ambientLightColor = [0.1, 0.1, 0.1, 1.0]; - this._diffuseLightColor = [0.1, 0.1, 0.1, 1.0]; - this._specularLightColor = [0.6, 0.6, 0.6, 1.0]; - this._pointLightLoc = [0.0, 0.0, 0.05]; + // default light parameters + this._ambientLightColor = [0.1, 0.1, 0.1, 1.0]; + this._diffuseLightColor = [0.1, 0.1, 0.1, 1.0]; + this._specularLightColor = [0.6, 0.6, 0.6, 1.0]; + this._pointLightLoc = [0.0, 0.0, 0.05]; - // default material properties. Material properties should be overridden - // by the materials used by the objects - this._materialShininess = 20.0; + // default material properties. Material properties should be overridden + // by the materials used by the objects + this._materialShininess = 20.0; this._geomRoot = undefined; - this._cameraMat = Matrix.I(4); - this._cameraMat[14] = 5.0; - this._cameraMatInv = Matrix.I(4); - this._cameraMatInv[14] = -5.0; + this._cameraMat = Matrix.I(4); + this._cameraMat[14] = 5.0; + this._cameraMatInv = Matrix.I(4); + this._cameraMatInv[14] = -5.0; this._camera = null; - // keep a flag indicating whether a render has been completed. - // this allows us to turn off automatic updating if there are - // no animated materials - this._firstRender = true; + // keep a flag indicating whether a render has been completed. + // this allows us to turn off automatic updating if there are + // no animated materials + this._firstRender = true; - this._worldCount = worldCounter; - worldCounter++; + this._worldCount = worldCounter; + worldCounter++; - // keep a counter for generating node names - this._nodeCounter = 0; + // keep a counter for generating node names + this._nodeCounter = 0; // for sending notifications to listeners this._notifier = new Notifier(); @@ -113,42 +113,42 @@ var World = function GLWorld( canvas, use3D, preserveDrawingBuffer ) { /////////////////////////////////////////////////////////////////////// // Property accessors /////////////////////////////////////////////////////////////////////// - this.getGLContext = function() { return this._glContext; }; - this.setGLContext = function(gl) { this._glContext = gl; }; + this.getGLContext = function() { return this._glContext; }; + this.setGLContext = function(gl) { this._glContext = gl; }; - this.get2DContext = function() { return this._2DContext; }; - this.set2DContext = function(c) { this._2DContext = c; }; + this.get2DContext = function() { return this._2DContext; }; + this.set2DContext = function(c) { this._2DContext = c; }; - this.getCanvas = function() { return this._canvas; }; - this.setCanvas = function(c) { this._canvas = c; }; + this.getCanvas = function() { return this._canvas; }; + this.setCanvas = function(c) { this._canvas = c; }; - this.getShaderProgram = function() { return this._shaderProgram; }; + this.getShaderProgram = function() { return this._shaderProgram; }; - this.getViewportWidth = function() { return this._viewportWidth; }; - this.getViewportHeight = function() { return this._viewportHeight; }; + this.getViewportWidth = function() { return this._viewportWidth; }; + this.getViewportHeight = function() { return this._viewportHeight; }; - this.getAspect = function() { return this._viewportWidth/this._viewportHeight; }; + this.getAspect = function() { return this._viewportWidth/this._viewportHeight; }; - this.getGeomRoot = function() { return this._geomRoot; }; - this.getZNear = function() { return this._zNear; }; - this.getZFar = function() { return this._zFar; }; - this.getFOV = function() { return this._fov; }; + this.getGeomRoot = function() { return this._geomRoot; }; + this.getZNear = function() { return this._zNear; }; + this.getZFar = function() { return this._zFar; }; + this.getFOV = function() { return this._fov; }; - this.getCamera = function() { return this._camera; }; + this.getCamera = function() { return this._camera; }; - this.getCameraMat = function() { return this._cameraMat.slice(0); }; - this.setCameraMat = function(c) { this._cameraMat = c.slice(0); this._cameraMatInv = glmat4.inverse(c, []); }; + this.getCameraMat = function() { return this._cameraMat.slice(0); }; + this.setCameraMat = function(c) { this._cameraMat = c.slice(0); this._cameraMatInv = glmat4.inverse(c, []); }; - this.getCameraMatInverse = function() { return this._cameraMatInv.slice(0); }; + this.getCameraMatInverse = function() { return this._cameraMatInv.slice(0); }; - this.getViewDistance = function() { return this._viewDist; }; + this.getViewDistance = function() { return this._viewDist; }; - this.getRootNode = function() { return this._rootNode; }; - this.setRootNode = function(r) { this._rootNode = r; }; + this.getRootNode = function() { return this._rootNode; }; + this.setRootNode = function(r) { this._rootNode = r; }; - this.isWebGL = function() { return this._useWebGL; }; + this.isWebGL = function() { return this._useWebGL; }; - this.getRenderer = function() { return this.renderer; }; + this.getRenderer = function() { return this.renderer; }; // Flag to play/pause animation at authortime this._previewAnimation = true; @@ -164,265 +164,265 @@ var World = function GLWorld( canvas, use3D, preserveDrawingBuffer ) { this.strokeShader = null; this.renderer = null; - // keep an array of texture maps that need to be loaded - this._texMapsToLoad = []; - this._allMapsLoaded = true; + // keep an array of texture maps that need to be loaded + this._texMapsToLoad = []; + this._allMapsLoaded = true; - // this is the node to which objects get hung - this._rootNode = null; + // this is the node to which objects get hung + this._rootNode = null; - // set up the camera matrix - var camMat = Matrix.I(4); - camMat[14] = this.getViewDistance(); - this.setCameraMat( camMat ); + // set up the camera matrix + var camMat = Matrix.I(4); + camMat[14] = this.getViewDistance(); + this.setCameraMat( camMat ); // post-load processing of the scene this.init = function() - { - var ctx1 = RDGE.globals.engine.ctxMan.handleToObject(this._canvas.rdgeCtxHandle), - ctx2 = RDGE.globals.engine.getContext(); - if (ctx1 != ctx2) console.log( "***** different contexts *****" ); - this.renderer = ctx1.renderer; - this.renderer._world = this; + { + var ctx1 = RDGE.globals.engine.ctxMan.handleToObject(this._canvas.rdgeCtxHandle), + ctx2 = RDGE.globals.engine.getContext(); + if (ctx1 != ctx2) console.log( "***** different contexts *****" ); + this.renderer = ctx1.renderer; + this.renderer._world = this; - // create a camera, set its perspective, and then point it at the origin - var cam = new RDGE.camera(); - this._camera = cam; - cam.setPerspective(this.getFOV(), this.getAspect(), this.getZNear(), this.getZFar()); - cam.setLookAt([0, 0, this.getViewDistance()], [0, 0, 0], RDGE.vec3.up()); + // create a camera, set its perspective, and then point it at the origin + var cam = new RDGE.camera(); + this._camera = cam; + cam.setPerspective(this.getFOV(), this.getAspect(), this.getZNear(), this.getZFar()); + cam.setLookAt([0, 0, this.getViewDistance()], [0, 0, 0], RDGE.vec3.up()); - // make this camera the active camera - this.renderer.cameraManager().setActiveCamera(cam); + // make this camera the active camera + this.renderer.cameraManager().setActiveCamera(cam); - // change clear color - //this.renderer.setClearFlags(RDGE.globals.engine.getContext().DEPTH_BUFFER_BIT); - this.renderer.setClearColor([0.0, 0.0, 0.0, 0.0]); - //this.renderer.NinjaWorld = this; + // change clear color + //this.renderer.setClearFlags(RDGE.globals.engine.getContext().DEPTH_BUFFER_BIT); + this.renderer.setClearColor([0.0, 0.0, 0.0, 0.0]); + //this.renderer.NinjaWorld = this; - // create an empty scene graph - this.myScene = new RDGE.SceneGraph(); + // create an empty scene graph + this.myScene = new RDGE.SceneGraph(); - // create some lights - // light 1 -// this.light = RDGE.createLightNode("myLight"); -// this.light.setPosition([0,0,1.2]); -// this.light.setDiffuseColor([0.75,0.9,1.0,1.0]); + // create some lights + // light 1 +// this.light = RDGE.createLightNode("myLight"); +// this.light.setPosition([0,0,1.2]); +// this.light.setDiffuseColor([0.75,0.9,1.0,1.0]); - // light 2 -// this.light2 = RDGE.createLightNode("myLight2"); -// this.light2.setPosition([-0.5,0,1.2]); -// this.light2.setDiffuseColor([1.0,0.9,0.75,1.0]); + // light 2 +// this.light2 = RDGE.createLightNode("myLight2"); +// this.light2.setPosition([-0.5,0,1.2]); +// this.light2.setDiffuseColor([1.0,0.9,0.75,1.0]); - // create a light transform - var lightTr = RDGE.createTransformNode("lightTr"); + // create a light transform + var lightTr = RDGE.createTransformNode("lightTr"); - // create and attach a material - materials hold the light data - lightTr.attachMaterial(RDGE.createMaterialNode("lights")); + // create and attach a material - materials hold the light data + lightTr.attachMaterial(RDGE.createMaterialNode("lights")); - // enable light channels 1, 2 - channel 0 is used by the default shader -// lightTr.materialNode.enableLightChannel(1, this.light); -// lightTr.materialNode.enableLightChannel(2, this.light2); + // enable light channels 1, 2 - channel 0 is used by the default shader +// lightTr.materialNode.enableLightChannel(1, this.light); +// lightTr.materialNode.enableLightChannel(2, this.light2); - // all added objects are parented to the light node - this._rootNode = lightTr; + // all added objects are parented to the light node + this._rootNode = lightTr; - // add the light node to the scene - this.myScene.addNode(lightTr); + // add the light node to the scene + this.myScene.addNode(lightTr); - // Add the scene to the engine - necessary if you want the engine to draw for you - //RDGE.globals.engine.AddScene("myScene" + this._canvas.id, this.myScene); - var name = this._canvas.getAttribute( "data-RDGE-id" ); - RDGE.globals.engine.AddScene("myScene" + name, this.myScene); - }; + // Add the scene to the engine - necessary if you want the engine to draw for you + //RDGE.globals.engine.AddScene("myScene" + this._canvas.id, this.myScene); + var name = this._canvas.getAttribute( "data-RDGE-id" ); + RDGE.globals.engine.AddScene("myScene" + name, this.myScene); + }; - // main code for handling user interaction and updating the scene - this.update = function(dt) - { - if (!dt) dt = 0.2; + // main code for handling user interaction and updating the scene + this.update = function(dt) + { + if (!dt) dt = 0.2; - dt = 0.01; // use our own internal throttle - this.elapsed += dt; + dt = 0.01; // use our own internal throttle + this.elapsed += dt; - if (this._useWebGL) - { - // changed the global position uniform of light 0, another way to change behavior of a light - RDGE.rdgeGlobalParameters.u_light0Pos.set([5 * Math.cos(this.elapsed), 5 * Math.sin(this.elapsed), 20]); + if (this._useWebGL) + { + // changed the global position uniform of light 0, another way to change behavior of a light + RDGE.rdgeGlobalParameters.u_light0Pos.set([5 * Math.cos(this.elapsed), 5 * Math.sin(this.elapsed), 20]); - // orbit the light nodes around the boxes -// 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)]); -// this.light2.setPosition([-1.2*Math.cos(this.elapsed*2.0), 1.2*Math.sin(this.elapsed*2.0), -1.2*Math.cos(this.elapsed)]); - } + // orbit the light nodes around the boxes +// 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)]); +// this.light2.setPosition([-1.2*Math.cos(this.elapsed*2.0), 1.2*Math.sin(this.elapsed*2.0), -1.2*Math.cos(this.elapsed)]); + } - this.updateMaterials( this.getGeomRoot(), this.elapsed ); + this.updateMaterials( this.getGeomRoot(), this.elapsed ); - // now update all the nodes in the scene - if (this._useWebGL) - this.myScene.update(dt); + // now update all the nodes in the scene + if (this._useWebGL) + this.myScene.update(dt); }; // defining the draw function to control how the scene is rendered - this.draw = function() - { - if (this._useWebGL) - { - RDGE.globals.engine.setContext( this._canvas.rdgeid ); - var ctx = RDGE.globals.engine.getContext(); - var renderer = ctx.renderer; - if (renderer.unloadedTextureCount <= 0) - { - renderer.disableCulling(); - renderer._clear(); - this.myScene.render(); - - if (this._firstRender) - { - this._notifier.sendNotification( this._notifier.FIRST_RENDER ); - if (this._canvas.task) - { - this._firstRender = false; - - if (!this.hasAnimatedMaterials() || !this._previewAnimation) - { - this._canvas.task.stop(); - //this._renderCount = 10; - } - } - } - else if (this._renderCount >= 0) - { - if (this._canvas.task) - { - this._renderCount--; - if (this._renderCount <= 0) - { - this._canvas.task.stop(); + this.draw = function() + { + if (this._useWebGL) + { + RDGE.globals.engine.setContext( this._canvas.rdgeid ); + var ctx = RDGE.globals.engine.getContext(); + var renderer = ctx.renderer; + if (renderer.unloadedTextureCount <= 0) + { + renderer.disableCulling(); + renderer._clear(); + this.myScene.render(); + + if (this._firstRender) + { + this._notifier.sendNotification( this._notifier.FIRST_RENDER ); + if (this._canvas.task) + { + this._firstRender = false; + + if (!this.hasAnimatedMaterials() || !this._previewAnimation) + { + this._canvas.task.stop(); + //this._renderCount = 10; + } + } + } + else if (this._renderCount >= 0) + { + if (this._canvas.task) + { + this._renderCount--; + if (this._renderCount <= 0) + { + this._canvas.task.stop(); } - } - } - } - } - else - { - this.render(); - } + } + } + } + } + else + { + this.render(); + } }; - + this.onRunState = function() { -// console.log( "GLWorld.onRunState" ); - this.restartRenderLoop(); - }; - +// console.log( "GLWorld.onRunState" ); + this.restartRenderLoop(); + }; + this.onLoadState = function() { -// console.log( "GLWorld.onLoadState" ); - }; - - this.textureToLoad = function( texture ) - { - if (!texture.previouslyReferenced) - { - var name = texture.lookUpName; - texture._world = this; - texture.callback = this.textureMapLoaded; - this._texMapsToLoad[name] = true; - this._allMapsLoaded = false; - - // stop the draw loop until all textures have been loaded - this._canvas.task.stop(); - } - }; - - this.textureMapLoaded = function( texture ) - { - var world = texture._world; - if (!world) { - console.log( "**** loaded texture does not have world defined ****" ); - return; - } - - var name = texture.lookUpName; - if (!world._texMapsToLoad[name]) { - console.log( "loaded an unregistered texture map: " + name ); - } - else { - //console.log( "loaded a registered texture map: " + name ); - world._texMapsToLoad[name] = undefined; - } - - // check if all the texture maps are loaded. if so, resume the render loop - world._allMapsLoaded = world.allTextureMapsLoaded(); - if (world._allMapsLoaded) { - world._canvas.task.start(); +// console.log( "GLWorld.onLoadState" ); + }; + + this.textureToLoad = function( texture ) + { + if (!texture.previouslyReferenced) + { + var name = texture.lookUpName; + texture._world = this; + texture.callback = this.textureMapLoaded; + this._texMapsToLoad[name] = true; + this._allMapsLoaded = false; + + // stop the draw loop until all textures have been loaded + this._canvas.task.stop(); } - }; + }; - this.allTextureMapsLoaded = function() { - for (var name in this._texMapsToLoad) { - var needsLoad = this._texMapsToLoad[name]; - if (needsLoad) return false; - } + this.textureMapLoaded = function( texture ) + { + var world = texture._world; + if (!world) { + console.log( "**** loaded texture does not have world defined ****" ); + return; + } - return true; - }; + var name = texture.lookUpName; + if (!world._texMapsToLoad[name]) { + console.log( "loaded an unregistered texture map: " + name ); + } + else { + //console.log( "loaded a registered texture map: " + name ); + world._texMapsToLoad[name] = undefined; + } - this.textureLoadedCallback = function( name ) { -// console.log( "*** material texture loaded: " + name ); + // check if all the texture maps are loaded. if so, resume the render loop + world._allMapsLoaded = world.allTextureMapsLoaded(); + if (world._allMapsLoaded) { + world._canvas.task.start(); + } + }; - var world = this._world; - if (!world) { - console.log( "**** world not defined for loaded texture map: " + name ); + this.allTextureMapsLoaded = function() { + for (var name in this._texMapsToLoad) { + var needsLoad = this._texMapsToLoad[name]; + if (needsLoad) return false; } - else { - world.textureMapLoaded( name ); + + return true; + }; + + this.textureLoadedCallback = function( name ) { +// console.log( "*** material texture loaded: " + name ); + + var world = this._world; + if (!world) { + console.log( "**** world not defined for loaded texture map: " + name ); + } + else { + world.textureMapLoaded( name ); } - }; - - this.hasAnimatedMaterials = function() { - var root = this.getGeomRoot(); - var rtnVal = false; - if (root) { - rtnVal = this.hHasAnimatedMaterials( root ); + }; + + this.hasAnimatedMaterials = function() { + var root = this.getGeomRoot(); + var rtnVal = false; + if (root) { + rtnVal = this.hHasAnimatedMaterials( root ); this._hasAnimatedMaterials = rtnVal; } - else - { - // currently... - // we set this case to true - cloud materials create a - // world with no objects but cloud materials animate. - // TODO - find a better way to do this - rtnVal = true; - this._hasAnimatedMaterials = true; - } - - return rtnVal; - }; - - this.hHasAnimatedMaterials = function( obj ) { - if (obj) { - if (obj.getFillMaterial()) { - if (obj.getFillMaterial().isAnimated()) return true; - } - - if (obj.getStrokeMaterial()) { - if (obj.getStrokeMaterial().isAnimated()) return true; - } - - - // do the sibling - var hasAnim = false; - if (obj.getNext()) hasAnim = this.hHasAnimatedMaterials( obj.getNext() ); - if (hasAnim) return true; - if (obj.getChild()) hasAnim = this.hHasAnimatedMaterials( obj.getChild() ); - if (hasAnim) return true; - } - - return false; - }; - - this.generateUniqueNodeID = function() { - var str = "" + this._nodeCounter; - this._nodeCounter++; - return str; - }; + else + { + // currently... + // we set this case to true - cloud materials create a + // world with no objects but cloud materials animate. + // TODO - find a better way to do this + rtnVal = true; + this._hasAnimatedMaterials = true; + } + + return rtnVal; + }; + + this.hHasAnimatedMaterials = function( obj ) { + if (obj) { + if (obj.getFillMaterial()) { + if (obj.getFillMaterial().isAnimated()) return true; + } + + if (obj.getStrokeMaterial()) { + if (obj.getStrokeMaterial().isAnimated()) return true; + } + + + // do the sibling + var hasAnim = false; + if (obj.getNext()) hasAnim = this.hHasAnimatedMaterials( obj.getNext() ); + if (hasAnim) return true; + if (obj.getChild()) hasAnim = this.hHasAnimatedMaterials( obj.getChild() ); + if (hasAnim) return true; + } + + return false; + }; + + this.generateUniqueNodeID = function() { + var str = "" + this._nodeCounter; + this._nodeCounter++; + return str; + }; this.addListener = function( obj, callbackFunc, calleeData ) { @@ -436,14 +436,14 @@ var World = function GLWorld( canvas, use3D, preserveDrawingBuffer ) { // start RDGE passing your runtime object, and false to indicate we don't need a an initialization state // in the case of a procedurally built scene an init state is not needed for loading data - this._canvas.rdgeid = this._canvas.getAttribute( "data-RDGE-id" ); - if (this._useWebGL) { - rdgeStarted = true; - RDGE.globals.engine.unregisterCanvas( this._canvas ); - RDGE.globals.engine.registerCanvas(this._canvas, this); - RDGE.RDGEStart( this._canvas ); - this._canvas.task.stop() - } + this._canvas.rdgeid = this._canvas.getAttribute( "data-RDGE-id" ); + if (this._useWebGL) { + rdgeStarted = true; + RDGE.globals.engine.unregisterCanvas( this._canvas ); + RDGE.globals.engine.registerCanvas(this._canvas, this); + RDGE.RDGEStart( this._canvas ); + this._canvas.task.stop() + } }; @@ -459,66 +459,66 @@ World.prototype.getGeomRoot = function() { // Methods /////////////////////////////////////////////////////////////////////// World.prototype.updateObject = function (obj) { - if (!this._useWebGL) return; - - var prims = obj.getPrimitiveArray(); - var materialNodes = obj.getMaterialNodeArray(); - if (prims.length != materialNodes.length) - throw new Error("inconsistent material and primitive counts"); - var nPrims = prims.length; - var ctrTrNode; - if (nPrims > 0) - { - ctrTrNode = obj.getTransformNode(); - if (ctrTrNode == null) { - ctrTrNode = RDGE.createTransformNode("objRootNode_" + this._nodeCounter++); - this._rootNode.insertAsChild( ctrTrNode ); - obj.setTransformNode( ctrTrNode ); - } - - ctrTrNode.meshes.forEach( - function(thisMesh) { - RDGE.globals.meshMan.deleteMesh(thisMesh.mesh.name); - } - ); - ctrTrNode.meshes = []; - - ctrTrNode.attachMeshNode(this.renderer.id + "_prim_" + this._nodeCounter++, prims[0]); - ctrTrNode.attachMaterial(materialNodes[0]); - } - - // delete all of the child nodes - var i; - var childTrNode; - var children = ctrTrNode.children; - for (i=0; i 0) + { + ctrTrNode = obj.getTransformNode(); + if (ctrTrNode == null) { + ctrTrNode = RDGE.createTransformNode("objRootNode_" + this._nodeCounter++); + this._rootNode.insertAsChild( ctrTrNode ); + obj.setTransformNode( ctrTrNode ); + } + + ctrTrNode.meshes.forEach( + function(thisMesh) { + RDGE.globals.meshMan.deleteMesh(thisMesh.mesh.name); + } + ); + ctrTrNode.meshes = []; + + ctrTrNode.attachMeshNode(this.renderer.id + "_prim_" + this._nodeCounter++, prims[0]); + ctrTrNode.attachMaterial(materialNodes[0]); + } + + // delete all of the child nodes + var i; + var childTrNode; + var children = ctrTrNode.children; + for (i=0; i= 1)) { this.rebuildTree(this._geomRoot); this.restartRenderLoop(); - } - } - - // convert the object to a string - var jStr = JSON.stringify( worldObj ); - - // prepend some version information to the string. - // this string is also used to differentiate between JSON - // and pre-JSON versions of fileIO. - // the ending ';' in the version string is necessary - jStr = "v1.0;" + jStr; - - return jStr; + } + } + + // convert the object to a string + var jStr = JSON.stringify( worldObj ); + + // prepend some version information to the string. + // this string is also used to differentiate between JSON + // and pre-JSON versions of fileIO. + // the ending ';' in the version string is necessary + jStr = "v1.0;" + jStr; + + return jStr; }; World.prototype.rebuildTree = function (obj) { - if (!obj) return; + if (!obj) return; - obj.buildBuffers(); + obj.buildBuffers(); - if (obj.getChild()) { - this.rebuildTree( obj.getChild () ); + if (obj.getChild()) { + this.rebuildTree( obj.getChild () ); } - if (obj.getNext()) - this.rebuildTree( obj.getNext() ); + if (obj.getNext()) + this.rebuildTree( obj.getNext() ); }; World.prototype.exportObjectsJSON = function( obj, parentObj ) { - if (!obj) return; + if (!obj) return; - var jObj = obj.exportJSON(); - if (!parentObj.children) parentObj.children = []; - parentObj.children.push( jObj ); + var jObj = obj.exportJSON(); + if (!parentObj.children) parentObj.children = []; + parentObj.children.push( jObj ); - if (obj.getChild()) { - this.exportObjectsJSON( obj.getChild (), jObj ); + if (obj.getChild()) { + this.exportObjectsJSON( obj.getChild (), jObj ); } - if (obj.getNext()) - this.exportObjectsJSON( obj.getNext(), parentObj ); + if (obj.getNext()) + this.exportObjectsJSON( obj.getNext(), parentObj ); } World.prototype.findTransformNodeByMaterial = function( materialNode, trNode ) { - //if (trNode == null) trNode = this._ctrNode; - if (trNode == null) trNode = this._rootNode; - if ( trNode.transformNode && (materialNode == trNode.transformNode.materialNode)) return trNode; - - var rtnNode; - if (trNode.children != null) - { - var nKids = trNode.children.length; - for (var i=0; i 0) { this._width = width; @@ -85,14 +85,14 @@ exports.Circle = Object.create(GeomObj, { } else { this._strokeMaterial = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ).dup(); } - if (strokeColor && this._strokeMaterial.hasProperty( "color" )) this._strokeMaterial.setProperty( "color", this._strokeColor ); + if (strokeColor && this._strokeMaterial.hasProperty( "color" )) this._strokeMaterial.setProperty( "color", this._strokeColor ); if(fillMaterial) { this._fillMaterial = fillMaterial.dup(); } else { this._fillMaterial = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ).dup(); } - if (fillColor && this._fillMaterial.hasProperty( "color" )) this._fillMaterial.setProperty( "color", this._fillColor ); + if (fillColor && this._fillMaterial.hasProperty( "color" )) this._fillMaterial.setProperty( "color", this._fillColor ); } }, @@ -203,7 +203,7 @@ exports.Circle = Object.create(GeomObj, { }, /////////////////////////////////////////////////////////////////////// - // update the "color of the material + // update the "color of the material getFillColor: { value: function() { return this._fillColor; @@ -251,15 +251,15 @@ exports.Circle = Object.create(GeomObj, { // get the normalized device coordinates (NDC) for // all position and dimensions. - var vpw = world.getViewportWidth(), vph = world.getViewportHeight(); - var xNDC = 2*this._xOffset/vpw, yNDC = -2*this._yOffset/vph, + var vpw = world.getViewportWidth(), vph = world.getViewportHeight(); + var xNDC = 2*this._xOffset/vpw, yNDC = -2*this._yOffset/vph, xRadNDC = this._width/vpw, yRadNDC = this._height/vph, xStrokeNDC = 2*this._strokeWidth/vpw, yStrokeNDC = 2*this._strokeWidth/vph, xInnRadNDC = this._innerRadius*xRadNDC, yInnRadNDC = this._innerRadius*yRadNDC; var aspect = world.getAspect(); var zn = world.getZNear(), zf = world.getZFar(); - var t = zn * Math.tan(world.getFOV() * Math.PI / 360.0), + var t = zn * Math.tan(world.getFOV() * Math.PI / 360.0), b = -t, r = aspect*t, l = -r; @@ -321,7 +321,7 @@ exports.Circle = Object.create(GeomObj, { if(this._strokeWidth > 0) { var numStrokes = 1; if(this._innerRadius !== 0) { - strokeMaterial0 = this.makeStrokeMaterial(); + strokeMaterial0 = this.makeStrokeMaterial(); strokePrim0 = this.generateOvalRing(x, y, reverseRotMat, innerStrokeScaleMat, innerRadiusScaleMat, nTriangles, strokeMaterial0); } @@ -330,14 +330,14 @@ exports.Circle = Object.create(GeomObj, { } if (strokePrim0) { - strokeMaterial0.fitToPrimitive( strokePrim0 ); + strokeMaterial0.fitToPrimitive( strokePrim0 ); this._primArray.push( strokePrim0 ); this._materialNodeArray.push( strokeMaterial0.getMaterialNode() ); } if (strokePrim1) { - strokeMaterial2.fitToPrimitive( strokePrim1 ); + strokeMaterial2.fitToPrimitive( strokePrim1 ); this._primArray.push( strokePrim1 ); this._materialNodeArray.push( strokeMaterial2.getMaterialNode() ); @@ -353,7 +353,7 @@ exports.Circle = Object.create(GeomObj, { } if (fillPrim) { - fillMaterial.fitToPrimitive( fillPrim ); + fillMaterial.fitToPrimitive( fillPrim ); this._primArray.push( fillPrim ); this._materialNodeArray.push( fillMaterial.getMaterialNode() ); @@ -371,7 +371,7 @@ exports.Circle = Object.create(GeomObj, { var x = pts[0], y = pts[1], z = 0; var xs = scaleMat[0], ys = scaleMat[4]; - var vrts = [], nrms = [], uvs = [], indices = []; + var vrts = [], nrms = [], uvs = [], indices = []; var index = 0; for (var i=0; i