From 9fdbfe3ab750e8f6dae2ae80ebb6728a4b6c985d Mon Sep 17 00:00:00 2001 From: John Mayhew Date: Tue, 3 Apr 2012 09:40:10 -0700 Subject: updated the rdge compiled version and its runtime, incremented rdge library version number --- assets/canvas-runtime.js | 199 +++++++++++++++++++++++------------------------ 1 file changed, 98 insertions(+), 101 deletions(-) (limited to 'assets/canvas-runtime.js') diff --git a/assets/canvas-runtime.js b/assets/canvas-runtime.js index f53a4ef6..b4563ea5 100644 --- a/assets/canvas-runtime.js +++ b/assets/canvas-runtime.js @@ -19,7 +19,7 @@ function initWebGl (rootElement, directory) { cvsDataMngr = new CanvasDataManager(); //Loading data to canvas(es) cvsDataMngr.loadGLData(rootElement, ninjaWebGlData.data, directory); -} +}; /////////////////////////////////////////////////////////////////////// // Class ShapeRuntime @@ -59,7 +59,7 @@ function CanvasDataManager() } } } - } + }; this.collectGLData = function( elt, dataArray ) { @@ -78,7 +78,7 @@ function CanvasDataManager() this.collectGLData( child, dataArray ); } } - } + }; this.findCanvasWithID = function( id, elt ) { @@ -95,8 +95,8 @@ function CanvasDataManager() if (foundElt) return foundElt; } } - } -} + }; +}; /////////////////////////////////////////////////////////////////////// // Class GLRuntime @@ -149,16 +149,16 @@ function GLRuntime( canvas, jObj, assetPath ) /////////////////////////////////////////////////////////////////////// // accessors /////////////////////////////////////////////////////////////////////// - this.getZNear = function() { return this._zNear; } - this.getZFar = function() { return this._zFar; } - this.getFOV = function() { return this._fov; } - this.getAspect = function() { return this._aspect; } - this.getViewDistance = function() { return this._viewDist; } + this.getZNear = function() { return this._zNear; }; + this.getZFar = function() { return this._zFar; }; + this.getFOV = function() { return this._fov; }; + this.getAspect = function() { return this._aspect; }; + this.getViewDistance = function() { return this._viewDist; }; - this.get2DContext = function() { return this._context; } + this.get2DContext = function() { return this._context; }; - this.getViewportWidth = function() { return this._canvas.width; } - this.getViewportHeight = function() { return this._canvas.height; } + this.getViewportWidth = function() { return this._canvas.width; }; + this.getViewportHeight = function() { return this._canvas.height; }; /////////////////////////////////////////////////////////////////////// // accessors @@ -188,20 +188,20 @@ function GLRuntime( canvas, jObj, assetPath ) this.importObjects( root ); this.render(); } - } + }; this.init = function() { - var ctx1 = g_Engine.ctxMan.handleToObject(this._canvas.rdgeCtxHandle), - ctx2 = g_Engine.getContext(); + 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; // create a camera, set its perspective, and then point it at the origin - var cam = new camera(); + 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], vec3.up()); + cam.setLookAt([0, 0, this.getViewDistance()], [0, 0, 0], RDGE.vec3.up()); // make this camera the active camera this.renderer.cameraManager().setActiveCamera(cam); @@ -210,17 +210,17 @@ function GLRuntime( canvas, jObj, assetPath ) this.renderer.setClearColor([1.0, 1.0, 1.0, 0.0]); // create an empty scene graph - this.myScene = new SceneGraph(); + this.myScene = new RDGE.SceneGraph(); // load the scene graph data this.loadScene(); // Add the scene to the engine - necessary if you want the engine to draw for you var name = "myScene" + this._canvas.getAttribute( "data-RDGE-id" ); - g_Engine.AddScene(name, this.myScene); + RDGE.globals.engine.AddScene(name, this.myScene); this._initialized = true; - } + }; // main code for handling user interaction and updating the scene this.update = function(dt) @@ -233,7 +233,7 @@ function GLRuntime( canvas, jObj, assetPath ) this.elapsed += dt; // changed the global position uniform of light 0, another way to change behavior of a light - rdgeGlobalParameters.u_light0Pos.set( [5*Math.cos(this.elapsed), 5*Math.sin(this.elapsed), 20]); + RDGE.rdgeGlobalParameters.u_light0Pos.set( [5*Math.cos(this.elapsed), 5*Math.sin(this.elapsed), 20]); // orbit the light nodes around the boxes if (this.light ) 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)]); @@ -244,7 +244,7 @@ function GLRuntime( canvas, jObj, assetPath ) // now update all the nodes in the scene this.myScene.update(dt); } - } + }; this.updateMaterials = function() { @@ -254,16 +254,16 @@ function GLRuntime( canvas, jObj, assetPath ) var mat = this._materials[i]; mat.update(); } - } + }; // defining the draw function to control how the scene is rendered this.draw = function() { if (this._initialized) { - g_Engine.setContext( this._canvas.rdgeid ); + RDGE.globals.engine.setContext( this._canvas.rdgeid ); - var ctx = g_Engine.getContext(); + var ctx = RDGE.globals.engine.getContext(); var renderer = ctx.renderer; if (renderer.unloadedTextureCount <= 0) { @@ -281,7 +281,7 @@ function GLRuntime( canvas, jObj, assetPath ) } } } - } + }; this.importObjects = function( jObj, parent ) { @@ -298,7 +298,7 @@ function GLRuntime( canvas, jObj, assetPath ) this.importObjects( child, gObj ); } } - } + }; this.importObject = function( jObj, parent ) { @@ -330,7 +330,7 @@ function GLRuntime( canvas, jObj, assetPath ) this.addObject( obj, parent ); return obj; - } + }; this.addObject = function( obj, parent ) { @@ -341,7 +341,7 @@ function GLRuntime( canvas, jObj, assetPath ) this._geomRoot = obj; else parent.addChild( obj ); - } + }; this.linkLights = function() { @@ -351,7 +351,7 @@ function GLRuntime( canvas, jObj, assetPath ) this.light = matNode.lightChannel[1]; this.light2 = matNode.lightChannel[2]; } - } + }; this.linkMaterials = function( obj ) { @@ -372,7 +372,7 @@ function GLRuntime( canvas, jObj, assetPath ) this._materials.push( mat ); } } - } + }; this.initMaterials = function() { @@ -382,7 +382,7 @@ function GLRuntime( canvas, jObj, assetPath ) var mat = this._materials[i]; mat.init( this ); } - } + }; this.remapAssetFolder = function( url ) { @@ -397,7 +397,7 @@ function GLRuntime( canvas, jObj, assetPath ) // return rtnPath; return url; - } + }; this.findMaterialNode = function( nodeName, node ) { @@ -419,7 +419,7 @@ function GLRuntime( canvas, jObj, assetPath ) if (rtnNode) return rtnNode; } } - } + }; this.render = function( obj ) { @@ -436,7 +436,7 @@ function GLRuntime( canvas, jObj, assetPath ) this.render( child ); } } - } + }; // start RDGE or load Canvas 2D objects if (jObj.scenedata) this._useWebGL = true; @@ -444,14 +444,14 @@ function GLRuntime( canvas, jObj, assetPath ) { var id = canvas.getAttribute( "data-RDGE-id" ); canvas.rdgeid = id; - g_Engine.registerCanvas(canvas, this); - RDGEStart( canvas ); + RDGE.globals.engine.registerCanvas(canvas, this); + RDGE.RDGEStart( canvas ); } else { this.loadScene(); } -} +}; /////////////////////////////////////////////////////////////////////// // Class RuntimeGeomObj @@ -485,10 +485,10 @@ function RuntimeGeomObj() // Property accessors /////////////////////////////////////////////////////////////////////// - this.geomType = function() { return this.GEOM_TYPE_UNDEFINED; } + this.geomType = function() { return this.GEOM_TYPE_UNDEFINED; }; - this.setWorld = function(w) { this._world = w; } - this.getWorld = function() { return this._world; } + this.setWorld = function(w) { this._world = w; }; + this.getWorld = function() { return this._world; }; /////////////////////////////////////////////////////////////////////// // Methods @@ -497,11 +497,11 @@ function RuntimeGeomObj() { if (!this._children) this._children = []; this._children.push( child ); - } + }; this.import = function() { - } + }; this.importMaterials = function(jObj) { @@ -553,7 +553,7 @@ function RuntimeGeomObj() this._materials.push( mat ); } } - } + }; //////////////////////////////////////////////////////////////////// // vector function @@ -571,7 +571,7 @@ function RuntimeGeomObj() rtnVec[i] = a[i] + b[i]; return rtnVec; - } + }; this.vecSubtract = function( dimen, a, b ) @@ -587,7 +587,7 @@ function RuntimeGeomObj() rtnVec[i] = a[i] - b[i]; return rtnVec; - } + }; this.vecDot = function( dimen, v0, v1 ) { @@ -601,7 +601,7 @@ function RuntimeGeomObj() sum += v0[i] * v1[i]; return sum; - } + }; this.vecMag = function( dimen, vec ) { @@ -609,7 +609,7 @@ function RuntimeGeomObj() for (var i=0; i 200.0) this._time = 0.0; } } - } -} + }; +}; function RuntimeRadialGradientMaterial() { @@ -1321,7 +1319,7 @@ function RuntimeRadialGradientMaterial() if (material) { var technique = material.shaderProgram.default; - var renderer = g_Engine.getContext().renderer; + var renderer = RDGE.globals.engine.getContext().renderer; if (renderer && technique) { if (this._shader && this._shader.default) @@ -1341,7 +1339,7 @@ function RuntimeRadialGradientMaterial() } } } - } + }; this.import = function( jObj ) { @@ -1356,9 +1354,8 @@ function RuntimeRadialGradientMaterial() if (this._angle !== undefined) this._angle = jObj.angle; - } - -} + }; +}; function RuntimeLinearGradientMaterial() { @@ -1371,7 +1368,7 @@ function RuntimeLinearGradientMaterial() // the only difference between linear & radial gradient is the existance of an angle for linear. this._angle = 0.0; -} +}; function RuntimeBumpMetalMaterial() { @@ -1393,7 +1390,7 @@ function RuntimeBumpMetalMaterial() this._diffuseTexture = jObj.diffuseTexture; this._specularTexture = jObj.specularTexture; this._normalTexture = jObj.normalMap; - } + }; this.init = function( world ) { @@ -1401,7 +1398,7 @@ function RuntimeBumpMetalMaterial() if (material) { var technique = material.shaderProgram.default; - var renderer = g_Engine.getContext().renderer; + var renderer = RDGE.globals.engine.getContext().renderer; if (renderer && technique) { if (this._shader && this._shader.default) @@ -1431,8 +1428,8 @@ function RuntimeBumpMetalMaterial() } } } - } -} + }; +}; function RuntimeUberMaterial() { @@ -1448,7 +1445,7 @@ function RuntimeUberMaterial() if (material) { var technique = material.shaderProgram.defaultTechnique; - var renderer = g_Engine.getContext().renderer; + var renderer = RDGE.globals.engine.getContext().renderer; if (renderer && technique) { if (this._shader && this._shader.defaultTechnique) @@ -1493,7 +1490,7 @@ function RuntimeUberMaterial() var uvTransform = [ 2.0, 0, 0, 0, 0, 2.0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 1]; technique.u_uvMatrix.set(uvTransform); - var renderer = g_Engine.getContext().renderer; + var renderer = RDGE.globals.engine.getContext().renderer; if (this._diffuseMap) { var tex = renderer.getTextureByName(this._diffuseMap, 'REPEAT'); @@ -1522,11 +1519,11 @@ function RuntimeUberMaterial() } } } - } + }; this.update = function( time ) { - } + }; this.import = function( jObj ) { @@ -1592,8 +1589,8 @@ function RuntimeUberMaterial() this._environmentMap = jObj['environmentMap']; if (this._environmentMap) this._environmentAmount = jObj['environmentAmount']; - } -} + }; +}; function RuntimePlasmaMaterial() { @@ -1604,13 +1601,13 @@ function RuntimePlasmaMaterial() this.init = function( ) { this.update(); - } + }; this.importJSON = function( jObj ) { this._speed = jObj.speed; this._dTime = jObj.dTime; - } + }; this.update = function( time ) { @@ -1618,7 +1615,7 @@ function RuntimePlasmaMaterial() if (material) { var technique = material.shaderProgram.default; - var renderer = g_Engine.getContext().renderer; + var renderer = RDGE.globals.engine.getContext().renderer; if (renderer && technique) { if (this._shader && this._shader.default) @@ -1627,7 +1624,7 @@ function RuntimePlasmaMaterial() if (this._time > 200.0) this._time = 0.0; } } - } -} + }; +}; -- cgit v1.2.3 From d5d4dcac78ebf8ba3163a8c7055d783b6397a435 Mon Sep 17 00:00:00 2001 From: John Mayhew Date: Tue, 3 Apr 2012 12:55:54 -0700 Subject: Namespaced the canvas runtime file and updated all dependencies --- assets/canvas-runtime.js | 186 ++++++++++++++++++++++------------------------- 1 file changed, 88 insertions(+), 98 deletions(-) (limited to 'assets/canvas-runtime.js') diff --git a/assets/canvas-runtime.js b/assets/canvas-runtime.js index b4563ea5..6e9d1121 100644 --- a/assets/canvas-runtime.js +++ b/assets/canvas-runtime.js @@ -4,11 +4,12 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. */ - +// namespace for the Ninja Canvas Runtime +var NinjaCvsRt = NinjaCvsRt || {}; /////////////////////////////////////////////////////////////////////// //Loading webGL/canvas data -function initWebGl (rootElement, directory) { +NinjaCvsRt.initWebGl = function (rootElement, directory) { var cvsDataMngr, ninjaWebGlData = JSON.parse((document.querySelectorAll(['script[data-ninja-webgl]'])[0].innerHTML.replace('(', '')).replace(')', '')); if (ninjaWebGlData && ninjaWebGlData.data) { for (var n=0; ninjaWebGlData.data[n]; n++) { @@ -16,7 +17,7 @@ function initWebGl (rootElement, directory) { } } //Creating data manager - cvsDataMngr = new CanvasDataManager(); + cvsDataMngr = new NinjaCvsRt.CanvasDataManager(); //Loading data to canvas(es) cvsDataMngr.loadGLData(rootElement, ninjaWebGlData.data, directory); }; @@ -25,7 +26,7 @@ function initWebGl (rootElement, directory) { // Class ShapeRuntime // Manages runtime shape display /////////////////////////////////////////////////////////////////////// -function CanvasDataManager() +NinjaCvsRt.CanvasDataManager = function () { this.loadGLData = function(root, valueArray, assetPath ) { @@ -54,32 +55,13 @@ function CanvasDataManager() var canvas = this.findCanvasWithID( id, root ); if (canvas) { - new GLRuntime( canvas, jObj, assetPath ); + new NinjaCvsRt.GLRuntime( canvas, jObj, assetPath ); } } } } }; - this.collectGLData = function( elt, dataArray ) - { - if (elt.elementModel && elt.elementModel.shapeModel && elt.elementModel.shapeModel.GLWorld) - { - var data = elt.elementModel.shapeModel.GLWorld.export( true ); - dataArray.push( data ); - } - - if (elt.children) - { - var nKids = elt.children.length; - for (var i=0; i= 0) -// { -// rtnPath = url.substr( index + searchStr.length ); -// rtnPath = this._assetPath + rtnPath; -// } -// return rtnPath; - - return url; - }; - this.findMaterialNode = function( nodeName, node ) { if (node.transformNode) @@ -1257,7 +1247,6 @@ NinjaCvsRt.RuntimePulseMaterial = function () technique.u_resolution.set( res ); var wrap = 'REPEAT', mips = true; - this._texMap = world.remapAssetFolder( this._texMap ); var tex = renderer.getTextureByName(this._texMap, wrap, mips ); if (tex) technique.u_tex0.set( tex ); @@ -1399,19 +1388,16 @@ NinjaCvsRt.RuntimeBumpMetalMaterial = function () var wrap = 'REPEAT', mips = true; if (this._diffuseTexture) { - this._diffuseTexture = world.remapAssetFolder( this._diffuseTexture ); tex = renderer.getTextureByName(this._diffuseTexture, wrap, mips ); if (tex) technique.u_colMap.set( tex ); } if (this._normalTexture) { - this._normalTexture = world.remapAssetFolder( this._normalTexture ); tex = renderer.getTextureByName(this._normalTexture, wrap, mips ); if (tex) technique.u_normalMap.set( tex ); } if (this._specularTexture) { - this._specularTexture = world.remapAssetFolder( this._specularTexture ); tex = renderer.getTextureByName(this._specularTexture, wrap, mips ); technique.u_glowMap.set( tex ); } -- cgit v1.2.3