From 01211be8e96360dcccdc421e5cb19c7708f5dfdd Mon Sep 17 00:00:00 2001 From: Armen Kesablyan Date: Wed, 28 Mar 2012 14:37:49 -0700 Subject: Bug #1073: Panels interact with hottest drag drop Signed-off-by: Armen Kesablyan --- js/panels/drag-drop-composer.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'js') diff --git a/js/panels/drag-drop-composer.js b/js/panels/drag-drop-composer.js index b36c8334..4791bd6d 100644 --- a/js/panels/drag-drop-composer.js +++ b/js/panels/drag-drop-composer.js @@ -91,7 +91,9 @@ exports.DragDropComposer = Montage.create(Composer, { e.stopImmediatePropagation(); if (!this._dragover) { this._dragover = true; - this.component.element.classList.add("dragOver"); + if (this.component.application.ninja.componentBeingDragged) { + this.component.element.classList.add("dragOver"); + } } } }, -- cgit v1.2.3 From bff711520b7d21cfffe07c7a14fe8870243ba796 Mon Sep 17 00:00:00 2001 From: Armen Kesablyan Date: Thu, 29 Mar 2012 14:06:22 -0700 Subject: Resizing Bugs Signed-off-by: Armen Kesablyan --- js/ninja.reel/ninja.js | 53 +++++++++++++++++++++++++------------------------- js/panels/Splitter.js | 13 +++++++++++-- 2 files changed, 37 insertions(+), 29 deletions(-) (limited to 'js') diff --git a/js/ninja.reel/ninja.js b/js/ninja.reel/ninja.js index ca094936..c3e00911 100755 --- a/js/ninja.reel/ninja.js +++ b/js/ninja.reel/ninja.js @@ -24,7 +24,7 @@ exports.Ninja = Montage.create(Component, { }, _isResizing: { - value: false + value: null }, _resizedHeight : { value: 0 @@ -40,7 +40,6 @@ exports.Ninja = Montage.create(Component, { set: function(val) { if(this._height != val) { this._height = val; - this.needsDraw = true; } } @@ -60,7 +59,6 @@ exports.Ninja = Montage.create(Component, { set: function(val) { if(this._width != val) { this._width = val; - this.needsDraw = true; } } @@ -71,6 +69,8 @@ exports.Ninja = Montage.create(Component, { this.isResizing = true; this.height = parseInt(this.timeline.element.offsetHeight); this.width = parseInt(this.rightPanelContainer.offsetWidth); + this.rightPanelContainer.classList.add("disableTransition"); + this.timeline.element.classList.add("disableTransition"); this.needsDraw = true; } }, @@ -79,7 +79,6 @@ exports.Ninja = Montage.create(Component, { value:function(e) { this._resizedHeight = e._event.dY; this._resizedWidth = e._event.dX; - console.log("resizing"); this.stage.resizeCanvases = true; this.needsDraw = true; } @@ -87,13 +86,17 @@ exports.Ninja = Montage.create(Component, { handleResizeEnd: { value: function(e) { - this.height -= this._resizedHeight; - this.width -= this._resizedWidth; +// this.height -= this._resizedHeight; +// this.width -= this._resizedWidth; this.stage.resizeCanvases = true; this._resizedHeight = 0; this._resizedWidth = 0; this.isResizing = false; this.needsDraw = true; + this.rightPanelContainer.classList.remove("disableTransition"); + this.timeline.element.classList.remove("disableTransition"); + this.height = this.timeline.element.offsetHeight; + this.width = this.rightPanelContainer.offsetWidth; } }, @@ -106,6 +109,7 @@ exports.Ninja = Montage.create(Component, { this.needsDraw = true; this.timelineSplitter.collapsed = false; this.panelSplitter.collapsed = false; + this.stage.resizeCanvases = true; } }, @@ -167,30 +171,28 @@ exports.Ninja = Montage.create(Component, { willDraw: { value: function() { - if (this.height === null) { - this.height = parseInt(this.timeline.element.offsetHeight); - } - if (this.width === null) { - this.width = parseInt(this.rightPanelContainer.offsetWidth); - } + } }, draw: { value: function() { - if (this.height - this._resizedHeight < 46) { - this.timelineSplitter.collapsed = true; - } else { - this.timelineSplitter.collapsed = false; - } - if (this.width - this._resizedWidth < 30) { - this.panelSplitter.collapsed = true; - } else { - this.panelSplitter.collapsed = false; + if(this.isResizing) { + if (this.height - this._resizedHeight < 46) { + this.timelineSplitter.collapsed = true; + } else { + this.timelineSplitter.collapsed = false; + } + this.timeline.element.style.height = (this.height - this._resizedHeight) + "px"; + + if (this.width - this._resizedWidth < 30) { + this.panelSplitter.collapsed = true; + } else { + this.panelSplitter.collapsed = false; + } + this.rightPanelContainer.style.width = (this.width - this._resizedWidth) + "px"; } - this.timeline.element.style.height = (this.height - this._resizedHeight) + "px"; - this.rightPanelContainer.style.width = (this.width - this._resizedWidth) + "px"; } }, @@ -200,10 +202,7 @@ exports.Ninja = Montage.create(Component, { didDraw: { value: function() { - if (!this.isResizing) { - this.height = this.timeline.element.offsetHeight; - this.width = this.rightPanelContainer.offsetWidth; - } + if(!this._didDraw) { if (!this.application.ninja.coreIoApi.ioServiceDetected) { var check = this.application.ninja.coreIoApi.cloudAvailable(); diff --git a/js/panels/Splitter.js b/js/panels/Splitter.js index 6791e0d5..ac45b4ba 100755 --- a/js/panels/Splitter.js +++ b/js/panels/Splitter.js @@ -94,7 +94,11 @@ exports.Splitter = Montage.create(Component, { handleClick : { value: function() { if (!this.disabled) { - this.panel.addEventListener("webkitTransitionEnd", this, false); + if(this.panel.element) { + this.panel.element.addEventListener("webkitTransitionEnd", this, false); + } else { + this.panel.addEventListener("webkitTransitionEnd", this, false); + } this.collapsed = !this.collapsed; this.needsDraw = true; } @@ -103,7 +107,12 @@ exports.Splitter = Montage.create(Component, { handleWebkitTransitionEnd: { value: function() { - this.panel.removeEventListener("webkitTransitionEnd", this, false); + if(this.panel.element) { + this.panel.element.removeEventListener("webkitTransitionEnd", this, false); + } else { + this.panel.removeEventListener("webkitTransitionEnd", this, false); + } + this.application.ninja.stage.resizeCanvases = true; } }, -- cgit v1.2.3 From e6299d0965d669cd296de1b2ffc1b30734ead43b Mon Sep 17 00:00:00 2001 From: Armen Kesablyan Date: Thu, 29 Mar 2012 15:58:36 -0700 Subject: Bug Fix: Height and width of panels not be kept Signed-off-by: Armen Kesablyan --- js/ninja.reel/ninja.js | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) (limited to 'js') diff --git a/js/ninja.reel/ninja.js b/js/ninja.reel/ninja.js index c3e00911..068a44bc 100755 --- a/js/ninja.reel/ninja.js +++ b/js/ninja.reel/ninja.js @@ -35,11 +35,19 @@ exports.Ninja = Montage.create(Component, { height: { get: function() { + if(this._height === null) { + var storedData = this.application.localStorage.getItem("timelinePanel"); + if(storedData && storedData.value) { + this._height = storedData.value; + } + } return this._height; }, set: function(val) { if(this._height != val) { this._height = val; + this.application.localStorage.setItem("timelinePanel", {"version": this.version, "value": val}); + this.needsDraw = true; } } @@ -54,11 +62,19 @@ exports.Ninja = Montage.create(Component, { width: { get: function() { + if(this._width === null) { + var storedData = this.application.localStorage.getItem("rightPanelsContainer"); + if(storedData && storedData.value) { + this._width = storedData.value; + } + } return this._width; }, set: function(val) { if(this._width != val) { this._width = val; + this.application.localStorage.setItem("rightPanelsContainer", {"version": this.version, "value": val}); + this.needsDraw = true; } } @@ -106,10 +122,10 @@ exports.Ninja = Montage.create(Component, { this.height = 140; this._resizedHeight = 0; this._resizedWidth = 0; - this.needsDraw = true; this.timelineSplitter.collapsed = false; this.panelSplitter.collapsed = false; this.stage.resizeCanvases = true; + this.needsDraw = true; } }, @@ -183,16 +199,16 @@ exports.Ninja = Montage.create(Component, { } else { this.timelineSplitter.collapsed = false; } - this.timeline.element.style.height = (this.height - this._resizedHeight) + "px"; if (this.width - this._resizedWidth < 30) { this.panelSplitter.collapsed = true; } else { this.panelSplitter.collapsed = false; } - this.rightPanelContainer.style.width = (this.width - this._resizedWidth) + "px"; - } + } + this.rightPanelContainer.style.width = (this.width - this._resizedWidth) + "px"; + this.timeline.element.style.height = (this.height - this._resizedHeight) + "px"; } }, -- cgit v1.2.3 From 7aefa059c79c9bef5c7a8a93cdfbd1ce55f69118 Mon Sep 17 00:00:00 2001 From: Eric Guzman Date: Thu, 29 Mar 2012 16:28:34 -0700 Subject: Presets - Remove style transition when transition doesn't start. Also added temporary fix for aggregating animations (from timeline/presets) --- js/controllers/presets-controller.js | 76 +++++++++++++++++--------- js/panels/presets/default-animation-presets.js | 4 +- 2 files changed, 54 insertions(+), 26 deletions(-) (limited to 'js') diff --git a/js/controllers/presets-controller.js b/js/controllers/presets-controller.js index 7152ba93..e436023a 100644 --- a/js/controllers/presets-controller.js +++ b/js/controllers/presets-controller.js @@ -20,14 +20,39 @@ exports.PresetsController = Montage.create(Component, { addTransition: { value: function(element) { + var transitionDuration; + element.classList.add(this.transitionClass); element.addEventListener("webkitTransitionEnd", this, true); + + + //// TODO: replace this hack when webkit supports transitionStart event + transitionDuration = this.application.ninja.stylesController.getElementStyle(element, '-webkit-transition-duration', true); + element.njTimeout = window.setTimeout(function() { + this.captureWebkitTransitionEnd({ + 'target': element + }); + }.bind(this), this._getMilliseconds(transitionDuration) + 100); + } + }, + + _getMilliseconds : { + value: function(duration) { + if(duration.indexOf('ms') !== -1) { + return parseInt(duration); + } else { + return parseFloat(duration)*1000; + } } }, captureWebkitTransitionEnd : { value : function(e) { var el = e.target; + + //// TODO: replace this hack when webkit supports transitionStart event (see above) + window.clearTimeout(el.njTimeout); + el.classList.remove(this.transitionClass); el.removeEventListener("webkitTransitionEnd", this, true); } @@ -41,30 +66,25 @@ exports.PresetsController = Montage.create(Component, { var stylesController = this.application.ninja.stylesController, selectorBase = presetData.selectorBase, - rules = []; + rules = [], + animationNames = []; selectorBase = stylesController.generateClassName(selectorBase); - presetData.rules.forEach(function(rule, i) { - ///// Treat keyframed rules differently - if(rule.isKeyFrameRule) { - this.application.ninja.stylesController.addRule( - '@-webkit-keyframes ' + presetData.selectorBase, - this.stringifyKeys(rule.keys) - ); - } else { - var suffix = rule.selectorSuffix || ''; - rules.push(stylesController.addRule('.'+selectorBase + suffix, rule.styles)); - } - }, this); - selection.forEach(function(element) { - var el = element._element; + var el = element._element, + animationName; if(useTransition) { this.addTransition(el); } + ///// TODO: remove when we find out what to do with competing animations + animationName = stylesController.getElementStyle(el, '-webkit-animation-name'); + if(animationName) { + animationNames.push(animationName); + } + el.classList.add(selectorBase); //// Keep track of elements with presets and don't add duplicates @@ -72,20 +92,26 @@ exports.PresetsController = Montage.create(Component, { }, this); - } - }, - - setCachedPreset : { - value: function(el, presetId, rules) { + presetData.rules.forEach(function(rule, i) { + ///// Treat keyframed rules differently + if(rule.isKeyFrameRule) { + this.application.ninja.stylesController.addRule( + '@-webkit-keyframes ' + presetData.selectorBase, + this.stringifyKeys(rule.keys) + ); + } else { + var suffix = rule.selectorSuffix || ''; - } - }, + ///// TODO: remove when we find out what to do with competing animations + if(rule.styles['-webkit-animation-name']) { + rule.styles['-webkit-animation-name'] += ',' + animationNames.join(','); + } - getPresets : { - value: function(element) { + rules.push(stylesController.addRule('.'+selectorBase + suffix, rule.styles)); + } + }, this); } - }, stringifyKeys : { diff --git a/js/panels/presets/default-animation-presets.js b/js/panels/presets/default-animation-presets.js index b12a94b2..578c1622 100644 --- a/js/panels/presets/default-animation-presets.js +++ b/js/panels/presets/default-animation-presets.js @@ -14,7 +14,9 @@ exports.animationPresets = { "selectorBase" : "border-morph", "rules" : [{ "styles" : { - "-webkit-animation": "border-morph 2s infinite" + "-webkit-animation-name": "border-morph", + "-webkit-animation-duration": "2s", + "-webkit-animation-iteration-count": "infinite" } }, { -- cgit v1.2.3 From 0491907d1cba1534d88c49f2bb4035484831bbe5 Mon Sep 17 00:00:00 2001 From: Eric Guzman Date: Fri, 30 Mar 2012 09:43:48 -0700 Subject: Presets Controller - Remove unused method call --- js/controllers/presets-controller.js | 3 --- 1 file changed, 3 deletions(-) (limited to 'js') diff --git a/js/controllers/presets-controller.js b/js/controllers/presets-controller.js index e436023a..9d898a53 100644 --- a/js/controllers/presets-controller.js +++ b/js/controllers/presets-controller.js @@ -87,9 +87,6 @@ exports.PresetsController = Montage.create(Component, { el.classList.add(selectorBase); - //// Keep track of elements with presets and don't add duplicates - this.setCachedPreset(el, presetData.id, rules); - }, this); presetData.rules.forEach(function(rule, i) { -- cgit v1.2.3 From fb0a659c9ca3479fd6799325498b11f074689936 Mon Sep 17 00:00:00 2001 From: John Mayhew Date: Mon, 2 Apr 2012 14:57:31 -0700 Subject: -Namespaced all RDGE javascript. -Removed the following unused files from the build script /core/script/fx/blur.js /core/script/fx/ssao.js /core/script/animation.js - Fully removed the following from the build and from source control as they are unused or no longer needed /core/script/util/dbgpanel.js /core/script/util/fpsTracker.js /core/script/util/statTracker.js /core/script/input.js /core/script/TextureManager.js /core/script/ubershader.js --- js/helper-classes/RDGE/runtime/GLRuntime.js | 26 +- .../RDGE/src/core/script/MeshManager.js | 255 +-- .../RDGE/src/core/script/RenderInitProcs.js | 476 ++-- .../RDGE/src/core/script/RenderProcs.js | 787 ++++--- .../RDGE/src/core/script/ScreenQuad.js | 32 +- .../RDGE/src/core/script/ShaderManager.js | 124 +- .../RDGE/src/core/script/TextureManager.js | 6 - .../RDGE/src/core/script/animation.js | 191 +- js/helper-classes/RDGE/src/core/script/box.js | 181 +- js/helper-classes/RDGE/src/core/script/camera.js | 468 ++-- js/helper-classes/RDGE/src/core/script/engine.js | 513 ++--- js/helper-classes/RDGE/src/core/script/fx/blur.js | 283 ++- js/helper-classes/RDGE/src/core/script/fx/ssao.js | 211 +- .../RDGE/src/core/script/init_state.js | 553 +++-- js/helper-classes/RDGE/src/core/script/input.js | 117 - js/helper-classes/RDGE/src/core/script/jpass.js | 771 +++---- js/helper-classes/RDGE/src/core/script/jshader.js | 260 ++- .../RDGE/src/core/script/lightmanager.js | 148 +- .../RDGE/src/core/script/math/mat4.js | 1055 +++++---- .../RDGE/src/core/script/math/quat.js | 237 +- .../RDGE/src/core/script/math/vec2.js | 229 +- .../RDGE/src/core/script/math/vec3.js | 423 ++-- .../RDGE/src/core/script/math/vec4.js | 315 +-- .../RDGE/src/core/script/objectManager.js | 8 +- js/helper-classes/RDGE/src/core/script/particle.js | 1591 +++++++------- .../RDGE/src/core/script/precompiled.js | 123 +- .../RDGE/src/core/script/renderUtils.js | 644 +++--- .../RDGE/src/core/script/rendercontext.js | 454 ++-- js/helper-classes/RDGE/src/core/script/renderer.js | 2299 ++++++++++---------- .../RDGE/src/core/script/run_state.js | 711 +++--- js/helper-classes/RDGE/src/core/script/runtime.js | 280 +-- .../RDGE/src/core/script/scenegraph.js | 1754 +++++++-------- .../RDGE/src/core/script/scenegraphNodes.js | 1016 ++++----- .../RDGE/src/core/script/shadowLight.js | 90 +- js/helper-classes/RDGE/src/core/script/sockets.js | 243 +-- .../RDGE/src/core/script/ubershader.js | 159 -- .../RDGE/src/core/script/util/dbgpanel.js | 237 -- .../RDGE/src/core/script/util/fpsTracker.js | 51 - .../RDGE/src/core/script/util/statTracker.js | 338 --- .../RDGE/src/core/script/utilities.js | 282 ++- .../RDGE/src/tools/compile-rdge-core.bat | 2 +- .../RDGE/src/tools/compile-rdge-core.sh | 2 +- js/lib/drawing/world.js | 58 +- js/lib/geom/circle.js | 6 +- js/lib/geom/line.js | 4 +- js/lib/geom/rectangle.js | 8 +- js/lib/geom/shape-primitive.js | 4 +- js/lib/rdge/materials/bump-metal-material.js | 6 +- js/lib/rdge/materials/deform-material.js | 4 +- js/lib/rdge/materials/flat-material.js | 4 +- js/lib/rdge/materials/fly-material.js | 4 +- js/lib/rdge/materials/julia-material.js | 6 +- js/lib/rdge/materials/keleidoscope-material.js | 6 +- js/lib/rdge/materials/linear-gradient-material.js | 4 +- js/lib/rdge/materials/mandel-material.js | 6 +- js/lib/rdge/materials/plasma-material.js | 4 +- js/lib/rdge/materials/pulse-material.js | 10 +- js/lib/rdge/materials/radial-blur-material.js | 10 +- js/lib/rdge/materials/radial-gradient-material.js | 4 +- js/lib/rdge/materials/relief-tunnel-material.js | 4 +- js/lib/rdge/materials/square-tunnel-material.js | 4 +- js/lib/rdge/materials/star-material.js | 4 +- js/lib/rdge/materials/taper-material.js | 4 +- js/lib/rdge/materials/tunnel-material.js | 4 +- js/lib/rdge/materials/twist-material.js | 6 +- js/lib/rdge/materials/twist-vert-material.js | 6 +- js/lib/rdge/materials/uber-material.js | 16 +- js/lib/rdge/materials/water-material.js | 4 +- js/lib/rdge/materials/z-invert-material.js | 6 +- js/preloader/Preloader.js | 8 - 70 files changed, 8193 insertions(+), 9966 deletions(-) delete mode 100755 js/helper-classes/RDGE/src/core/script/TextureManager.js delete mode 100755 js/helper-classes/RDGE/src/core/script/input.js delete mode 100755 js/helper-classes/RDGE/src/core/script/ubershader.js delete mode 100755 js/helper-classes/RDGE/src/core/script/util/dbgpanel.js delete mode 100755 js/helper-classes/RDGE/src/core/script/util/fpsTracker.js delete mode 100755 js/helper-classes/RDGE/src/core/script/util/statTracker.js (limited to 'js') diff --git a/js/helper-classes/RDGE/runtime/GLRuntime.js b/js/helper-classes/RDGE/runtime/GLRuntime.js index 5c99be02..80162f91 100644 --- a/js/helper-classes/RDGE/runtime/GLRuntime.js +++ b/js/helper-classes/RDGE/runtime/GLRuntime.js @@ -31,8 +31,8 @@ function GLRuntime( canvas, importStr ) /////////////////////////////////////////////////////////////////////// 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 ); this.loadScene = function() { @@ -53,16 +53,16 @@ function GLRuntime( canvas, importStr ) 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); @@ -77,17 +77,17 @@ function GLRuntime( canvas, importStr ) /* // create some lights // light 1 - this.light = createLightNode("myLight"); + 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 = createLightNode("myLight2"); + 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 = createTransformNode("lightTr"); + var lightTr = RDGE.createTransformNode("lightTr"); // create and attach a material - materials hold the light data lightTr.attachMaterial(createMaterialNode("lights")); @@ -107,7 +107,7 @@ function GLRuntime( canvas, importStr ) // 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); } // main code for handling user interaction and updating the scene @@ -119,7 +119,7 @@ function GLRuntime( canvas, importStr ) 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 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)]); @@ -132,9 +132,9 @@ function GLRuntime( canvas, importStr ) // defining the draw function to control how the scene is rendered this.draw = function() { - 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) { diff --git a/js/helper-classes/RDGE/src/core/script/MeshManager.js b/js/helper-classes/RDGE/src/core/script/MeshManager.js index 43813078..2c31781e 100755 --- a/js/helper-classes/RDGE/src/core/script/MeshManager.js +++ b/js/helper-classes/RDGE/src/core/script/MeshManager.js @@ -4,86 +4,80 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. */ -function Model(name, mesh) -{ +// RDGE namespaces +var RDGE = RDGE || {}; + +RDGE.Model = function (name, mesh) { this.name = name; this.mesh = mesh; this.camera = null; -} +}; /* - * Maintains a list of meshes to allow instancing of data - */ -function MeshManager() { - this.contentUrl = "assets_web/mesh/"; - this.modelMap = {}; - this.readyList = []; // meshes that have data ready - this.meshesLoading = true; // indicates that no meshes have loaded or that they are still loading - this.postMeshLoadCallbackList = []; - this.tempSphere = null; - this.requestCounter = 0; -} +* Maintains a list of meshes to allow instancing of data +*/ +RDGE.MeshManager = function () { + this.contentUrl = "assets_web/mesh/"; + this.modelMap = {}; + this.readyList = []; // meshes that have data ready + this.meshesLoading = true; // indicates that no meshes have loaded or that they are still loading + this.postMeshLoadCallbackList = []; + this.tempSphere = null; + this.requestCounter = 0; +}; /* - * Pass the scene meshNode stump, loads temp object while real mesh is downloading - */ -MeshManager.prototype.loadMesh = function (meshStump, tempMesh) -{ +* Pass the scene meshNode stump, loads temp object while real mesh is downloading +*/ +RDGE.MeshManager.prototype.loadMesh = function (meshStump, tempMesh) { // if it exists already, return the mesh requested - if ( this.modelMap[meshStump.name] !== undefined ) + if (this.modelMap[meshStump.name] !== undefined) return this.modelMap[meshStump.name]; meshStump.ready = false; meshStump.addr = this.contentUrl + meshStump.name + "_mesh.json"; - meshStump.ctxID = g_Engine.getContext().renderer.id; - - // sets a temp mesh up in place of the final mesh to load - if (!tempMesh) - { - if (this.tempSphere == null) - { - this.tempSphere = makeSphere(g_Engine.getContext().renderer.ctx, 25, 5, 5); + meshStump.ctxID = RDGE.globals.engine.getContext().renderer.id; + + // sets a temp mesh up in place of the final mesh to load + if (!tempMesh) { + if (this.tempSphere == null) { + this.tempSphere = RDGE.renderUtils.makeSphere(RDGE.globals.engine.getContext().renderer.ctx, 25, 5, 5); } tempMesh = this.tempSphere; } - // add the temp mesh to the map of loaded meshes + // add the temp mesh to the map of loaded meshes this.modelMap[meshStump.name] = tempMesh; - + // update the request counter - we now have one more mesh to load this.requestCounter++; - requestMesh(meshStump); + RDGE.requestMesh(meshStump); return null; }; /* - * Deletes the passed mesh from the manager as well as all renderers - */ -MeshManager.prototype.deleteMesh = function (name) -{ - var model = this.modelMap[name]; - - if (model) - { - g_Engine.ctxMan.forEach(function(context) - { - context.renderer.deletePrimitive(model.primitive); - }); - - delete this.modelMap[name]; - } +* Deletes the passed mesh from the manager as well as all renderers +*/ +RDGE.MeshManager.prototype.deleteMesh = function (name) { + var model = this.modelMap[name]; + + if (model) { + RDGE.globals.engine.ctxMan.forEach(function (context) { + context.renderer.deletePrimitive(model.primitive); + }); + + delete this.modelMap[name]; + } }; -MeshManager.prototype.getModelByName = function (name) -{ +RDGE.MeshManager.prototype.getModelByName = function (name) { return this.modelMap[name]; }; -MeshManager.prototype.getModelNames = function () -{ +RDGE.MeshManager.prototype.getModelNames = function () { var names = []; for (var index in this.modelMap) { names.push(this.modelList[index].name); @@ -93,134 +87,121 @@ MeshManager.prototype.getModelNames = function () }; -MeshManager.prototype.processMeshData = function () { - var renderer = g_Engine.getContext().renderer; - +RDGE.MeshManager.prototype.processMeshData = function () { + var renderer = RDGE.globals.engine.getContext().renderer; + // loop through meshes and load ready data for (var index in this.readyList) { // if item is ready load it if (this.readyList[index] && this.readyList[index].ready && renderer.id === this.readyList[index].ctxID) { - + // pop the item var model = this.readyList[index]; this.readyList.splice(index, 1); - - var primset = new rdgePrimitiveDefinition(); - - primset.vertexDefinition = + + var primset = new RDGE.rdgePrimitiveDefinition(); + + primset.vertexDefinition = { - // this shows two ways to map this data to an attribute - "vert":{'type':rdgeConstants.VS_ELEMENT_POS, 'bufferIndex':0, 'bufferUsage': rdgeConstants.BUFFER_STATIC}, - "a_pos":{'type':rdgeConstants.VS_ELEMENT_POS, 'bufferIndex':0, 'bufferUsage': rdgeConstants.BUFFER_STATIC}, - "normal":{'type':rdgeConstants.VS_ELEMENT_FLOAT3, 'bufferIndex':1, 'bufferUsage': rdgeConstants.BUFFER_STATIC}, - "a_norm":{'type':rdgeConstants.VS_ELEMENT_FLOAT3, 'bufferIndex':1, 'bufferUsage': rdgeConstants.BUFFER_STATIC}, - "a_normal":{'type':rdgeConstants.VS_ELEMENT_FLOAT3, 'bufferIndex':1, 'bufferUsage': rdgeConstants.BUFFER_STATIC}, - "texcoord":{'type':rdgeConstants.VS_ELEMENT_FLOAT2, 'bufferIndex':2, 'bufferUsage': rdgeConstants.BUFFER_STATIC}, - "a_texcoord":{'type':rdgeConstants.VS_ELEMENT_FLOAT2, 'bufferIndex':2, 'bufferUsage': rdgeConstants.BUFFER_STATIC}, - "a_texcoords":{'type':rdgeConstants.VS_ELEMENT_FLOAT2, 'bufferIndex':2, 'bufferUsage': rdgeConstants.BUFFER_STATIC}, - "a_uv":{'type':rdgeConstants.VS_ELEMENT_FLOAT2, 'bufferIndex':2, 'bufferUsage': rdgeConstants.BUFFER_STATIC} + // this shows two ways to map this data to an attribute + "vert": { 'type': RDGE.rdgeConstants.VS_ELEMENT_POS, 'bufferIndex': 0, 'bufferUsage': RDGE.rdgeConstants.BUFFER_STATIC }, + "a_pos": { 'type': RDGE.rdgeConstants.VS_ELEMENT_POS, 'bufferIndex': 0, 'bufferUsage': RDGE.rdgeConstants.BUFFER_STATIC }, + "normal": { 'type': RDGE.rdgeConstants.VS_ELEMENT_FLOAT3, 'bufferIndex': 1, 'bufferUsage': RDGE.rdgeConstants.BUFFER_STATIC }, + "a_norm": { 'type': RDGE.rdgeConstants.VS_ELEMENT_FLOAT3, 'bufferIndex': 1, 'bufferUsage': RDGE.rdgeConstants.BUFFER_STATIC }, + "a_normal": { 'type': RDGE.rdgeConstants.VS_ELEMENT_FLOAT3, 'bufferIndex': 1, 'bufferUsage': RDGE.rdgeConstants.BUFFER_STATIC }, + "texcoord": { 'type': RDGE.rdgeConstants.VS_ELEMENT_FLOAT2, 'bufferIndex': 2, 'bufferUsage': RDGE.rdgeConstants.BUFFER_STATIC }, + "a_texcoord": { 'type': RDGE.rdgeConstants.VS_ELEMENT_FLOAT2, 'bufferIndex': 2, 'bufferUsage': RDGE.rdgeConstants.BUFFER_STATIC }, + "a_texcoords": { 'type': RDGE.rdgeConstants.VS_ELEMENT_FLOAT2, 'bufferIndex': 2, 'bufferUsage': RDGE.rdgeConstants.BUFFER_STATIC }, + "a_uv": { 'type': RDGE.rdgeConstants.VS_ELEMENT_FLOAT2, 'bufferIndex': 2, 'bufferUsage': RDGE.rdgeConstants.BUFFER_STATIC } }; - - primset.bufferStreams = + + primset.bufferStreams = [ model.root.data.coords, model.root.data.normals, model.root.data.uvs ]; - - primset.streamUsage = + + primset.streamUsage = [ - rdgeConstants.BUFFER_STATIC, - rdgeConstants.BUFFER_STATIC, - rdgeConstants.BUFFER_STATIC + RDGE.rdgeConstants.BUFFER_STATIC, + RDGE.rdgeConstants.BUFFER_STATIC, + RDGE.rdgeConstants.BUFFER_STATIC ]; - - primset.indexUsage = rdgeConstants.BUFFER_STREAM; - + + primset.indexUsage = RDGE.rdgeConstants.BUFFER_STREAM; + primset.indexBuffer = model.root.data.indices; - renderer.createPrimitive( primset ); - - model.root.primitive = primset; + renderer.createPrimitive(primset); + + model.root.primitive = primset; // generate a bounding box for this mesh - model.root.bbox = new box(); + model.root.bbox = new RDGE.box(); var numCoords = model.root.data.coords.length; var idx = 0; - while (idx < numCoords - 2) - { - var thisCoord = [model.root.data.coords[idx+0], model.root.data.coords[idx+1], model.root.data.coords[idx+2]]; - model.root.bbox.addVec3(thisCoord); - idx += 3; + while (idx < numCoords - 2) { + var thisCoord = [model.root.data.coords[idx + 0], model.root.data.coords[idx + 1], model.root.data.coords[idx + 2]]; + model.root.bbox.addVec3(thisCoord); + idx += 3; } this.modelMap[model.root.attribs.name] = model.root; - + // now that the model is load reduce the request count this.requestCounter--; - + this.onLoaded(model.root.attribs.name); //break; } } -} +}; -MeshManager.prototype.isReady = function() -{ - return this.readyList.length == 0; -} +RDGE.MeshManager.prototype.isReady = function () { + return this.readyList.length == 0; +}; -MeshManager.prototype.addOnLoadedCallback = function (callback) -{ +RDGE.MeshManager.prototype.addOnLoadedCallback = function (callback) { this.postMeshLoadCallbackList.push(callback) -} +}; -MeshManager.prototype.onLoaded = function ( meshName ) -{ - for (var index = 0 in this.postMeshLoadCallbackList) - { +RDGE.MeshManager.prototype.onLoaded = function (meshName) { + for (var index = 0 in this.postMeshLoadCallbackList) { // call the functions this.postMeshLoadCallbackList[index].onMeshLoaded(meshName); } -} - -MeshManager.prototype.exportJSON = function () -{ - for(var m in this.modelMap) - { - this.modelMap[m].primitive.built = false; - } - - return JSON.stringify(this.modelMap); -} - -MeshManager.prototype.importJSON = function ( jsonMeshExport ) -{ - try - { - var tempModelMap = JSON.parse(jsonMeshExport); - - for(var m in tempModelMap) - { - if(!this.modelMap[m]) - { - this.modelMap[m] = tempModelMap[m]; - } - } - window.console.log("meshes imported"); - }catch( e ) - { - window.console.error("error importing meshes: " + e.description ); - } -} +}; + +RDGE.MeshManager.prototype.exportJSON = function () { + for (var m in this.modelMap) { + this.modelMap[m].primitive.built = false; + } + + return JSON.stringify(this.modelMap); +}; + +RDGE.MeshManager.prototype.importJSON = function (jsonMeshExport) { + try { + var tempModelMap = JSON.parse(jsonMeshExport); + + for (var m in tempModelMap) { + if (!this.modelMap[m]) { + this.modelMap[m] = tempModelMap[m]; + } + } + window.console.log("meshes imported"); + } catch (e) { + window.console.error("error importing meshes: " + e.description); + } +}; /* - * global function for the mesh manager to make mesh file requests - */ -function requestMesh(mesh) -{ +* global function for the mesh manager to make mesh file requests +*/ +RDGE.requestMesh = function (mesh) { var request = new XMLHttpRequest(); request.mesh = mesh; request.onreadystatechange = function () { @@ -229,7 +210,7 @@ function requestMesh(mesh) var mesh = eval("(" + request.responseText + ")"); //retrieve result as an JavaScript object mesh.ready = true; mesh.ctxID = request.mesh.ctxID; - g_meshMan.readyList.push(mesh); + RDGE.globals.meshMan.readyList.push(mesh); } else { alert("An error has occured making the request"); @@ -239,4 +220,4 @@ function requestMesh(mesh) request.open("GET", mesh.addr, true); request.send(null); -} +}; diff --git a/js/helper-classes/RDGE/src/core/script/RenderInitProcs.js b/js/helper-classes/RDGE/src/core/script/RenderInitProcs.js index 9d4e0d63..4e80183e 100755 --- a/js/helper-classes/RDGE/src/core/script/RenderInitProcs.js +++ b/js/helper-classes/RDGE/src/core/script/RenderInitProcs.js @@ -4,260 +4,232 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. */ -renderInitProcDefault = __renderInitProcDefault; -renderInitScreenQuad = __renderInitScreenQuad; -renderInitProcDepthMap = __renderInitProcDepthMap; -renderInitShadowReceiver= __renderInitShadowReceiver; -renderInitShadowProjection = __renderInitShadowProjection; - -function __renderInitProcDefault(primSet, vertexData) -{ - var material = primSet.material; - - //push envMap tex - material.tex.env.push(arrayPeek(material.shader).envMap); - material.tex.envDiff.push(arrayPeek(material.shader).envDiff); - - gl.useProgram(arrayPeek(material.shader).shaderHandle); - - arrayPeek(material.renderObj).addTexture("layerMap1", 0, UNIFORMTYPE.TEXTURE2D); - arrayPeek(material.renderObj).addTexture("layerMap2", 1, UNIFORMTYPE.TEXTURE2D); - arrayPeek(material.renderObj).addTexture("colorMeMap1", 2, UNIFORMTYPE.TEXTURE2D); - arrayPeek(material.renderObj).addTexture("colorMeMap2", 3, UNIFORMTYPE.TEXTURE2D); - arrayPeek(material.renderObj).addTexture("envMap", 4, UNIFORMTYPE.TEXTURE2D); - arrayPeek(material.renderObj).addTexture("envDiff", 5, UNIFORMTYPE.TEXTURE2D); - - arrayPeek(material.renderObj).addTexture("normalMap1", 15, UNIFORMTYPE.TEXTURE2D); - arrayPeek(material.renderObj).addTexture("normalMap2", 6, UNIFORMTYPE.TEXTURE2D); - - arrayPeek(material.renderObj).addTexture("stickerMap0", 7, UNIFORMTYPE.TEXTURE2D); - arrayPeek(material.renderObj).addTexture("stickerMap1", 8, UNIFORMTYPE.TEXTURE2D); - arrayPeek(material.renderObj).addTexture("stickerMap2", 9, UNIFORMTYPE.TEXTURE2D); - arrayPeek(material.renderObj).addTexture("stickerMap3", 10, UNIFORMTYPE.TEXTURE2D); - arrayPeek(material.renderObj).addTexture("stickerMap4", 11, UNIFORMTYPE.TEXTURE2D); - arrayPeek(material.renderObj).addTexture("stickerMap5", 12, UNIFORMTYPE.TEXTURE2D); - arrayPeek(material.renderObj).addTexture("stickerMap6", 13, UNIFORMTYPE.TEXTURE2D); - arrayPeek(material.renderObj).addTexture("stickerMap7", 14, UNIFORMTYPE.TEXTURE2D); - - arrayPeek(material.renderObj).addUniform("u_normalMatrix", gl.normalMatrix, UNIFORMTYPE.MATRIX4); - arrayPeek(material.renderObj).addUniform("u_mvMatrix", gl.mvMatrix, UNIFORMTYPE.MATRIX4); - arrayPeek(material.renderObj).addUniform("u_invMvMatrix", gl.invMvMatrix, UNIFORMTYPE.MATRIX4); - - arrayPeek(material.renderObj).addUniform("u_stickerMatrix0", primSet.parentMesh.stickers[0], UNIFORMTYPE.MATRIX4); - arrayPeek(material.renderObj).addUniform("u_stickerMatrix1", primSet.parentMesh.stickers[1], UNIFORMTYPE.MATRIX4); - arrayPeek(material.renderObj).addUniform("u_stickerMatrix2", primSet.parentMesh.stickers[2], UNIFORMTYPE.MATRIX4); - arrayPeek(material.renderObj).addUniform("u_stickerMatrix3", primSet.parentMesh.stickers[3], UNIFORMTYPE.MATRIX4); - arrayPeek(material.renderObj).addUniform("u_stickerMatrix4", primSet.parentMesh.stickers[4], UNIFORMTYPE.MATRIX4); - arrayPeek(material.renderObj).addUniform("u_stickerMatrix5", primSet.parentMesh.stickers[5], UNIFORMTYPE.MATRIX4); - arrayPeek(material.renderObj).addUniform("u_stickerMatrix6", primSet.parentMesh.stickers[6], UNIFORMTYPE.MATRIX4); - arrayPeek(material.renderObj).addUniform("u_stickerMatrix7", primSet.parentMesh.stickers[7], UNIFORMTYPE.MATRIX4); - - arrayPeek(material.renderObj).addUniform("u_stickerPos0", primSet.parentMesh.stickersPos[0], UNIFORMTYPE.FLOAT3); - arrayPeek(material.renderObj).addUniform("u_stickerPos1", primSet.parentMesh.stickersPos[1], UNIFORMTYPE.FLOAT3); - arrayPeek(material.renderObj).addUniform("u_stickerPos2", primSet.parentMesh.stickersPos[2], UNIFORMTYPE.FLOAT3); - arrayPeek(material.renderObj).addUniform("u_stickerPos3", primSet.parentMesh.stickersPos[3], UNIFORMTYPE.FLOAT3); - arrayPeek(material.renderObj).addUniform("u_stickerPos4", primSet.parentMesh.stickersPos[4], UNIFORMTYPE.FLOAT3); - arrayPeek(material.renderObj).addUniform("u_stickerPos5", primSet.parentMesh.stickersPos[5], UNIFORMTYPE.FLOAT3); - arrayPeek(material.renderObj).addUniform("u_stickerPos6", primSet.parentMesh.stickersPos[6], UNIFORMTYPE.FLOAT3); - arrayPeek(material.renderObj).addUniform("u_stickerPos7", primSet.parentMesh.stickersPos[7], UNIFORMTYPE.FLOAT3); - - - arrayPeek(material.renderObj).addUniform("u_projMatrix", gl.perspectiveMatrix, UNIFORMTYPE.MATRIX4); - - arrayPeek(material.renderObj).addUniform("u_fillColor1", material.fillColor[0], UNIFORMTYPE.FLOAT4); - arrayPeek(material.renderObj).addUniform("u_fillColor2", material.fillColor[1], UNIFORMTYPE.FLOAT4); - arrayPeek(material.renderObj).addUniform("u_skinColor", material.fillColor[2], UNIFORMTYPE.FLOAT4); - - - // debug--- - vertexData.vertexObject.name = "vertexObject"; - vertexData.normalObject.name = "normalObject"; - vertexData.texCoordObject.name = "texCoordObject"; - vertexData.indexObject.name = "indexObject"; - //---------- - - arrayPeek(material.renderObj).addBuffers(vertexData.vertexObject, gl.ARRAY_BUFFER, 3, 0, gl.FLOAT); - arrayPeek(material.renderObj).addBuffers(vertexData.normalObject, gl.ARRAY_BUFFER, 3, 1, gl.FLOAT); - arrayPeek(material.renderObj).addBuffers(vertexData.texCoordObject, gl.ARRAY_BUFFER, 2, 2, gl.FLOAT); - arrayPeek(material.renderObj).addBuffers(vertexData.indexObject, gl.ELEMENT_ARRAY_BUFFER); - - - //} - - gl.useProgram(null); -// gl.console.log("Mesh Init done!"); - -} - -function __renderInitScreenQuad(quad, shader) -{ - if(shader == undefined) - { - quad.shader = createShader(gl, 'screenQuad_vShader', 'screenQuad_fShader', [ "vert", "texcoord"]); - } - else - { - quad.shader = shader; - } - - quad.renderObj = new RenderObject(quad.shader); - - quadBuf = getScreenAlignedQuad(); - - quad.vertBuffer = quadBuf.vertexObject; - quad.uvBuffer = quadBuf.texCoordObject; - - - quad.renderObj.addTexture("basemap", 0, UNIFORMTYPE.TEXTURE2D); - - var invWidth = (g_width == 0.0) ? 0.0 : 1.0/g_width, invHeight = (g_height == 0.0) ? 0.0 : 1.0/g_height; - quad.renderObj.addUniform("u_inv_viewport_width", invWidth, UNIFORMTYPE.FLOAT); - quad.renderObj.addUniform("u_inv_viewport_height", invHeight, UNIFORMTYPE.FLOAT); - - quad.renderObj.addBuffers(quad.vertBuffer, gl.ARRAY_BUFFER, 3, 0, gl.FLOAT); - quad.renderObj.addBuffers(quad.uvBuffer, gl.ARRAY_BUFFER, 2, 2, gl.FLOAT); -} - -function __renderInitProcDepthMap(renderObj) -{ - renderObj.shader = g_depthShader.shaderHandle;//createShader(gl, depthMapVShader, depthMapFShader, [ "vert", "normal", "texcoord"]); - +// RDGE namespaces +var RDGE = RDGE || {}; + +RDGE.renderInitProcDefault = function (primSet, vertexData) { + var material = primSet.material; + + //push envMap tex + material.tex.env.push(arrayPeek(material.shader).envMap); + material.tex.envDiff.push(arrayPeek(material.shader).envDiff); + + gl.useProgram(arrayPeek(material.shader).shaderHandle); + + arrayPeek(material.renderObj).addTexture("layerMap1", 0, RDGE.UNIFORMTYPE.TEXTURE2D); + arrayPeek(material.renderObj).addTexture("layerMap2", 1, RDGE.UNIFORMTYPE.TEXTURE2D); + arrayPeek(material.renderObj).addTexture("colorMeMap1", 2, RDGE.UNIFORMTYPE.TEXTURE2D); + arrayPeek(material.renderObj).addTexture("colorMeMap2", 3, RDGE.UNIFORMTYPE.TEXTURE2D); + arrayPeek(material.renderObj).addTexture("envMap", 4, RDGE.UNIFORMTYPE.TEXTURE2D); + arrayPeek(material.renderObj).addTexture("envDiff", 5, RDGE.UNIFORMTYPE.TEXTURE2D); + + arrayPeek(material.renderObj).addTexture("normalMap1", 15, RDGE.UNIFORMTYPE.TEXTURE2D); + arrayPeek(material.renderObj).addTexture("normalMap2", 6, RDGE.UNIFORMTYPE.TEXTURE2D); + + arrayPeek(material.renderObj).addTexture("stickerMap0", 7, RDGE.UNIFORMTYPE.TEXTURE2D); + arrayPeek(material.renderObj).addTexture("stickerMap1", 8, RDGE.UNIFORMTYPE.TEXTURE2D); + arrayPeek(material.renderObj).addTexture("stickerMap2", 9, RDGE.UNIFORMTYPE.TEXTURE2D); + arrayPeek(material.renderObj).addTexture("stickerMap3", 10, RDGE.UNIFORMTYPE.TEXTURE2D); + arrayPeek(material.renderObj).addTexture("stickerMap4", 11, RDGE.UNIFORMTYPE.TEXTURE2D); + arrayPeek(material.renderObj).addTexture("stickerMap5", 12, RDGE.UNIFORMTYPE.TEXTURE2D); + arrayPeek(material.renderObj).addTexture("stickerMap6", 13, RDGE.UNIFORMTYPE.TEXTURE2D); + arrayPeek(material.renderObj).addTexture("stickerMap7", 14, RDGE.UNIFORMTYPE.TEXTURE2D); + + arrayPeek(material.renderObj).addUniform("u_normalMatrix", gl.normalMatrix, RDGE.UNIFORMTYPE.MATRIX4); + arrayPeek(material.renderObj).addUniform("u_mvMatrix", gl.mvMatrix, RDGE.UNIFORMTYPE.MATRIX4); + arrayPeek(material.renderObj).addUniform("u_invMvMatrix", gl.invMvMatrix, RDGE.UNIFORMTYPE.MATRIX4); + + arrayPeek(material.renderObj).addUniform("u_stickerMatrix0", primSet.parentMesh.stickers[0], RDGE.UNIFORMTYPE.MATRIX4); + arrayPeek(material.renderObj).addUniform("u_stickerMatrix1", primSet.parentMesh.stickers[1], RDGE.UNIFORMTYPE.MATRIX4); + arrayPeek(material.renderObj).addUniform("u_stickerMatrix2", primSet.parentMesh.stickers[2], RDGE.UNIFORMTYPE.MATRIX4); + arrayPeek(material.renderObj).addUniform("u_stickerMatrix3", primSet.parentMesh.stickers[3], RDGE.UNIFORMTYPE.MATRIX4); + arrayPeek(material.renderObj).addUniform("u_stickerMatrix4", primSet.parentMesh.stickers[4], RDGE.UNIFORMTYPE.MATRIX4); + arrayPeek(material.renderObj).addUniform("u_stickerMatrix5", primSet.parentMesh.stickers[5], RDGE.UNIFORMTYPE.MATRIX4); + arrayPeek(material.renderObj).addUniform("u_stickerMatrix6", primSet.parentMesh.stickers[6], RDGE.UNIFORMTYPE.MATRIX4); + arrayPeek(material.renderObj).addUniform("u_stickerMatrix7", primSet.parentMesh.stickers[7], RDGE.UNIFORMTYPE.MATRIX4); + + arrayPeek(material.renderObj).addUniform("u_stickerPos0", primSet.parentMesh.stickersPos[0], RDGE.UNIFORMTYPE.FLOAT3); + arrayPeek(material.renderObj).addUniform("u_stickerPos1", primSet.parentMesh.stickersPos[1], RDGE.UNIFORMTYPE.FLOAT3); + arrayPeek(material.renderObj).addUniform("u_stickerPos2", primSet.parentMesh.stickersPos[2], RDGE.UNIFORMTYPE.FLOAT3); + arrayPeek(material.renderObj).addUniform("u_stickerPos3", primSet.parentMesh.stickersPos[3], RDGE.UNIFORMTYPE.FLOAT3); + arrayPeek(material.renderObj).addUniform("u_stickerPos4", primSet.parentMesh.stickersPos[4], RDGE.UNIFORMTYPE.FLOAT3); + arrayPeek(material.renderObj).addUniform("u_stickerPos5", primSet.parentMesh.stickersPos[5], RDGE.UNIFORMTYPE.FLOAT3); + arrayPeek(material.renderObj).addUniform("u_stickerPos6", primSet.parentMesh.stickersPos[6], RDGE.UNIFORMTYPE.FLOAT3); + arrayPeek(material.renderObj).addUniform("u_stickerPos7", primSet.parentMesh.stickersPos[7], RDGE.UNIFORMTYPE.FLOAT3); + + arrayPeek(material.renderObj).addUniform("u_projMatrix", gl.perspectiveMatrix, RDGE.UNIFORMTYPE.MATRIX4); + + arrayPeek(material.renderObj).addUniform("u_fillColor1", material.fillColor[0], RDGE.UNIFORMTYPE.FLOAT4); + arrayPeek(material.renderObj).addUniform("u_fillColor2", material.fillColor[1], RDGE.UNIFORMTYPE.FLOAT4); + arrayPeek(material.renderObj).addUniform("u_skinColor", material.fillColor[2], RDGE.UNIFORMTYPE.FLOAT4); + + // debug--- + vertexData.vertexObject.name = "vertexObject"; + vertexData.normalObject.name = "normalObject"; + vertexData.texCoordObject.name = "texCoordObject"; + vertexData.indexObject.name = "indexObject"; + //---------- + + arrayPeek(material.renderObj).addBuffers(vertexData.vertexObject, gl.ARRAY_BUFFER, 3, 0, gl.FLOAT); + arrayPeek(material.renderObj).addBuffers(vertexData.normalObject, gl.ARRAY_BUFFER, 3, 1, gl.FLOAT); + arrayPeek(material.renderObj).addBuffers(vertexData.texCoordObject, gl.ARRAY_BUFFER, 2, 2, gl.FLOAT); + arrayPeek(material.renderObj).addBuffers(vertexData.indexObject, gl.ELEMENT_ARRAY_BUFFER); + + gl.useProgram(null); + // gl.console.log("Mesh Init done!"); +}; + +RDGE.renderInitScreenQuad = function (quad, shader) { + if (shader == undefined) { + quad.shader = RDGE.createShader(gl, 'screenQuad_vShader', 'screenQuad_fShader', ["vert", "texcoord"]); + } + else { + quad.shader = shader; + } + + quad.renderObj = new RDGE.RenderObject(quad.shader); + + quadBuf = getScreenAlignedQuad(); + + quad.vertBuffer = quadBuf.vertexObject; + quad.uvBuffer = quadBuf.texCoordObject; + + + quad.renderObj.addTexture("basemap", 0, RDGE.UNIFORMTYPE.TEXTURE2D); + + var invWidth = (RDGE.globals.width == 0.0) ? 0.0 : 1.0 / RDGE.globals.width, invHeight = (RDGE.globals.height == 0.0) ? 0.0 : 1.0 / RDGE.globals.height; + quad.renderObj.addUniform("u_inv_viewport_width", invWidth, RDGE.UNIFORMTYPE.FLOAT); + quad.renderObj.addUniform("u_inv_viewport_height", invHeight, RDGE.UNIFORMTYPE.FLOAT); + + quad.renderObj.addBuffers(quad.vertBuffer, gl.ARRAY_BUFFER, 3, 0, gl.FLOAT); + quad.renderObj.addBuffers(quad.uvBuffer, gl.ARRAY_BUFFER, 2, 2, gl.FLOAT); +}; + +RDGE.renderInitProcDepthMap = function (renderObj) { + renderObj.shader = g_depthShader.shaderHandle; //RDGE.createShader(gl, depthMapVShader, depthMapFShader, [ "vert", "normal", "texcoord"]); + gl.useProgram(renderObj.shader); - renderObj.addUniform("u_mvpLightMatrix", g_mainLight.mvpMatrix, UNIFORMTYPE.MATRIX4); - //renderObj.addUniform("u_mvpLightMatrixWTF", g_mainLight.mvpMatrix, UNIFORMTYPE.MATRIX4); - // var uni = gl.getUniformLocation(renderObj.shader, "u_mvpLightMatrixWTF"); -// renderObj.addUniform("u_WTF1", g_lightMat[0], UNIFORMTYPE.FLOAT4); -// renderObj.addUniform("u_WTF2", g_lightMat[1], UNIFORMTYPE.FLOAT4); -// renderObj.addUniform("u_WTF3", g_lightMat[2], UNIFORMTYPE.FLOAT4); -// renderObj.addUniform("u_WTF4", g_lightMat[3], UNIFORMTYPE.FLOAT4); -// + renderObj.addUniform("u_mvpLightMatrix", g_mainLight.mvpMatrix, RDGE.UNIFORMTYPE.MATRIX4); + //renderObj.addUniform("u_mvpLightMatrixWTF", g_mainLight.mvpMatrix, RDGE.UNIFORMTYPE.MATRIX4); + // var uni = gl.getUniformLocation(renderObj.shader, "u_mvpLightMatrixWTF"); + // renderObj.addUniform("u_WTF1", g_lightMat[0], RDGE.UNIFORMTYPE.FLOAT4); + // renderObj.addUniform("u_WTF2", g_lightMat[1], RDGE.UNIFORMTYPE.FLOAT4); + // renderObj.addUniform("u_WTF3", g_lightMat[2], RDGE.UNIFORMTYPE.FLOAT4); + // renderObj.addUniform("u_WTF4", g_lightMat[3], RDGE.UNIFORMTYPE.FLOAT4); + // // since the uniform data references should not change we can just bind one time renderObj.bindUniforms(); - + + gl.useProgram(null); +}; + +RDGE.renderInitShadowReceiver = function (primSet, vertexData) { + // setup passes + primSet.shadowTarget = g_texMan.loadRenderTarget("shadowTarget", 256, 256); + primSet.shadowTargetFinal = g_texMan.loadRenderTarget("shadowTargetFinal", 256, 256); + primSet.screenQuad = new RDGE.ScreenQuad(primSet.shadowTargetFinal); + primSet.screenQuad.initialize(RDGE.renderInitRadialBlur); + + // set the target as the shadow to get projcetd + primSet.parentMesh.shadowToProject = primSet.shadowTarget; + + //mainSceneQuad = new RDGE.ScreenQuad(primSet.shadowTarget); + //mainSceneQuad.initialize(renderInitScreenQuad); + + var material = primSet.material; + + //push envMap tex + material.tex.env.push(arrayPeek(material.shader).envMap); + material.tex.envDiff.push(arrayPeek(material.shader).envDiff); + + gl.useProgram(arrayPeek(material.shader).shaderHandle); + + arrayPeek(material.renderObj).addTexture("shadowMap", 0, RDGE.UNIFORMTYPE.TEXTURE2D); + arrayPeek(material.renderObj).addUniform("u_mvMatrix", gl.mvMatrix, RDGE.UNIFORMTYPE.MATRIX4); + + arrayPeek(material.renderObj).addUniform("u_projMatrix", gl.perspectiveMatrix, RDGE.UNIFORMTYPE.MATRIX4); + + arrayPeek(material.renderObj).addUniform("u_shadowBiasMatrix", g_mainLight.shadowMatrix, RDGE.UNIFORMTYPE.MATRIX4); + arrayPeek(material.renderObj).addUniform("u_vShadowLight", g_mainLight.view, RDGE.UNIFORMTYPE.MATRIX4); + + + // debug--- + vertexData.vertexObject.name = "vertexObject"; + vertexData.normalObject.name = "normalObject"; + vertexData.texCoordObject.name = "texCoordObject"; + vertexData.indexObject.name = "indexObject"; + //---------- + + arrayPeek(material.renderObj).addBuffers(vertexData.vertexObject, gl.ARRAY_BUFFER, 3, 0, gl.FLOAT); + arrayPeek(material.renderObj).addBuffers(vertexData.normalObject, gl.ARRAY_BUFFER, 3, 1, gl.FLOAT); + arrayPeek(material.renderObj).addBuffers(vertexData.texCoordObject, gl.ARRAY_BUFFER, 2, 2, gl.FLOAT); + arrayPeek(material.renderObj).addBuffers(vertexData.indexObject, gl.ELEMENT_ARRAY_BUFFER); + gl.useProgram(null); -} - -function __renderInitShadowReceiver(primSet, vertexData) -{ - // setup passes - primSet.shadowTarget = g_texMan.loadRenderTarget("shadowTarget", 256, 256); - primSet.shadowTargetFinal = g_texMan.loadRenderTarget("shadowTargetFinal", 256, 256); - primSet.screenQuad = new ScreenQuad(primSet.shadowTargetFinal); - primSet.screenQuad.initialize(__renderInitRadialBlur); - - // set the target as the shadow to get projcetd - primSet.parentMesh.shadowToProject = primSet.shadowTarget; - - //mainSceneQuad = new ScreenQuad(primSet.shadowTarget); - //mainSceneQuad.initialize(renderInitScreenQuad); - - var material = primSet.material; - - //push envMap tex - material.tex.env.push(arrayPeek(material.shader).envMap); - material.tex.envDiff.push(arrayPeek(material.shader).envDiff); - - gl.useProgram(arrayPeek(material.shader).shaderHandle); - - arrayPeek(material.renderObj).addTexture("shadowMap", 0, UNIFORMTYPE.TEXTURE2D); - arrayPeek(material.renderObj).addUniform("u_mvMatrix", gl.mvMatrix, UNIFORMTYPE.MATRIX4); - - arrayPeek(material.renderObj).addUniform("u_projMatrix", gl.perspectiveMatrix, UNIFORMTYPE.MATRIX4); - - arrayPeek(material.renderObj).addUniform("u_shadowBiasMatrix", g_mainLight.shadowMatrix, UNIFORMTYPE.MATRIX4); - arrayPeek(material.renderObj).addUniform("u_vShadowLight", g_mainLight.view, UNIFORMTYPE.MATRIX4); - - - // debug--- - vertexData.vertexObject.name = "vertexObject"; - vertexData.normalObject.name = "normalObject"; - vertexData.texCoordObject.name = "texCoordObject"; - vertexData.indexObject.name = "indexObject"; - //---------- - - arrayPeek(material.renderObj).addBuffers(vertexData.vertexObject, gl.ARRAY_BUFFER, 3, 0, gl.FLOAT); - arrayPeek(material.renderObj).addBuffers(vertexData.normalObject, gl.ARRAY_BUFFER, 3, 1, gl.FLOAT); - arrayPeek(material.renderObj).addBuffers(vertexData.texCoordObject, gl.ARRAY_BUFFER, 2, 2, gl.FLOAT); - arrayPeek(material.renderObj).addBuffers(vertexData.indexObject, gl.ELEMENT_ARRAY_BUFFER); - - - //} - - gl.useProgram(null); -// gl.console.log("Mesh Init done!"); - - //__renderInitShadowProjection(primSet, vertexData); - -} - - -function __renderInitShadowProjection(primSet, vertexData) -{ - var material = primSet.material; - - //push envMap tex - //material.tex.env.push(arrayPeek(material.shader).envMap); - //material.tex.envDiff.push(arrayPeek(material.shader).envDiff); - - gl.useProgram(arrayPeek(material.shader).shaderHandle); - - arrayPeek(material.renderObj).addTexture("shadowMap", 0, UNIFORMTYPE.TEXTURE2D); - arrayPeek(material.renderObj).addUniform("u_mvMatrix", gl.mvMatrix, UNIFORMTYPE.MATRIX4); - - arrayPeek(material.renderObj).addUniform("u_projMatrix", gl.perspectiveMatrix, UNIFORMTYPE.MATRIX4); - - arrayPeek(material.renderObj).addUniform("u_shadowBiasMatrix", g_mainLight.shadowMatrix, UNIFORMTYPE.MATRIX4); - arrayPeek(material.renderObj).addUniform("u_vShadowLight", g_mainLight.view, UNIFORMTYPE.MATRIX4); - - - // debug--- - vertexData.vertexObject.name = "vertexObject"; - vertexData.normalObject.name = "normalObject"; - vertexData.texCoordObject.name = "texCoordObject"; - vertexData.indexObject.name = "indexObject"; - //---------- - - arrayPeek(material.renderObj).addBuffers(vertexData.vertexObject, gl.ARRAY_BUFFER, 3, 0, gl.FLOAT); - arrayPeek(material.renderObj).addBuffers(vertexData.normalObject, gl.ARRAY_BUFFER, 3, 1, gl.FLOAT); - arrayPeek(material.renderObj).addBuffers(vertexData.texCoordObject, gl.ARRAY_BUFFER, 2, 2, gl.FLOAT); - arrayPeek(material.renderObj).addBuffers(vertexData.indexObject, gl.ELEMENT_ARRAY_BUFFER); - - - //} - - gl.useProgram(null); -// gl.console.log("Mesh Init done!"); - -} - -function __renderInitRadialBlur(quad, shader) -{ - if(shader == undefined) - { - quad.shader = createShader(gl, 'radialBlur_vshader', 'radialBlur_fshader', [ "vert", "texcoord"]); - } - else - { - quad.shader = shader; - } - - quad.renderObj = new RenderObject(quad.shader); - - quadBuf = getScreenAlignedQuad(); - - quad.vertBuffer = quadBuf.vertexObject; - quad.uvBuffer = quadBuf.texCoordObject; - - - quad.renderObj.addTexture("basemap", 0, UNIFORMTYPE.TEXTURE2D); - - quad.renderObj.addUniform("u_inv_viewport_width", 1.0/g_width, UNIFORMTYPE.FLOAT); - quad.renderObj.addUniform("u_inv_viewport_height", 1.0/g_height, UNIFORMTYPE.FLOAT); - quad.renderObj.addUniform("u_sampRadius", 5.0, UNIFORMTYPE.FLOAT); - quad.renderObj.addUniform("u_numSamples", 16, UNIFORMTYPE.INT); - quad.renderObj.addUniform("u_mapSize", 256.0, UNIFORMTYPE.FLOAT); - - quad.renderObj.addBuffers(quad.vertBuffer, gl.ARRAY_BUFFER, 3, 0, gl.FLOAT); - quad.renderObj.addBuffers(quad.uvBuffer, gl.ARRAY_BUFFER, 2, 2, gl.FLOAT); -} + + //RDGE.renderInitShadowProjection(primSet, vertexData); +}; + + +RDGE.renderInitShadowProjection = function (primSet, vertexData) { + var material = primSet.material; + + //push envMap tex + //material.tex.env.push(arrayPeek(material.shader).envMap); + //material.tex.envDiff.push(arrayPeek(material.shader).envDiff); + + gl.useProgram(arrayPeek(material.shader).shaderHandle); + + arrayPeek(material.renderObj).addTexture("shadowMap", 0, RDGE.UNIFORMTYPE.TEXTURE2D); + arrayPeek(material.renderObj).addUniform("u_mvMatrix", gl.mvMatrix, RDGE.UNIFORMTYPE.MATRIX4); + + arrayPeek(material.renderObj).addUniform("u_projMatrix", gl.perspectiveMatrix, RDGE.UNIFORMTYPE.MATRIX4); + + arrayPeek(material.renderObj).addUniform("u_shadowBiasMatrix", g_mainLight.shadowMatrix, RDGE.UNIFORMTYPE.MATRIX4); + arrayPeek(material.renderObj).addUniform("u_vShadowLight", g_mainLight.view, RDGE.UNIFORMTYPE.MATRIX4); + + + // debug--- + vertexData.vertexObject.name = "vertexObject"; + vertexData.normalObject.name = "normalObject"; + vertexData.texCoordObject.name = "texCoordObject"; + vertexData.indexObject.name = "indexObject"; + //---------- + + arrayPeek(material.renderObj).addBuffers(vertexData.vertexObject, gl.ARRAY_BUFFER, 3, 0, gl.FLOAT); + arrayPeek(material.renderObj).addBuffers(vertexData.normalObject, gl.ARRAY_BUFFER, 3, 1, gl.FLOAT); + arrayPeek(material.renderObj).addBuffers(vertexData.texCoordObject, gl.ARRAY_BUFFER, 2, 2, gl.FLOAT); + arrayPeek(material.renderObj).addBuffers(vertexData.indexObject, gl.ELEMENT_ARRAY_BUFFER); + + + gl.useProgram(null); +}; + +RDGE.renderInitRadialBlur = function(quad, shader) { + if (shader == undefined) { + quad.shader = RDGE.createShader(gl, 'radialBlur_vshader', 'radialBlur_fshader', ["vert", "texcoord"]); + } + else { + quad.shader = shader; + } + + quad.renderObj = new RDGE.RenderObject(quad.shader); + + quadBuf = getScreenAlignedQuad(); + + quad.vertBuffer = quadBuf.vertexObject; + quad.uvBuffer = quadBuf.texCoordObject; + + + quad.renderObj.addTexture("basemap", 0, RDGE.UNIFORMTYPE.TEXTURE2D); + +