diff --git a/api/latest/scenejs.js b/api/latest/scenejs.js index 3ab67291..55872884 100644 --- a/api/latest/scenejs.js +++ b/api/latest/scenejs.js @@ -4,7 +4,7 @@ * A WebGL-based 3D scene graph from xeoLabs * http://scenejs.org/ * - * Built on 2016-09-13 + * Built on 2016-09-15 * * MIT License * Copyright 2016, Lindsay Kay @@ -2462,9 +2462,13 @@ SceneJS_Engine.prototype.start = function () { if (lastFrameTime > 0) { elapsedFrameTime = frameTime - lastFrameTime; - newFPS = 1000 / elapsedFrameTime; - totalFPS += newFPS; - fpsSamples.push(newFPS); + if(elapsedFrameTime == 0) { + newFPS = 0; + } else { + newFPS = 1000 / elapsedFrameTime; + totalFPS += newFPS; + fpsSamples.push(newFPS); + } if (fpsSamples.length >= numFPSSamples) { totalFPS -= fpsSamples.shift(); } @@ -8960,6 +8964,13 @@ new (function () { return SceneJS._sliceArray(this._core.matrix, 0); }; + SceneJS.Camera.prototype.setMatrix = function (matrix) { // TODO: Extract clip planes from matrix + this._core.matrix = matrix; + this._core.mat = matrix; + this.publish("matrix", this._core.matrix); + this._engine.display.imageDirty = true; + }; + /** * Compiles this camera node, setting this node's state core on the display, compiling sub-nodes, * then restoring the previous camera state core back onto the display on exit. @@ -11301,6 +11312,13 @@ SceneJS.Library.prototype._compile = function(ctx) { // Bypass child nodes return SceneJS._sliceArray(this._core.matrix, 0); }; + SceneJS.Lookat.prototype.setMatrix = function (matrix) { // TODO: Extract clip planes from matrix + this._core.matrix = matrix; + this._core.mat = matrix; + this.publish("matrix", this._core.matrix); + this._engine.display.imageDirty = true; + }; + SceneJS.Lookat.prototype.getAttributes = function () { return { look:{ @@ -17778,14 +17796,10 @@ SceneJS_Display.prototype.render = function (params) { //this._logPickList(); } - if (true || this.imageDirty || params.force) { + if (this.imageDirty || params.force) { SceneJS_events.fireEvent(SceneJS_events.RENDER, { forced: !!params.force }); - //if (!this._helloWebGL) { - // this._helloWebGL = new HelloWebGL(this._canvas.canvas, this._canvas.gl); - //} -// this._helloWebGL.draw(); this._doDrawList({ // Render, no pick clear: (params.clear !== false), // Clear buffers by default opaqueOnly: params.opaqueOnly @@ -18131,7 +18145,9 @@ SceneJS_Display.prototype._logPickList = function () { var localRayOrigin = SceneJS_math_vec3(); var localRayDir = SceneJS_math_vec3(); - var pickMatrix = SceneJS_math_mat4(); + var pickViewMatrix = mat4.create(); + var pickProjMatrix = mat4.create(); + mat4.frustum(pickProjMatrix, -1, 1, -1, 1, 0.1, 10000); var a = SceneJS_math_vec3(); var b = SceneJS_math_vec3(); @@ -18292,7 +18308,7 @@ SceneJS_Display.prototype._logPickList = function () { var look = SceneJS_math_addVec3(worldRayOrigin, worldRayDir, tempVec3); var up = new Float32Array([0, 1, 0]); // TODO: derive from ray - SceneJS_math_lookAtMat4v(worldRayOrigin, look, up, pickMatrix); + SceneJS_math_lookAtMat4v(worldRayOrigin, look, up, pickViewMatrix); pickBufX = canvas.clientWidth * 0.5; pickBufY = canvas.clientHeight * 0.5; @@ -18316,7 +18332,8 @@ SceneJS_Display.prototype._logPickList = function () { this._doDrawList({ pickObject: true, clear: true, - pickMatrix: worldRayPicking ? pickMatrix: null + pickViewMatrix: worldRayPicking ? pickViewMatrix: null, + pickProjMatrix: worldRayPicking ? pickProjMatrix: null }); this._canvas.gl.finish(); @@ -18362,7 +18379,8 @@ SceneJS_Display.prototype._logPickList = function () { this._doDrawList({ pickRegion: true, object: object, - pickMatrix: worldRayPicking ? pickMatrix: null, + pickViewMatrix: worldRayPicking ? pickViewMatrix: null, + pickProjMatrix: worldRayPicking ? pickProjMatrix: null, clear: true }); @@ -18413,7 +18431,8 @@ SceneJS_Display.prototype._logPickList = function () { this._doDrawList({ pickTriangle: true, object: object, - pickMatrix: worldRayPicking ? pickMatrix: null, + pickViewMatrix: worldRayPicking ? pickViewMatrix: null, + pickProjMatrix: worldRayPicking ? pickProjMatrix: null, clear: true }); @@ -18808,7 +18827,8 @@ SceneJS_Display.prototype._doDrawList = function (params) { frameCtx.bindTexture = 0; frameCtx.bindArray = 0; - frameCtx.pickMatrix = params.pickMatrix; + frameCtx.pickViewMatrix = params.pickViewMatrix; + frameCtx.pickProjMatrix = params.pickProjMatrix; // The extensions needs to be re-queried in case the context was lost and has been recreated. if (SceneJS.WEBGL_INFO.SUPPORTED_EXTENSIONS["OES_element_index_uint"]) { @@ -21015,7 +21035,7 @@ SceneJS_ChunkFactory.prototype.webglRestored = function () { var gl = this.program.gl; if (this._uPMatrixPick) { - this._uPMatrixPick.setValue(this.core.mat); + this._uPMatrixPick.setValue(frameCtx.pickProjMatrix || this.core.mat); } if (frameCtx.rayPick) { // Z-pick pass: feed near and far clip planes into shader @@ -21851,7 +21871,7 @@ SceneJS_ChunkFactory.createChunkType({ pick : function(frameCtx) { if (this._uvMatrixPick) { - this._uvMatrixPick.setValue(frameCtx.pickMatrix || this.core.mat); + this._uvMatrixPick.setValue(frameCtx.pickViewMatrix || this.core.mat); } frameCtx.viewMat = this.core.mat; diff --git a/api/latest/scenejs.min.js b/api/latest/scenejs.min.js index f6e13975..39b7ea52 100644 --- a/api/latest/scenejs.min.js +++ b/api/latest/scenejs.min.js @@ -4,7 +4,7 @@ * A WebGL-based 3D scene graph from xeoLabs * http://scenejs.org/ * - * Built on 2016-09-13 + * Built on 2016-09-15 * * MIT License * Copyright 2016, Lindsay Kay @@ -13,12 +13,12 @@ */ if(void 0===require){var requirejs,require,define;!function(ba){function J(a){return"[object Function]"===N.call(a)}function K(a){return"[object Array]"===N.call(a)}function z(a,b){if(a){var c;for(c=0;cthis.depCount&&!this.defined){if(J(e)){if(this.events.error&&this.map.isDefine||h.onError!==ca)try{d=w.execCb(c,e,b,d)}catch(f){a=f}else d=w.execCb(c,e,b,d);if(this.map.isDefine&&((b=this.module)&&void 0!==b.exports&&b.exports!==this.exports?d=b.exports:void 0===d&&this.usingExports&&(d=this.exports)),a)return a.requireMap=this.map,a.requireModules=this.map.isDefine?[this.map.id]:null,a.requireType=this.map.isDefine?"define":"require",j(this.error=a)}else d=e;this.exports=d,this.map.isDefine&&!this.ignore&&(I[c]=d,h.onResourceLoad)&&h.onResourceLoad(w,this.map,this.depMaps),l(c),this.defined=!0}this.defining=!1,this.defined&&!this.defineEmitted&&(this.defineEmitted=!0,this.emit("defined",this.exports),this.defineEmitComplete=!0)}}else this.fetch()}},callPlugin:function(){var a=this.map,c=a.id,d=f(a.prefix);this.depMaps.push(d),i(d,"defined",v(this,function(d){var e,k;k=this.map.name;var n=this.map.parentMap?this.map.parentMap.name:null,o=w.makeRequire(a.parentMap,{enableBuildCallback:!0});this.map.unnormalized?(d.normalize&&(k=d.normalize(k,function(a){return b(a,n,!0)})||""),d=f(a.prefix+"!"+k,this.map.parentMap),i(d,"defined",v(this,function(a){this.init([],function(){return a},null,{enabled:!0,ignore:!0})})),(k=m(D,d.id))&&(this.depMaps.push(d),this.events.error&&k.on("error",v(this,function(a){this.emit("error",a)})),k.enable())):(e=v(this,function(a){this.init([],function(){return a},null,{enabled:!0})}),e.error=v(this,function(a){this.inited=!0,this.error=a,a.requireModules=[c],H(D,function(a){0===a.map.id.indexOf(c+"_unnormalized")&&l(a.map.id)}),j(a)}),e.fromText=v(this,function(b,d){var i=a.name,k=f(i),l=Q;d&&(b=d),l&&(Q=!1),g(k),t(C.config,c)&&(C.config[i]=C.config[c]);try{h.exec(b)}catch(m){return j(B("fromtexteval","fromText eval for "+c+" failed: "+m,m,[c]))}l&&(Q=!0),this.depMaps.push(k),w.completeLoad(i),o([i],e)}),d.load(a.name,o,e,C))})),w.enable(d,this),this.pluginMaps[d.id]=d},enable:function(){E[this.map.id]=this,this.enabling=this.enabled=!0,z(this.depMaps,v(this,function(a,b){var c,d;if("string"==typeof a){if(a=f(a,this.map.isDefine?this.map:this.map.parentMap,!1,!this.skipMap),this.depMaps[b]=a,c=m(x,a.id))return void(this.depExports[b]=c(this));this.depCount+=1,i(a,"defined",v(this,function(a){this.defineDep(b,a),this.check()})),this.errback&&i(a,"error",v(this,this.errback))}c=a.id,d=D[c],!t(x,c)&&d&&!d.enabled&&w.enable(a,this)})),H(this.pluginMaps,v(this,function(a){var b=m(D,a.id);b&&!b.enabled&&w.enable(a,this)})),this.enabling=!1,this.check()},on:function(a,b){var c=this.events[a];c||(c=this.events[a]=[]),c.push(b)},emit:function(a,b){z(this.events[a],function(a){a(b)}),"error"===a&&delete this.events[a]}},w={config:C,contextName:a,registry:D,defined:I,urlFetched:L,defQueue:G,Module:u,makeModuleMap:f,nextTick:h.nextTick,onError:j,configure:function(a){a.baseUrl&&"/"!==a.baseUrl.charAt(a.baseUrl.length-1)&&(a.baseUrl+="/");var b=C.pkgs,c=C.shim,d={paths:!0,config:!0,map:!0};H(a,function(a,b){d[b]?"map"===b?(C.map||(C.map={}),S(C[b],a,!0,!0)):S(C[b],a,!0):C[b]=a}),a.shim&&(H(a.shim,function(a,b){K(a)&&(a={deps:a}),!a.exports&&!a.init||a.exportsFn||(a.exportsFn=w.makeShimExports(a)),c[b]=a}),C.shim=c),a.packages&&(z(a.packages,function(a){a="string"==typeof a?{name:a}:a,b[a.name]={name:a.name,location:a.location||a.name,main:(a.main||"main").replace(ka,"").replace(fa,"")}}),C.pkgs=b),H(D,function(a,b){!a.inited&&!a.map.unnormalized&&(a.map=f(b))}),(a.deps||a.callback)&&w.require(a.deps||[],a.callback)},makeShimExports:function(a){return function(){var b;return a.init&&(b=a.init.apply(ba,arguments)),b||a.exports&&da(a.exports)}},makeRequire:function(c,d){function e(b,i,k){var l,m;return d.enableBuildCallback&&i&&J(i)&&(i.__requireJsBuild=!0),"string"==typeof b?J(i)?j(B("requireargs","Invalid require call"),k):c&&t(x,b)?x[b](D[c.id]):h.get?h.get(w,b,c,e):(l=f(b,c,!1,!0),l=l.id,t(I,l)?I[l]:j(B("notloaded",'Module name "'+l+'" has not been loaded yet for context: '+a+(c?"":". Use require([])")))):(r(),w.nextTick(function(){r(),m=g(f(null,c)),m.skipMap=d.skipMap,m.init(b,i,k,{enabled:!0}),o()}),e)}return d=d||{},S(e,{isBrowser:A,toUrl:function(a){var d,e=a.lastIndexOf("."),f=a.split("/")[0];return-1!==e&&("."!==f&&".."!==f||1d.attachEvent.toString().indexOf("[native code")||Z?(d.addEventListener("load",a.onScriptLoad,!1),d.addEventListener("error",a.onScriptError,!1)):(Q=!0,d.attachEvent("onreadystatechange",a.onScriptLoad)),d.src=c,M=d,E?y.insertBefore(d,E):y.appendChild(d),M=null,d;if(ea)try{importScripts(c),a.completeLoad(b)}catch(f){a.onError(B("importscripts","importScripts failed for "+b+" at "+c,f,[b]))}},A&&O(document.getElementsByTagName("script"),function(a){if(y||(y=a.parentNode),L=a.getAttribute("data-main"))return s=L,u.baseUrl||(F=s.split("/"),s=F.pop(),ga=F.length?F.join("/")+"/":"./",u.baseUrl=ga),s=s.replace(fa,""),h.jsExtRegExp.test(s)&&(s=L),u.deps=u.deps?u.deps.concat(s):[s],!0}),define=function(a,b,c){var d,e;"string"!=typeof a&&(c=b,b=a,a=null),K(b)||(c=b,b=null),!b&&J(c)&&(b=[],c.length&&(c.toString().replace(ma,"").replace(na,function(a,c){b.push(c)}),b=(1===c.length?["require"]:["require","exports","module"]).concat(b))),Q&&((d=M)||(R&&"interactive"===R.readyState||O(document.getElementsByTagName("script"),function(a){if("interactive"===a.readyState)return R=a}),d=R),d&&(a||(a=d.getAttribute("data-requiremodule")),e=G[d.getAttribute("data-requirecontext")])),(e?e.defQueue:U).push([a,b,c])},define.amd={jQuery:!0},h.exec=function(b){return eval(b)},h(u)}}(this)}WebGLDebugUtils=function(){function a(a){if(null==m){m={};for(var b in a)"number"==typeof a[b]&&(m[a[b]]=b)}}function b(){if(null==m)throw"WebGLDebugUtils.init(ctx) not called"}function c(a){return b(),void 0!==m[a]}function d(a){b();var c=m[a];return void 0!==c?c:"*UNKNOWN WebGL ENUM (0x"+a.toString(16)+")"}function e(a,b,c){var e=l[a];return void 0!==e&&e[b]?d(c):null===c?"null":void 0===c?"undefined":c.toString()}function f(a,b){for(var c="",d=0;d=0&&setTimeout(function(){a.restoreContext()},v)},0)}},a.restoreContext=function(){q&&o.length&&setTimeout(function(){if(!u)throw"can not restore. webglcontestlost listener did not call event.preventDefault";h(),i(l),q=!1,t=0,u=!1;for(var a=o.slice(),b=j("context restored"),c=0;c0?a.FS_MAX_FLOAT_PRECISION="highp":c.getShaderPrecisionFormat(c.FRAGMENT_SHADER,c.MEDIUM_FLOAT).precision>0?a.FS_MAX_FLOAT_PRECISION="mediump":a.FS_MAX_FLOAT_PRECISION="lowp":a.FS_MAX_FLOAT_PRECISION="mediump",a.DEPTH_BUFFER_BITS=c.getParameter(c.DEPTH_BITS),a.MAX_TEXTURE_SIZE=c.getParameter(c.MAX_TEXTURE_SIZE),a.MAX_CUBE_MAP_SIZE=c.getParameter(c.MAX_CUBE_MAP_TEXTURE_SIZE),a.MAX_RENDERBUFFER_SIZE=c.getParameter(c.MAX_RENDERBUFFER_SIZE),a.MAX_TEXTURE_UNITS=c.getParameter(c.MAX_COMBINED_TEXTURE_IMAGE_UNITS),a.MAX_VERTEX_ATTRIBS=c.getParameter(c.MAX_VERTEX_ATTRIBS),a.MAX_VERTEX_UNIFORM_VECTORS=c.getParameter(c.MAX_VERTEX_UNIFORM_VECTORS),a.MAX_FRAGMENT_UNIFORM_VECTORS=c.getParameter(c.MAX_FRAGMENT_UNIFORM_VECTORS),a.MAX_VARYING_VECTORS=c.getParameter(c.MAX_VARYING_VECTORS),a.SUPPORTED_EXTENSIONS={},c.getSupportedExtensions().forEach(function(b){a.SUPPORTED_EXTENSIONS[b]=!0}),a):a}(),this.publish=function(a,b,c){c||(this._topicPubs[a]=b);var d=this._topicSubs[a];if(d)for(var e in d)d.hasOwnProperty(e)&&d[e].call(this,b)},this.unpublish=function(a){var b=this._topicSubs[a];if(b)for(var c in b)b.hasOwnProperty(c)&&b[c].call(this,null);delete this._topicPubs[a]},this.on=function(a,b){var c=this._topicSubs[a];c||(c={},this._topicSubs[a]=c);var d=this._handleMap.addItem();c[d]=b,this._handleTopics[d]=a;var e=this._topicPubs[a];return e&&b.call(this,e),d},this.off=function(a){var b=this._handleTopics[a];if(b){delete this._handleTopics[a];var c=this._topicSubs[b];c&&delete c[a],this._handleMap.removeItem(a),"rendered"==b&&this._engine.branchDirty(this)}},this.once=function(a,b){var c=this,d=this.on(a,function(a){c.off(d),b(a)})},this.createScene=function(a,b){if(a=a||{},a.id){if(this._engines[a.id])throw SceneJS_error.fatalError(SceneJS.errors.ILLEGAL_NODE_CONFIG,"Scene already exists with this ID: '"+a.id+"'");this._engineIds.addItem(a.id,{})}else a.id=this._engineIds.addItem({});var c=new SceneJS_Engine(a,b);return this._engines[a.id]=c,SceneJS_events.fireEvent(SceneJS_events.SCENE_CREATED,{engine:c}),c.scene.start(b),c.scene},this.scene=function(a){var b=this._engines[a];return b?b.scene:null},this.getScene=function(a){if(!a)for(var a in this._engines)if(this._engines.hasOwnProperty(a))return this._engines[a].scene;var b=this._engines[a];return b?b.scene:null},this.getScenes=function(){var a={};for(var b in this._engines)this._engines.hasOwnProperty(b)&&(a[b]=this._engines[b].scene);return a},this._isArray=function(a){return a&&!a.propertyIsEnumerable("length")&&"object"==typeof a&&"number"==typeof a.length},this._shallowClone=function(a){var b={};for(var c in a)a.hasOwnProperty(c)&&(b[c]=a[c]);return b},this._applyIf=function(a,b){for(var c in a)a.hasOwnProperty(c)&&(void 0!=b[c]&&null!=b[c]||(b[c]=a[c]));return b},this._apply=function(a,b,c){var d;if(c)for(d in b)b.hasOwnProperty(d)&&delete b[d];for(d in a)a.hasOwnProperty(d)&&void 0!=a[d]&&(b[d]=a[d]);return b};var a=Object.prototype.hasOwnProperty;this._isEmpty=function(b){if(null==b)return!0;if(b.length>0)return!1;if(0===b.length)return!0;for(var c in b)if(a.call(b,c))return!1;return!0},this._isNumeric=function(a){return!isNaN(parseFloat(a))&&isFinite(a)},this._sliceArray=function(a,b,c){if(a.slice)return a.slice(b,c);b=b||0,c=c||a.length;for(var d=c-b,e=new a.constructor(d),f=0;f0;)a.pop().destroy();SceneJS_events.fireEvent(SceneJS_events.RESET)}};!function(){var a;SceneJS.on("configs",function(b){if(b.pluginPath!=a){a=b.pluginPath;var c=a+"/lib";require.config({paths:{scenejsPluginDeps:c}})}})}();var SceneJS_eventManager=function(){this._handlerIds=new SceneJS_Map,this.typeHandlers={}};SceneJS_eventManager.prototype.createEvent=function(a){this.typeHandlers[a]||(this.typeHandlers[a]={handlers:{},numSubs:0})},SceneJS_eventManager.prototype.onEvent=function(a,b){var c=this.typeHandlers[a]||(this.typeHandlers[a]={handlers:{},numSubs:0}),d=this._handlerIds.addItem(a),e=c.handlers;return e[d]=b,c.numSubs++,d},SceneJS_eventManager.prototype.fireEvent=function(a,b){var c=this.typeHandlers[a]||(this.typeHandlers[a]={handlers:{},numSubs:0});if(c.numSubs>0){var d=c.handlers;for(var e in d)d.hasOwnProperty(e)&&d[e](b)}},SceneJS_eventManager.prototype.unEvent=function(a){var b=this._handlerIds.items[a];if(b){this._handlerIds.removeItem(a);var c=this.typeHandlers[b];c&&(delete c[a],this.typeHandlers[b].numSubs--)}},SceneJS.Plugins=new function(){function a(a,c,f,g){var h=d[a]||(d[a]={});h[c]=g,b(f,0,function(){for(var b=a+c,d=e[b]||(e[b]=[]);d.length>0;)d.pop()(g);delete e[b]})}function b(a,d,e){if(!a||d>=a.length)return void e();var f=a[d],g=SceneJS_configsModule.configs.pluginPath;if(!g)throw"no pluginPath config";f=g+"/"+f,c(f,function(){b(a,d+1,e)})}function c(a,b){var c=document.createElement("script");c.type="text/javascript",c.readyState?c.onreadystatechange=function(){"loaded"!=c.readyState&&"complete"!=c.readyState||(c.onreadystatechange=null,b&&b())}:c.onload=function(){b&&b()},c.src=a,document.getElementsByTagName("head")[0].appendChild(c)}var d={},e={};this.addPlugin=function(){var b,c,d=arguments[0],e=arguments[1];4==arguments.length?(b=arguments[2],c=arguments[3]):c=arguments[2],a(d,e,b,c)},this.hasPlugin=function(a,b){var c=d[a];return c&&!!c[b]},this.getPlugin=function(a,b,f){var g=d[a];if(g){var h=g[b];if(h)return void f(h)}var i=a+b,j=e[i]||(e[i]=[]);if(j.push(f),!(j.length>1)){var k=SceneJS_configsModule.configs.pluginPath;if(!k)throw"no pluginPath config";var l=k+"/"+a+"/"+b+".js";c(l)}}};var SceneJS_events=new function(){this.ERROR=0,this.RESET=1,this.NODE_CREATED=2,this.SCENE_CREATED=3,this.SCENE_COMPILING=4,this.SCENE_DESTROYED=5,this.OBJECT_COMPILING=6,this.WEBGL_CONTEXT_LOST=7,this.WEBGL_CONTEXT_RESTORED=8,this.RENDER=9;var a=[];this.addListener=function(b,c,d){var e=a[b];e||(e=[],a[b]=e);for(var f={command:c,priority:void 0==d?e.length:d},g=-1,h=0,i=e.length;h',e.appendChild(f)}var h=document.getElementById(b);if(!h)throw SceneJS_error.fatalError(SceneJS.errors.CANVAS_NOT_FOUND,"SceneJS.Scene attribute 'canvasId' does not match any elements in the page");this.canvasId=b,this.options=d||{},this.canvas=this.options.simulateWebGLContextLost?WebGLDebugUtils.makeLostContextSimulatingCanvas(h):h,this.resolutionScaling=this.options.resolutionScaling||1,this.canvas.width=this.canvas.clientWidth*this.resolutionScaling,this.canvas.height=this.canvas.clientHeight*this.resolutionScaling,this.contextAttr=c||{},this.contextAttr.depth=!0,this.contextAttr.alpha=!0,this.contextAttr.preserveDrawingbuffer=!1,this.contextAttr.stencil=!0,this.gl=null,this.webgl2=!1,this.initWebGL()};SceneJS_Canvas.prototype._WEBGL_CONTEXT_NAMES=["webgl","experimental-webgl","webkit-3d","moz-webgl","moz-glweb20"],SceneJS_Canvas.prototype.initWebGL=function(){if(this.options.webgl2!==!1){try{this.gl=this.canvas.getContext("webgl2",this.contextAttr)}catch(a){}this.gl?this.webgl2=!0:console.log("Failed to get a WebGL 2 context - defaulting to WebGL 1.")}if(!this.gl)for(var b=0;!this.gl&&b0;)--this._numNodesToDestroy,a=this._nodesToDestroy[this._numNodesToDestroy],this._nodesToDestroy[this._numNodesToDestroy]=null,a._doDestroy(),this._coreFactory.putCore(a._core),this._nodeFactory.putNode(a)},SceneJS_Engine.prototype.findNode=function(a){return this._nodeFactory.nodes.items[a]},SceneJS_Engine.prototype.findNodes=function(a){var b=new RegExp(a),c=[],d=this._nodeFactory.nodes.items;for(var e in d)d.hasOwnProperty(e)&&b.test(e)&&c.push(d[e]);return c},SceneJS_Engine.prototype.hasCore=function(a,b){return this._coreFactory.hasCore(a,b)},SceneJS_Engine.prototype.branchDirty=function(a){if(!this.sceneDirty&&a!=window){a.branchDirty=!0,a.dirty=!0;for(var b=a.parent;b&&!b.dirty&&!b.branchDirty;b=b.parent)b.dirty=!0;this._sceneBranchesDirty=!0}},SceneJS_Engine.prototype.renderFrame=function(a){var b=!1;if(this._needCompile()||a&&a.force)for(var c=Date.now(),d=a&&a.force,e=0;e0&&(e=d-r,f=1e3/e,u+=f,s.push(f),s.length>=t&&(u-=s.shift()),g.stats.frame.fps=Math.round(u/s.length));for(var a=0;a0?requestAnimationFrame(a):a()}g.running&&(g.fps>0?setTimeout(window[h],1e3/g.fps):requestAnimationFrame(window[h]))},setTimeout(window[h],0)}},SceneJS_Engine.prototype.pick=function(a){this._needCompile()&&this.compile();var b=this.display.pick({pickTriangle:!!a&&a.rayPick,pickRegion:!!a&&a.regionPick,canvasPos:a.canvasPos,origin:a.origin,direction:a.direction});return b},SceneJS_Engine.prototype.readPixels=function(a,b,c){return this._needCompile()&&this.compile(),this.display.readPixels(a,b,c)},SceneJS_Engine.prototype._needCompile=function(){return this.display.imageDirty||this.display.drawListDirty||this.display.stateSortDirty||this.display.stateOrderDirty||this.display.objectListDirty||this._sceneBranchesDirty||this.sceneDirty},SceneJS_Engine.prototype.pauseCompilation=function(){this._compilationPaused=!0},SceneJS_Engine.prototype.resumeCompilation=function(){this._compilationPaused=!1},SceneJS_Engine.prototype.compile=function(){if(!this._compilationPaused){if(this._sceneBranchesDirty||this.sceneDirty){this._sceneBranchesDirty=!1,SceneJS_events.fireEvent(SceneJS_events.SCENE_COMPILING,{engine:this}),this.pubSubProxy=new SceneJS_PubSubProxy(this.scene,null);var a={pubSubProxy:this.pubSubProxy};this.scene._compileNodes(a),this.sceneDirty=!1}this._doDestroyNodes()}},SceneJS_Engine.prototype.setDepthSort=function(a){this.display.setDepthSort(a)},SceneJS_Engine.prototype.pause=function(a){this.paused=a},SceneJS_Engine.prototype.stop=function(){this.running&&(this.running=!1,this.paused=!1,window["__scenejs_sceneLoop"+this.id]=null)},SceneJS_Engine.prototype.destroyNode=function(a){this._nodesToDestroy[this._numNodesToDestroy++]=a;var b=this.sceneStatus.nodes[a.id];b&&(this.sceneStatus.numTasks-=b.numTasks,delete this.sceneStatus.nodes[a.id])},SceneJS_Engine.prototype.destroy=function(){this.destroyed=!0},self.Int32Array||(self.Int32Array=Array,self.Float32Array=Array),function(){for(var a=0,b=["ms","moz","webkit","o"],c=0;c0&&(g=1/g,this.normal[0]=d*g,this.normal[1]=e*g,this.normal[2]=f*g,this.offset*=g)}}},window.SceneJS_math_MAX_DOUBLE=Number.POSITIVE_INFINITY,window.SceneJS_math_MIN_DOUBLE=Number.NEGATIVE_INFINITY,window.SceneJS_math_Box3=function(a,b){this.min=a||[SceneJS_math_MAX_DOUBLE,SceneJS_math_MAX_DOUBLE,SceneJS_math_MAX_DOUBLE],this.max=b||[SceneJS_math_MIN_DOUBLE,SceneJS_math_MIN_DOUBLE,SceneJS_math_MIN_DOUBLE],this.init=function(a,b){return this.min[0]=a[0],this.min[1]=a[1],this.min[2]=a[2],this.max[0]=b[0],this.max[1]=b[1],this.max[2]=b[2],this},this.fromPoints=function(a){for(var b=a.length,c=0;cthis.max[0]&&(this.max[0]=e),f>this.max[1]&&(this.max[1]=f),g>this.max[2]&&(this.max[2]=g)}return this},this.isEmpty=function(){return this.min[0]>=this.max[0]&&this.min[1]>=this.max[1]&&this.min[2]>=this.max[2]},this.getCenter=function(){return[(this.max[0]+this.min[0])/2,(this.max[1]+this.min[1])/2,(this.max[2]+this.min[2])/2]},this.getSize=function(){return[this.max[0]-this.min[0],this.max[1]-this.min[1],this.max[2]-this.min[2]]},this.getFacesAreas=function(){var a=this.size;return[a[1]*a[2],a[0]*a[2],a[0]*a[1]]},this.getSurfaceArea=function(){var a=this.getFacesAreas();return 2*(a[0]+a[1]+a[2])},this.getVolume=function(){var a=this.size;return a[0]*a[1]*a[2]},this.getOffset=function(a){return this.min[0]-=a,this.min[1]-=a,this.min[2]-=a,this.max[0]+=a,this.max[1]+=a,this.max[2]+=a,this}},window.SceneJS_math_AxisBox3=function(a,b){var c=a[0],d=a[1],e=a[2],f=b[0],g=b[1],h=b[2];this.verts=[[c,d,e],[f,d,e],[f,g,e],[c,g,e],[c,d,h],[f,d,h],[f,g,h],[c,g,h]],this.toBox3=function(){for(var a=new SceneJS_math_Box3,b=0;b<8;++b)for(var c=this.verts[b],d=0;d<3;++d)c[d]a.max[d]&&(a.max[d]=c[d])}},window.SceneJS_math_Sphere3=function(a,b){this.center=[a[0],a[1],a[2]],this.radius=b,this.isEmpty=function(){return 0===this.radius},this.surfaceArea=function(){return 4*Math.PI*this.radius*this.radius},this.getVolume=function(){var a=this.radius;return 4/3*Math.PI*a*a*a}},window.SceneJS_math_billboardMat=function(a){var b=[SceneJS_math_getColMat4(a,0),SceneJS_math_getColMat4(a,1),SceneJS_math_getColMat4(a,2)],c=[SceneJS_math_lenVec4(b[0]),SceneJS_math_lenVec4(b[1]),SceneJS_math_lenVec4(b[2])],d=SceneJS_math_mat4();SceneJS_math_rcpVec3(c,d);var e=SceneJS_math_scalingMat4v(c);SceneJS_math_mulVec4Scalar(b[0],d[0]),SceneJS_math_mulVec4Scalar(b[1],d[1]),SceneJS_math_mulVec4Scalar(b[2],d[2]);var f=SceneJS_math_identityMat4();return SceneJS_math_setRowMat4(f,0,b[0]),SceneJS_math_setRowMat4(f,1,b[1]),SceneJS_math_setRowMat4(f,2,b[2]),SceneJS_math_mulMat4(f,e)},window.SceneJS_math_FrustumPlane=function(a,b,c,d){var e=1/Math.sqrt(a*a+b*b+c*c);this.normal=[a*e,b*e,c*e],this.offset=d*e,this.testVertex=[this.normal[0]>=0?1:0,this.normal[1]>=0?1:0,this.normal[2]>=0?1:0]},window.SceneJS_math_OUTSIDE_FRUSTUM=3,window.SceneJS_math_INTERSECT_FRUSTUM=4,window.SceneJS_math_INSIDE_FRUSTUM=5,window.SceneJS_math_Frustum=function(a,b,c){var d=SceneJS_math_mat4();SceneJS_math_mulMat4(b,a,d);var e=d[0],f=d[1],g=d[2],h=d[3],i=d[4],j=d[5],k=d[6],l=d[7],m=d[8],n=d[9],o=d[10],p=d[11],q=d[12],r=d[13],s=d[14],t=d[15],u=[new SceneJS_math_FrustumPlane(h-e,l-i,p-m,t-q),new SceneJS_math_FrustumPlane(h+e,l+i,p+m,t+q),new SceneJS_math_FrustumPlane(h-f,l-j,p-n,t-r),new SceneJS_math_FrustumPlane(h+f,l+j,p+n,t+r),new SceneJS_math_FrustumPlane(h-g,l-k,p-o,t-s),new SceneJS_math_FrustumPlane(h+g,l+k,p+o,t+s)],v=[SceneJS_math_getColMat4(a,0),SceneJS_math_getColMat4(a,1),SceneJS_math_getColMat4(a,2)],w=[SceneJS_math_lenVec4(v[0]),SceneJS_math_lenVec4(v[1]),SceneJS_math_lenVec4(v[2])],x=SceneJS_math_rcpVec3(w),y=SceneJS_math_scalingMat4v(w),z=SceneJS_math_scalingMat4v(x);SceneJS_math_mulVec4Scalar(v[0],x[0]),SceneJS_math_mulVec4Scalar(v[1],x[1]),SceneJS_math_mulVec4Scalar(v[2],x[2]);var A=SceneJS_math_identityMat4();SceneJS_math_setRowMat4(A,0,v[0]),SceneJS_math_setRowMat4(A,1,v[1]),SceneJS_math_setRowMat4(A,2,v[2]),this.matrix||(this.matrix=SceneJS_math_mat4()),SceneJS_math_mulMat4(b,a,this.matrix),this.billboardMatrix||(this.billboardMatrix=SceneJS_math_mat4()),SceneJS_math_mulMat4(z,SceneJS_math_mulMat4(A,y),this.billboardMatrix),this.viewport=c.slice(0,4),this.textAxisBoxIntersection=function(a){for(var b=SceneJS_math_INSIDE_FRUSTUM,c=[a.min,a.max],d=null,e=0;e<6;++e){if(d=u[e],d.normal[0]*c[d.testVertex[0]][0]+d.normal[1]*c[d.testVertex[1]][1]+d.normal[2]*c[d.testVertex[2]][2]+d.offset<0)return SceneJS_math_OUTSIDE_FRUSTUM;d.normal[0]*c[1-d.testVertex[0]][0]+d.normal[1]*c[1-d.testVertex[1]][1]+d.normal[2]*c[1-d.testVertex[2]][2]+d.offset<0&&(b=SceneJS_math_INTERSECT_FRUSTUM); +}catch(a){}if(!this.gl)throw SceneJS_error.fatalError(SceneJS.errors.WEBGL_NOT_SUPPORTED,"Failed to get a WebGL context")},SceneJS_Canvas.prototype.loseWebGLContext=function(){this.options.simulateWebGLContextLost&&this.canvas.loseContext()},SceneJS_Canvas.prototype.setResolutionScaling=function(a){this.resolutionScaling=a,this.canvas.width=this.canvas.clientWidth*a,this.canvas.height=this.canvas.clientHeight*a};var SceneJS_Engine=function(a,b){b=b||{},a.type="scene",this.id=a.id,this._numPasses=a.numPasses||1,this._clearEachPass=!!a.clearEachPass,this.canvas=new SceneJS_Canvas(this.id,a.canvasId,a.contextAttr,b),this.events=new SceneJS_eventManager,this._coreFactory=new SceneJS_CoreFactory,this._nodeFactory=new SceneJS_NodeFactory,this.stats={build:{version:SceneJS.VERSION},client:{browser:navigator&&navigator.userAgent?navigator.userAgent:"n/a"},components:{},memory:{meshes:0,positions:0,colors:0,normals:0,uvs:0,indices:0,textures:0,programs:0},frame:{frameCount:0,fps:0,useProgram:0,setUniform:0,setUniformCacheHits:0,bindTexture:0,bindArray:0,drawElements:0,drawArrays:0,drawChunks:0}},this.display=new SceneJS_Display(this.stats,{canvas:this.canvas,transparent:a.transparent,dof:a.dof,depthSort:b.depthSort}),this.sceneDirty=!1,this._sceneBranchesDirty=!1,this._compilationPaused=!1,this._nodesToDestroy=[],this._numNodesToDestroy=0,this.fps=a.fps||0,this.running=!1,this.paused=!1,this.destroyed=!1,this.sceneStatus={nodes:{},numTasks:0};var c=this,d=a.nodes;a.nodes=null,this.scene=this.createNode(a),d&&(a.nodes=d,this.scene.addNodes(d)),SceneJS_events.addListener(SceneJS_events.RENDER,function(a){c.scene.publish("render",a)}),this.canvas.canvas.addEventListener("webglcontextlost",function(a){a.preventDefault(),c.stop(),SceneJS_events.fireEvent(SceneJS_events.WEBGL_CONTEXT_LOST,{scene:c.scene})},!1),this.canvas.canvas.addEventListener("webglcontextrestored",function(a){c.canvas.initWebGL(),c._coreFactory.webglRestored(),c.display.webglRestored(),SceneJS_events.fireEvent(SceneJS_events.WEBGL_CONTEXT_RESTORED,{scene:c.scene}),c.start()},!1)};SceneJS_Engine.prototype.setNumPasses=function(a){this._numPasses=a},SceneJS_Engine.prototype.setClearEachPass=function(a){this._clearEachPass=a},SceneJS_Engine.prototype.loseWebGLContext=function(){this.canvas.loseWebGLContext()},SceneJS_Engine.prototype.getNodeType=function(a,b){SceneJS_NodeFactory.getNodeType(a,b)},SceneJS_Engine.prototype.hasNodeType=function(a){return!!SceneJS_NodeFactory.nodeTypes[a]},SceneJS_Engine.prototype.createNode=function(a,b){this._doDestroyNodes(),a.type=a.type||"node";var c=this._coreFactory.getCore(a.type,a.coreId),d=this;return this._nodeFactory.getNode(this,a,c,function(c){if(!c._fromPlugin&&a.nodes)for(var e=0,f=0,g=a.nodes.length;f0;)--this._numNodesToDestroy,a=this._nodesToDestroy[this._numNodesToDestroy],this._nodesToDestroy[this._numNodesToDestroy]=null,a._doDestroy(),this._coreFactory.putCore(a._core),this._nodeFactory.putNode(a)},SceneJS_Engine.prototype.findNode=function(a){return this._nodeFactory.nodes.items[a]},SceneJS_Engine.prototype.findNodes=function(a){var b=new RegExp(a),c=[],d=this._nodeFactory.nodes.items;for(var e in d)d.hasOwnProperty(e)&&b.test(e)&&c.push(d[e]);return c},SceneJS_Engine.prototype.hasCore=function(a,b){return this._coreFactory.hasCore(a,b)},SceneJS_Engine.prototype.branchDirty=function(a){if(!this.sceneDirty&&a!=window){a.branchDirty=!0,a.dirty=!0;for(var b=a.parent;b&&!b.dirty&&!b.branchDirty;b=b.parent)b.dirty=!0;this._sceneBranchesDirty=!0}},SceneJS_Engine.prototype.renderFrame=function(a){var b=!1;if(this._needCompile()||a&&a.force)for(var c=Date.now(),d=a&&a.force,e=0;e0&&(e=d-r,0==e?f=0:(f=1e3/e,u+=f,s.push(f)),s.length>=t&&(u-=s.shift()),g.stats.frame.fps=Math.round(u/s.length));for(var a=0;a0?requestAnimationFrame(a):a()}g.running&&(g.fps>0?setTimeout(window[h],1e3/g.fps):requestAnimationFrame(window[h]))},setTimeout(window[h],0)}},SceneJS_Engine.prototype.pick=function(a){this._needCompile()&&this.compile();var b=this.display.pick({pickTriangle:!!a&&a.rayPick,pickRegion:!!a&&a.regionPick,canvasPos:a.canvasPos,origin:a.origin,direction:a.direction});return b},SceneJS_Engine.prototype.readPixels=function(a,b,c){return this._needCompile()&&this.compile(),this.display.readPixels(a,b,c)},SceneJS_Engine.prototype._needCompile=function(){return this.display.imageDirty||this.display.drawListDirty||this.display.stateSortDirty||this.display.stateOrderDirty||this.display.objectListDirty||this._sceneBranchesDirty||this.sceneDirty},SceneJS_Engine.prototype.pauseCompilation=function(){this._compilationPaused=!0},SceneJS_Engine.prototype.resumeCompilation=function(){this._compilationPaused=!1},SceneJS_Engine.prototype.compile=function(){if(!this._compilationPaused){if(this._sceneBranchesDirty||this.sceneDirty){this._sceneBranchesDirty=!1,SceneJS_events.fireEvent(SceneJS_events.SCENE_COMPILING,{engine:this}),this.pubSubProxy=new SceneJS_PubSubProxy(this.scene,null);var a={pubSubProxy:this.pubSubProxy};this.scene._compileNodes(a),this.sceneDirty=!1}this._doDestroyNodes()}},SceneJS_Engine.prototype.setDepthSort=function(a){this.display.setDepthSort(a)},SceneJS_Engine.prototype.pause=function(a){this.paused=a},SceneJS_Engine.prototype.stop=function(){this.running&&(this.running=!1,this.paused=!1,window["__scenejs_sceneLoop"+this.id]=null)},SceneJS_Engine.prototype.destroyNode=function(a){this._nodesToDestroy[this._numNodesToDestroy++]=a;var b=this.sceneStatus.nodes[a.id];b&&(this.sceneStatus.numTasks-=b.numTasks,delete this.sceneStatus.nodes[a.id])},SceneJS_Engine.prototype.destroy=function(){this.destroyed=!0},self.Int32Array||(self.Int32Array=Array,self.Float32Array=Array),function(){for(var a=0,b=["ms","moz","webkit","o"],c=0;c0&&(g=1/g,this.normal[0]=d*g,this.normal[1]=e*g,this.normal[2]=f*g,this.offset*=g)}}},window.SceneJS_math_MAX_DOUBLE=Number.POSITIVE_INFINITY,window.SceneJS_math_MIN_DOUBLE=Number.NEGATIVE_INFINITY,window.SceneJS_math_Box3=function(a,b){this.min=a||[SceneJS_math_MAX_DOUBLE,SceneJS_math_MAX_DOUBLE,SceneJS_math_MAX_DOUBLE],this.max=b||[SceneJS_math_MIN_DOUBLE,SceneJS_math_MIN_DOUBLE,SceneJS_math_MIN_DOUBLE],this.init=function(a,b){return this.min[0]=a[0],this.min[1]=a[1],this.min[2]=a[2],this.max[0]=b[0],this.max[1]=b[1],this.max[2]=b[2],this},this.fromPoints=function(a){for(var b=a.length,c=0;cthis.max[0]&&(this.max[0]=e),f>this.max[1]&&(this.max[1]=f),g>this.max[2]&&(this.max[2]=g)}return this},this.isEmpty=function(){return this.min[0]>=this.max[0]&&this.min[1]>=this.max[1]&&this.min[2]>=this.max[2]},this.getCenter=function(){return[(this.max[0]+this.min[0])/2,(this.max[1]+this.min[1])/2,(this.max[2]+this.min[2])/2]},this.getSize=function(){return[this.max[0]-this.min[0],this.max[1]-this.min[1],this.max[2]-this.min[2]]},this.getFacesAreas=function(){var a=this.size;return[a[1]*a[2],a[0]*a[2],a[0]*a[1]]},this.getSurfaceArea=function(){var a=this.getFacesAreas();return 2*(a[0]+a[1]+a[2])},this.getVolume=function(){var a=this.size;return a[0]*a[1]*a[2]},this.getOffset=function(a){return this.min[0]-=a,this.min[1]-=a,this.min[2]-=a,this.max[0]+=a,this.max[1]+=a,this.max[2]+=a,this}},window.SceneJS_math_AxisBox3=function(a,b){var c=a[0],d=a[1],e=a[2],f=b[0],g=b[1],h=b[2];this.verts=[[c,d,e],[f,d,e],[f,g,e],[c,g,e],[c,d,h],[f,d,h],[f,g,h],[c,g,h]],this.toBox3=function(){for(var a=new SceneJS_math_Box3,b=0;b<8;++b)for(var c=this.verts[b],d=0;d<3;++d)c[d]a.max[d]&&(a.max[d]=c[d])}},window.SceneJS_math_Sphere3=function(a,b){this.center=[a[0],a[1],a[2]],this.radius=b,this.isEmpty=function(){return 0===this.radius},this.surfaceArea=function(){return 4*Math.PI*this.radius*this.radius},this.getVolume=function(){var a=this.radius;return 4/3*Math.PI*a*a*a}},window.SceneJS_math_billboardMat=function(a){var b=[SceneJS_math_getColMat4(a,0),SceneJS_math_getColMat4(a,1),SceneJS_math_getColMat4(a,2)],c=[SceneJS_math_lenVec4(b[0]),SceneJS_math_lenVec4(b[1]),SceneJS_math_lenVec4(b[2])],d=SceneJS_math_mat4();SceneJS_math_rcpVec3(c,d);var e=SceneJS_math_scalingMat4v(c);SceneJS_math_mulVec4Scalar(b[0],d[0]),SceneJS_math_mulVec4Scalar(b[1],d[1]),SceneJS_math_mulVec4Scalar(b[2],d[2]);var f=SceneJS_math_identityMat4();return SceneJS_math_setRowMat4(f,0,b[0]),SceneJS_math_setRowMat4(f,1,b[1]),SceneJS_math_setRowMat4(f,2,b[2]),SceneJS_math_mulMat4(f,e)},window.SceneJS_math_FrustumPlane=function(a,b,c,d){var e=1/Math.sqrt(a*a+b*b+c*c);this.normal=[a*e,b*e,c*e],this.offset=d*e,this.testVertex=[this.normal[0]>=0?1:0,this.normal[1]>=0?1:0,this.normal[2]>=0?1:0]},window.SceneJS_math_OUTSIDE_FRUSTUM=3,window.SceneJS_math_INTERSECT_FRUSTUM=4,window.SceneJS_math_INSIDE_FRUSTUM=5,window.SceneJS_math_Frustum=function(a,b,c){var d=SceneJS_math_mat4();SceneJS_math_mulMat4(b,a,d);var e=d[0],f=d[1],g=d[2],h=d[3],i=d[4],j=d[5],k=d[6],l=d[7],m=d[8],n=d[9],o=d[10],p=d[11],q=d[12],r=d[13],s=d[14],t=d[15],u=[new SceneJS_math_FrustumPlane(h-e,l-i,p-m,t-q),new SceneJS_math_FrustumPlane(h+e,l+i,p+m,t+q),new SceneJS_math_FrustumPlane(h-f,l-j,p-n,t-r),new SceneJS_math_FrustumPlane(h+f,l+j,p+n,t+r),new SceneJS_math_FrustumPlane(h-g,l-k,p-o,t-s),new SceneJS_math_FrustumPlane(h+g,l+k,p+o,t+s)],v=[SceneJS_math_getColMat4(a,0),SceneJS_math_getColMat4(a,1),SceneJS_math_getColMat4(a,2)],w=[SceneJS_math_lenVec4(v[0]),SceneJS_math_lenVec4(v[1]),SceneJS_math_lenVec4(v[2])],x=SceneJS_math_rcpVec3(w),y=SceneJS_math_scalingMat4v(w),z=SceneJS_math_scalingMat4v(x);SceneJS_math_mulVec4Scalar(v[0],x[0]),SceneJS_math_mulVec4Scalar(v[1],x[1]),SceneJS_math_mulVec4Scalar(v[2],x[2]);var A=SceneJS_math_identityMat4();SceneJS_math_setRowMat4(A,0,v[0]),SceneJS_math_setRowMat4(A,1,v[1]),SceneJS_math_setRowMat4(A,2,v[2]),this.matrix||(this.matrix=SceneJS_math_mat4()),SceneJS_math_mulMat4(b,a,this.matrix),this.billboardMatrix||(this.billboardMatrix=SceneJS_math_mat4()),SceneJS_math_mulMat4(z,SceneJS_math_mulMat4(A,y),this.billboardMatrix),this.viewport=c.slice(0,4),this.textAxisBoxIntersection=function(a){for(var b=SceneJS_math_INSIDE_FRUSTUM,c=[a.min,a.max],d=null,e=0;e<6;++e){if(d=u[e],d.normal[0]*c[d.testVertex[0]][0]+d.normal[1]*c[d.testVertex[1]][1]+d.normal[2]*c[d.testVertex[2]][2]+d.offset<0)return SceneJS_math_OUTSIDE_FRUSTUM;d.normal[0]*c[1-d.testVertex[0]][0]+d.normal[1]*c[1-d.testVertex[1]][1]+d.normal[2]*c[1-d.testVertex[2]][2]+d.offset<0&&(b=SceneJS_math_INTERSECT_FRUSTUM); }return b},this.getProjectedSize=function(a){var b=SceneJS_math_mat4();SceneJS_math_subVec3(a.max,a.min,b);var d=SceneJS_math_lenVec3(b),e=Math.abs(d),f=[.5*(a.min[0]+a.max[0]),.5*(a.min[1]+a.max[1]),.5*(a.min[2]+a.max[2]),0],g=.5*e,h=[-g,0,0,1],i=[g,0,0,1];return h=SceneJS_math_mulMat4v4(this.billboardMatrix,h),h=SceneJS_math_addVec4(h,f),h=SceneJS_math_projectVec4(SceneJS_math_mulMat4v4(this.matrix,h)),i=SceneJS_math_mulMat4v4(this.billboardMatrix,i),i=SceneJS_math_addVec4(i,f),i=SceneJS_math_projectVec4(SceneJS_math_mulMat4v4(this.matrix,i)),c[2]*Math.abs(i[0]-h[0])},this.getProjectedState=function(a){for(var b,d,e,f=SceneJS_math_transformPoints3(this.matrix,a),g=1e7,h=1e7,i=-1e7,j=-1e7,k=f.length,l=0;l.5&&(d=.5),e>.5&&(e=.5),di&&(i=d),e>j&&(j=e);g+=.5,h+=.5,i+=.5,j+=.5;var m=c[2],n=c[3];g*=m+15,h*=n+15,i*=m+15,j*=n+15;var o=SceneJS_math_mat4();SceneJS_math_subVec2([i,j],[g,h],o);var p=SceneJS_math_lenVec2(o);return g<0&&(g=0),i>m&&(i=m),h<0&&(h=0),j>n&&(j=n),{canvasBox:{min:[g,h],max:[i,j]},canvasSize:p}}},window.SceneJS_math_identityQuaternion=function(){return[0,0,0,1]},window.SceneJS_math_angleAxisQuaternion=function(a,b,c,d){var e=d/180*Math.PI,f=e/2,g=Math.sin(f);return[g*a,g*b,g*c,Math.cos(f)]},window.SceneJS_math_mulQuaternions=function(a,b){var c=a[0],d=a[1],e=a[2],f=a[3],g=b[0],h=b[1],i=b[2],j=b[3];return[f*g+c*j+d*i-e*h,f*h+d*j+e*g-c*i,f*i+e*j+c*h-d*g,f*j-c*g-d*h-e*i]},window.SceneJS_math_newMat4FromQuaternion=function(a){var b=a[0],c=a[1],d=a[2],e=a[3],f=2*b,g=2*c,h=2*d,i=f*e,j=g*e,k=h*e,l=f*b,m=g*b,n=h*b,o=g*c,p=h*c,q=h*d,r=SceneJS_math_identityMat4();return SceneJS_math_setCellMat4(r,0,0,1-(o+q)),SceneJS_math_setCellMat4(r,0,1,m-k),SceneJS_math_setCellMat4(r,0,2,n+j),SceneJS_math_setCellMat4(r,1,0,m+k),SceneJS_math_setCellMat4(r,1,1,1-(l+q)),SceneJS_math_setCellMat4(r,1,2,p-i),SceneJS_math_setCellMat4(r,2,0,n-j),SceneJS_math_setCellMat4(r,2,1,p+i),SceneJS_math_setCellMat4(r,2,2,1-(l+o)),r},window.SceneJS_math_slerp=function(a,b,c){var d=.0174532925*b[3],e=.0174532925*c[3],f=d*e+b[0]*c[0]+b[1]*c[1]+b[2]*c[2];if(Math.abs(f)>=1)return[b[0],b[1],b[2],b[3]];var g=Math.acos(f),h=Math.sqrt(1-f*f);if(Math.abs(h)<.001)return[.5*b[0]+.5*c[0],.5*b[1]+.5*c[1],.5*b[2]+.5*c[2],.5*b[3]+.5*c[3]];var i=Math.sin((1-a)*g)/h,j=Math.sin(a*g)/h;return[b[0]*i+c[0]*j,b[1]*i+c[1]*j,b[2]*i+c[2]*j,57.295779579*(d*i+e*j)]},window.SceneJS_math_normalizeQuaternion=function(a){var b=SceneJS_math_lenVec4([a[0],a[1],a[2],a[3]]);return[a[0]/b,a[1]/b,a[2]/b,a[3]/b]},window.SceneJS_math_conjugateQuaternion=function(a){return[-a[0],-a[1],-a[2],a[3]]},window.SceneJS_math_angleAxisFromQuaternion=function(a){a=SceneJS_math_normalizeQuaternion(a);var b=a[3],c=2*Math.acos(b),d=Math.sqrt(1-b*b);return d<.001?{x:a[0],y:a[1],z:a[2],angle:57.295779579*c}:{x:a[0]/d,y:a[1]/d,z:a[2]/d,angle:57.295779579*c}},window.SceneJS_math_getPickPrimitives=function(a,b){for(var c,d,e,f,g,h,i,j,k=b.length,l=new Float32Array(3*k),m=new Float32Array(4*k),n=0,o=0;o>24&255)/255,i=(n>>16&255)/255,h=(n>>8&255)/255,g=(255&n)/255,f=b[o],c=3*f,l[d]=a[c],l[d+1]=a[c+1],l[d+2]=a[c+2],m[e]=g,m[e+1]=h,m[e+2]=i,m[e+3]=j,f=b[o+1],c=3*f,l[d+3]=a[c],l[d+4]=a[c+1],l[d+5]=a[c+2],m[e+4]=g,m[e+5]=h,m[e+6]=i,m[e+7]=j,f=b[o+2],c=3*f,l[d+6]=a[c],l[d+7]=a[c+1],l[d+8]=a[c+2],m[e+8]=g,m[e+9]=h,m[e+10]=i,m[e+11]=j,n++;return{positions:l,colors:m}},window.SceneJS_math_getPickPositions=function(a,b){for(var c,d,e,f=b.length,g=new Float32Array(3*f),h=0;h>24&255)/255,e=(i>>16&255)/255,d=(i>>8&255)/255,c=(255&i)/255,h[b]=c,h[b+1]=d,h[b+2]=e,h[b+3]=f,h[b+4]=c,h[b+5]=d,h[b+6]=e,h[b+7]=f,h[b+8]=c,h[b+9]=d,h[b+10]=e,h[b+11]=f,i++;return h},window.SceneJS_math_rayTriangleIntersect=function(f,g,h,i,j,k){k=k||SceneJS_math_vec3();var l=1e-6,m=SceneJS_math_subVec3(i,h,a),n=SceneJS_math_subVec3(j,h,b),o=SceneJS_math_cross3Vec3(g,n,c),p=SceneJS_math_dotVec3(m,o);if(pp)return null;var s=SceneJS_math_cross3Vec3(q,m,e),t=SceneJS_math_dotVec3(g,s);if(t<0||r+t>p)return null;var u=SceneJS_math_dotVec3(n,s)/p;return k[0]=f[0]+u*g[0],k[1]=f[1]+u*g[1],k[2]=f[2]+u*g[2],k},window.SceneJS_math_rayPlaneIntersect=function(e,f,g,h,i,j){j=j||SceneJS_math_vec3(),f=SceneJS_math_normalizeVec3(f,a);var k=SceneJS_math_subVec3(h,g,b),l=SceneJS_math_subVec3(i,g,c),m=SceneJS_math_cross3Vec3(k,l,d);SceneJS_math_normalizeVec3(m,m);var n=-SceneJS_math_dotVec3(g,m),o=-(SceneJS_math_dotVec3(e,m)+n)/SceneJS_math_dotVec3(f,m);return j[0]=e[0]+o*f[0],j[1]=e[1]+o*f[1],j[2]=e[2]+o*f[2],j},window.SceneJS_math_cartesianToBarycentric=function(g,h,i,j,k){var l=SceneJS_math_subVec3(h,g,a),m=SceneJS_math_subVec3(i,g,b),n=SceneJS_math_subVec3(j,g,c),o=SceneJS_math_subVec3(h,i,d),p=SceneJS_math_subVec3(h,j,e),q=SceneJS_math_lenVec3(SceneJS_math_cross3Vec3(o,p,f));return k[0]=SceneJS_math_lenVec3(SceneJS_math_cross3Vec3(m,n,f))/q,k[1]=SceneJS_math_lenVec3(SceneJS_math_cross3Vec3(n,l,f))/q,k[2]=SceneJS_math_lenVec3(SceneJS_math_cross3Vec3(l,m,f))/q,k},window.SceneJS_math_cartesianToBarycentric2=function(d,e,f,g,h){var i=SceneJS_math_subVec3(g,e,a),j=SceneJS_math_subVec3(f,e,b),k=SceneJS_math_subVec3(d,e,c),l=SceneJS_math_dotVector3(i,i),m=SceneJS_math_dotVector3(i,j),n=SceneJS_math_dotVector3(i,k),o=SceneJS_math_dotVector3(j,j),p=SceneJS_math_dotVector3(j,k),q=l*o-m*m;if(0===q)return null;var r=1/q,s=(o*n-m*p)*r,t=(l*p-m*n)*r;return h[0]=1-s-t,h[1]=t,h[2]=s,h},window.SceneJS_math_barycentricInsideTriangle=function(a){var b=a[1],c=a[2];return c>=0&&b>=0&&c+b<1},window.SceneJS_math_barycentricToCartesian=function(a,b,c,d,e){e=e||SceneJS_math_vec3();var f=a[0],g=a[1],h=a[2];return e[0]=b[0]*f+c[0]*g+d[0]*h,e[1]=b[1]*f+c[1]*g+d[1]*h,e[2]=b[2]*f+c[2]*g+d[2]*h,e},window.SceneJS_math_buildTangents=function(h,i,j){for(var k=new Float32Array(h.length),l=0;lthis.length?(this.destroy(),this._allocate(a,a.length)):b||0===b?this.gl.bufferSubData(this.type,b,a):this.gl.bufferData(this.type,a))},SceneJS._webgl.ArrayBuffer.prototype.unbind=function(){this.allocated&&this.gl.bindBuffer(this.type,null)},SceneJS._webgl.ArrayBuffer.prototype.destroy=function(){this.allocated&&(this.gl.deleteBuffer(this.handle),this.handle=null,this.allocated=!1)},SceneJS._webgl.ArrayBuffer.prototype.bind=function(){this.allocated&&this.gl.bindBuffer(this.type,this.handle)},SceneJS._webgl.Attribute=function(a,b,c,d,e,f){this.gl=a,this.location=f,this.bindFloatArrayBuffer=function(b){b&&(b.bind(),a.enableVertexAttribArray(f),a.vertexAttribPointer(f,b.itemSize,a.FLOAT,!1,0,0))}},SceneJS._webgl.Attribute.prototype.bindInterleavedFloatArrayBuffer=function(a,b,c){this.gl.enableVertexAttribArray(this.location),this.gl.vertexAttribPointer(this.location,a,this.gl.FLOAT,!1,b,c)},SceneJS._webgl.enumMap={funcAdd:"FUNC_ADD",funcSubtract:"FUNC_SUBTRACT",funcReverseSubtract:"FUNC_REVERSE_SUBTRACT",zero:"ZERO",one:"ONE",srcColor:"SRC_COLOR",oneMinusSrcColor:"ONE_MINUS_SRC_COLOR",dstColor:"DST_COLOR",oneMinusDstColor:"ONE_MINUS_DST_COLOR",srcAlpha:"SRC_ALPHA",oneMinusSrcAlpha:"ONE_MINUS_SRC_ALPHA",dstAlpha:"DST_ALPHA",oneMinusDstAlpha:"ONE_MINUS_DST_ALPHA",contantColor:"CONSTANT_COLOR",oneMinusConstantColor:"ONE_MINUS_CONSTANT_COLOR",constantAlpha:"CONSTANT_ALPHA",oneMinusConstantAlpha:"ONE_MINUS_CONSTANT_ALPHA",srcAlphaSaturate:"SRC_ALPHA_SATURATE",front:"FRONT",back:"BACK",frontAndBack:"FRONT_AND_BACK",never:"NEVER",less:"LESS",equal:"EQUAL",lequal:"LEQUAL",greater:"GREATER",notequal:"NOTEQUAL",gequal:"GEQUAL",always:"ALWAYS",cw:"CW",ccw:"CCW",linear:"LINEAR",nearest:"NEAREST",linearMipMapNearest:"LINEAR_MIPMAP_NEAREST",nearestMipMapNearest:"NEAREST_MIPMAP_NEAREST",nearestMipMapLinear:"NEAREST_MIPMAP_LINEAR",linearMipMapLinear:"LINEAR_MIPMAP_LINEAR",repeat:"REPEAT",clampToEdge:"CLAMP_TO_EDGE",mirroredRepeat:"MIRRORED_REPEAT",alpha:"ALPHA",rgb:"RGB",rgba:"RGBA",luminance:"LUMINANCE",luminanceAlpha:"LUMINANCE_ALPHA",textureBinding2D:"TEXTURE_BINDING_2D",textureBindingCubeMap:"TEXTURE_BINDING_CUBE_MAP",compareRToTexture:"COMPARE_R_TO_TEXTURE",unsignedByte:"UNSIGNED_BYTE"},SceneJS._webgl.RenderBuffer=function(a){this.allocated=!1,this.canvas=a.canvas,this.gl=a.canvas.gl,this.buf=null,this.bound=!1},SceneJS._webgl.RenderBuffer.prototype.webglRestored=function(a){this.gl=a,this.buf=null,this.allocated=!1,this.bound=!1},SceneJS._webgl.RenderBuffer.prototype.bind=function(){this._touch(),this.bound||(this.gl.bindFramebuffer(this.gl.FRAMEBUFFER,this.buf.framebuf),this.bound=!0)},SceneJS._webgl.RenderBuffer.prototype._touch=function(){var a=this.canvas.canvas.width,b=this.canvas.canvas.height;if(this.buf){if(this.buf.width==a&&this.buf.height==b)return;this.gl.deleteTexture(this.buf.texture),this.gl.deleteFramebuffer(this.buf.framebuf),this.gl.deleteRenderbuffer(this.buf.renderbuf)}if(this.buf={framebuf:this.gl.createFramebuffer(),renderbuf:this.gl.createRenderbuffer(),texture:this.gl.createTexture(),width:a,height:b},this.gl.bindFramebuffer(this.gl.FRAMEBUFFER,this.buf.framebuf),this.gl.bindTexture(this.gl.TEXTURE_2D,this.buf.texture),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_MAG_FILTER,this.gl.NEAREST),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_MIN_FILTER,this.gl.NEAREST),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_WRAP_S,this.gl.CLAMP_TO_EDGE),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_WRAP_T,this.gl.CLAMP_TO_EDGE),this._setTexture(a,b),this.gl.bindRenderbuffer(this.gl.RENDERBUFFER,this.buf.renderbuf),this.gl.renderbufferStorage(this.gl.RENDERBUFFER,this.gl.DEPTH_COMPONENT16,a,b),this.gl.framebufferTexture2D(this.gl.FRAMEBUFFER,this.gl.COLOR_ATTACHMENT0,this.gl.TEXTURE_2D,this.buf.texture,0),this.gl.framebufferRenderbuffer(this.gl.FRAMEBUFFER,this.gl.DEPTH_ATTACHMENT,this.gl.RENDERBUFFER,this.buf.renderbuf),this.gl.bindTexture(this.gl.TEXTURE_2D,null),this.gl.bindRenderbuffer(this.gl.RENDERBUFFER,null),this.gl.bindFramebuffer(this.gl.FRAMEBUFFER,null),this.gl.bindFramebuffer(this.gl.FRAMEBUFFER,this.buf.framebuf),!this.gl.isFramebuffer(this.buf.framebuf))throw SceneJS_error.fatalError(SceneJS.errors.INVALID_FRAMEBUFFER,"Invalid framebuffer");var c=this.gl.checkFramebufferStatus(this.gl.FRAMEBUFFER);switch(c){case this.gl.FRAMEBUFFER_COMPLETE:break;case this.gl.FRAMEBUFFER_INCOMPLETE_ATTACHMENT:throw SceneJS_error.fatalError(SceneJS.errors.ERROR,"Incomplete framebuffer: FRAMEBUFFER_INCOMPLETE_ATTACHMENT");case this.gl.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:throw SceneJS_error.fatalError(SceneJS.errors.ERROR,"Incomplete framebuffer: FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT");case this.gl.FRAMEBUFFER_INCOMPLETE_DIMENSIONS:throw SceneJS_error.fatalError(SceneJS.errors.ERROR,"Incomplete framebuffer: FRAMEBUFFER_INCOMPLETE_DIMENSIONS");case this.gl.FRAMEBUFFER_UNSUPPORTED:throw SceneJS_error.fatalError(SceneJS.errors.ERROR,"Incomplete framebuffer: FRAMEBUFFER_UNSUPPORTED");default:throw SceneJS_error.fatalError(SceneJS.errors.ERROR,"Incomplete framebuffer: "+c)}this.bound=!1},SceneJS._webgl.RenderBuffer.prototype._setTexture=function(a,b){try{this.gl.texImage2D(this.gl.TEXTURE_2D,0,this.gl.RGBA,a,b,0,this.gl.RGBA,this.gl.UNSIGNED_BYTE,null)}catch(c){var d=new WebGLUnsignedByteArray(a*b*3);this.gl.texImage2D(this.gl.TEXTURE_2D,0,this.gl.RGBA,a,b,0,this.gl.RGBA,this.gl.UNSIGNED_BYTE,d)}},SceneJS._webgl.RenderBuffer.prototype.clear=function(){if(!this.bound)throw"Render buffer not bound";this.gl.clear(this.gl.COLOR_BUFFER_BIT|this.gl.DEPTH_BUFFER_BIT),this.gl.disable(this.gl.BLEND)},SceneJS._webgl.RenderBuffer.prototype.read=function(a,b){var c=a,d=this.canvas.canvas.height-b,e=new Uint8Array(4);return this.gl.readPixels(c,d,1,1,this.gl.RGBA,this.gl.UNSIGNED_BYTE,e),e},SceneJS._webgl.RenderBuffer.prototype.unbind=function(){this.gl.bindFramebuffer(this.gl.FRAMEBUFFER,null),this.bound=!1},SceneJS._webgl.RenderBuffer.prototype.getTexture=function(){var a=this;return{bind:function(b){return!(!a.buf||!a.buf.texture)&&(a.gl.activeTexture(a.gl["TEXTURE"+b]),a.gl.bindTexture(a.gl.TEXTURE_2D,a.buf.texture),!0)},unbind:function(b){a.buf&&a.buf.texture&&(a.gl.activeTexture(a.gl["TEXTURE"+b]),a.gl.bindTexture(a.gl.TEXTURE_2D,null))}}},SceneJS._webgl.RenderBuffer.prototype.destroy=function(){this.buf&&(this.gl.deleteTexture(this.buf.texture),this.gl.deleteFramebuffer(this.buf.framebuf),this.gl.deleteRenderbuffer(this.buf.renderbuf),this.buf=null,this.bound=!1)},SceneJS._webgl.Program=function(a,b,c,d){this.stats=a,this.allocated=!1,this.gl=b,this._uniforms={},this._samplers={},this._attributes={},this.materialSettings={specularColor:[0,0,0],specular:0,shine:0,emit:0,alpha:0},this._shaders=[];var e,f,g,h,i,j;for(f=0;fb){var d=b/c,e=a.width*d,f=a.height*d,g=document.createElement("canvas");g.width=SceneJS._webgl.nextHighestPowerOfTwo(e),g.height=SceneJS._webgl.nextHighestPowerOfTwo(f);var h=g.getContext("2d");h.drawImage(a,0,0,a.width,a.height,0,0,g.width,g.height),a=g}return a},SceneJS._webgl.ensureImageSizePowerOfTwo=function(a){if(!SceneJS._webgl.isPowerOfTwo(a.width)||!SceneJS._webgl.isPowerOfTwo(a.height)){var b=document.createElement("canvas");b.width=SceneJS._webgl.nextHighestPowerOfTwo(a.width),b.height=SceneJS._webgl.nextHighestPowerOfTwo(a.height);var c=b.getContext("2d");c.drawImage(a,0,0,a.width,a.height,0,0,b.width,b.height),a=b}return a},SceneJS._webgl.isPowerOfTwo=function(a){return 0==(a&a-1)},SceneJS._webgl.nextHighestPowerOfTwo=function(a){--a;for(var b=1;b<32;b<<=1)a|=a>>b;return a+1},SceneJS._webgl.Uniform=function(a,b,c,d,e,f,g,h,i){var j=null,k=null;if(e===b.BOOL)j=function(c){return k===c?void a.setUniformCacheHits++:(k=c,b.uniform1i(g,c),void a.setUniform++)};else if(e===b.BOOL_VEC2)k=new Array(2),j=function(c){return k[0]===c[0]&&k[1]===c[1]?void a.setUniformCacheHits++:(k[0]=c[0],k[1]=c[1],b.uniform2iv(g,c),void a.setUniform++)};else if(e===b.BOOL_VEC3)k=new Array(3),j=function(c){return k[0]===c[0]&&k[1]===c[1]&&k[2]===c[2]?void a.setUniformCacheHits++:(k[0]=c[0],k[1]=c[1],k[2]=c[2],b.uniform3iv(g,c),void a.setUniform++)};else if(e===b.BOOL_VEC4)k=new Array(4),j=function(c){return k[0]===c[0]&&k[1]===c[1]&&k[2]===c[2]&&k[3]===c[3]?void a.setUniformCacheHits++:(k[0]=c[0],k[1]=c[1],k[2]=c[2],k[3]=c[3],b.uniform4iv(g,c),void a.setUniform++)};else if(e===b.INT)j=function(c){return k===c?void a.setUniformCacheHits++:(k=c,b.uniform1iv(g,c),void a.setUniform++)};else if(e===b.INT_VEC2)k=new Uint32Array(2),j=function(c){return k[0]===c[0]&&k[1]===c[1]?void a.setUniformCacheHits++:(k.set(c),b.uniform2iv(g,c),void a.setUniform++)};else if(e===b.INT_VEC3)k=new Uint32Array(3),j=function(c){return k[0]===c[0]&&k[1]===c[1]&&k[2]===c[2]?void a.setUniformCacheHits++:(k.set(c),b.uniform3iv(g,c),void a.setUniform++)};else if(e===b.INT_VEC4)k=new Uint32Array(4),j=function(c){return k[0]===c[0]&&k[1]===c[1]&&k[2]===c[2]&&k[3]===c[3]?void a.setUniformCacheHits++:(k.set(c),b.uniform4iv(g,c),void a.setUniform++)};else if(e===b.FLOAT)j=function(c){return k===c?void a.setUniformCacheHits++:(k=c,b.uniform1f(g,c),void a.setUniform++)};else if(e===b.FLOAT_VEC2)k=new Float32Array(2),j=function(c){return k[0]===c[0]&&k[1]===c[1]?void a.setUniformCacheHits++:(k.set(c),b.uniform2fv(g,c),void a.setUniform++)};else if(e===b.FLOAT_VEC3)k=new Float32Array(3),j=function(c){return k[0]===c[0]&&k[1]===c[1]&&k[2]===c[2]?void a.setUniformCacheHits++:(k.set(c),b.uniform3fv(g,c),void a.setUniform++)};else if(e===b.FLOAT_VEC4)k=new Float32Array(4),j=function(c){return k[0]===c[0]&&k[1]===c[1]&&k[2]===c[2]&&k[3]===c[3]?void a.setUniformCacheHits++:(k.set(c),b.uniform4fv(g,c),void a.setUniform++)};else if(e===b.FLOAT_MAT2)j=function(c){b.uniformMatrix2fv(g,b.FALSE,c),a.setUniform++};else if(e===b.FLOAT_MAT3)j=function(c){b.uniformMatrix3fv(g,b.FALSE,c),a.setUniform++};else{if(e!==b.FLOAT_MAT4)throw"Unsupported shader uniform type: "+e;j=function(c){b.uniformMatrix4fv(g,b.FALSE,c),a.setUniform++}}this.setValue=j,this.getLocation=function(){return g},this.index=h};var SceneJS_nodeEventsModule=new function(){var a,b=[],c=[],d=0,e={type:"listeners",stateId:SceneJS._baseStateId++,empty:!0,listeners:[]};SceneJS_events.addListener(SceneJS_events.SCENE_COMPILING,function(){d=0,a=!0}),SceneJS_events.addListener(SceneJS_events.OBJECT_COMPILING,function(f){if(a){if(d>0){var g={type:"listeners",stateId:b[d-1],listeners:c.slice(0,d)};f.display.renderListeners=g}else f.display.renderListeners=e;a=!1}}),this.preVisitNode=function(e){var f=e._topicSubs.rendered,g=e._topicSubs.worldPos,h=e._topicSubs.viewPos,i=e._topicSubs.cameraPos,j=e._topicSubs.projPos,k=e._topicSubs.canvasPos;(f||g||h||i||j||k)&&(b[d]=e.id,c[d]=function(a){f&&e.publish("rendered",a,!0),g&&e.publish("worldPos",a.getWorldPos()),h&&e.publish("viewPos",a.getViewPos()),i&&e.publish("cameraPos",a.getCameraPos()),j&&e.publish("projPos",a.getProjPos()),k&&e.publish("canvasPos",a.getCanvasPos())},d++,a=!0)},this.postVisitNode=function(c){c.id==b[d-1]&&(d--,a=!0)}},SceneJS_Core=function(a){this.type=a,this.coreId=null,this.stateId=null,this.useCount=0},SceneJS_CoreFactory=function(){this._stateMap=new SceneJS_Map(null,SceneJS._baseStateId),this._cores={}};SceneJS_CoreFactory.coreTypes={},SceneJS_CoreFactory.createCoreType=function(a,b){},SceneJS_CoreFactory.addCoreBuilder=function(a,b){},SceneJS_CoreFactory.coreAliases={rotate:"xform",translate:"xform",scale:"xform",matrix:"xform",xform:"xform"},SceneJS_CoreFactory.prototype.getCore=function(a,b){var c=SceneJS_CoreFactory.coreAliases[a];c&&(a=c);var d=this._cores[a];d||(d=this._cores[a]={});var e;return b&&(e=d[b])?(e.useCount++,e):(e=new SceneJS_Core(a),e.useCount=1,e.stateId=this._stateMap.addItem(e),e.coreId=void 0!=b&&null!=b?b:e.stateId,d[e.coreId]=e,e)},SceneJS_CoreFactory.prototype.hasCore=function(a,b){var c=SceneJS_CoreFactory.coreAliases[a];c&&(a=c);var d=this._cores[a];return d&&d[b]},SceneJS_CoreFactory.prototype.putCore=function(a){if(0!=a.useCount&&--a.useCount<=0){var b=this._cores[a.type];delete b[a.coreId],this._stateMap.removeItem(a.stateId)}},SceneJS_CoreFactory.prototype.webglRestored=function(){var a,b;for(var c in this._cores)if(this._cores.hasOwnProperty(c)&&(a=this._cores[c]))for(var d in a)a.hasOwnProperty(d)&&(b=a[d],b&&b.webglRestored&&b.webglRestored())},SceneJS.Node=function(){},SceneJS.Node.prototype.constructor=SceneJS.Node,SceneJS.Node.prototype._construct=function(a,b,c,d){this._engine=a,this._core=b,this.coreId=b.coreId,this.id=c.id||c.nodeId||d,this.type=c.type||"node",this.data=c.data,this.parent=null,this.nodes=[],this._handleMap=new SceneJS_Map,this._topicSubs={},this._handleTopics={},this._topicPubs={},this._listeners={},this._numListeners=0,this.dirty=!1,this.branchDirty=!1,this._init&&this._init(c)},SceneJS.Node.prototype.taskStarted=function(a){return SceneJS_sceneStatusModule.taskStarted(this,a||"Task")},SceneJS.Node.prototype.taskFinished=function(a){return SceneJS_sceneStatusModule.taskFinished(a)},SceneJS.Node.prototype.taskFailed=function(a){return SceneJS_sceneStatusModule.taskFailed(a)},SceneJS.Node.prototype.log=function(){var a,b;switch(1==arguments.length?(a="info",b=arguments[0]):2==arguments.length&&(a=arguments[0],b=arguments[1]),a){case"warn":b="WARN; [SceneJS.Node type="+this.type+", id="+this.id+"] : "+b;break;case"error":b="ERROR; [SceneJS.Node type="+this.type+", id="+this.id+"] : "+b;break;default:b="INFO; [SceneJS.Node type="+this.type+", id="+this.id+"] : "+b}console[a]?console[a](b):console.log(b)},SceneJS.Node.prototype.publish=function(a,b,c){if(c||(this._topicPubs[a]=b),this._topicSubs[a]){var d=this._topicSubs[a];for(var e in d)d.hasOwnProperty(e)&&d[e].call(this,b)}},SceneJS.Node.prototype.unpublish=function(a){var b=this._topicSubs[a];if(b)for(var c in b)b.hasOwnProperty(c)&&b[c].call(this,null);delete this._topicPubs[a]},SceneJS.Node.prototype.on=function(a,b){var c=this._topicSubs[a];c||(c={},this._topicSubs[a]=c);var d=this._handleMap.addItem();c[d]=b,this._handleTopics[d]=a;var e=this._topicPubs[a];return e&&b.call(this,e),"rendered"==a&&this._engine.branchDirty(this),d},SceneJS.Node.prototype.off=function(a){var b=this._handleTopics[a];if(b){delete this._handleTopics[a];var c=this._topicSubs[b];c&&delete c[a],this._handleMap.removeItem(a),"rendered"==b&&this._engine.branchDirty(this)}},SceneJS.Node.prototype.once=function(a,b){var c=this,d=this.on(a,function(a){c.off(d),b(a)})},SceneJS.Node.prototype.getScene=function(){return this._engine.scene},SceneJS.Node.prototype.getCoreId=function(){return this._core.coreId},SceneJS.Node.prototype.getID=function(){return this.id},SceneJS.Node.prototype.getId=function(){return this.id},SceneJS.Node.prototype.getNodeId=function(){return this.id},SceneJS.Node.prototype.getType=function(){return this.type},SceneJS.Node.prototype.getData=function(){return this.data},SceneJS.Node.prototype.setData=function(a){return this.data=a,this},SceneJS.Node.prototype.getNumNodes=function(){return this.nodes.length},SceneJS.Node.prototype.getNodes=function(){return this.nodes.slice(0)},SceneJS.Node.prototype.getNodeAt=function(a){return a<0||a>=this.nodes.length?null:this.nodes[a]},SceneJS.Node.prototype.getFirstNode=function(){return 0==this.nodes.length?null:this.nodes[0]},SceneJS.Node.prototype.getLastNode=function(){return 0==this.nodes.length?null:this.nodes[this.nodes.length-1]},SceneJS.Node.prototype.getNode=function(a){for(var b=0;b0?(b[0]._disconnectFromScene(),b[0].parent=null,this._engine.branchDirty(this),b[0]):null},SceneJS.Node.prototype.disconnect=function(){if(this.parent){for(var a=0;a=0;f--){var g=a[f];if("node"==g.type||this._engine.hasNodeType(g.type)){if(c=this.addNode(g),d[f]=c,0==--e)return b&&b(a),a}else{var h=this;!function(){var c=f;h.addNode(g,function(f){d[c]=f,0==--e&&b&&b(a)})}()}}return null},SceneJS.Node.prototype.addNode=function(a,b){if(a=a||{},a._compile){if(null!=a.parent)throw SceneJS_error.fatalError(SceneJS.errors.ILLEGAL_NODE_CONFIG,"Node#addNode - node argument is still attached to another parent");return this.nodes.push(a),a.parent=this,a._connectToScene(),this._engine.branchDirty(a),b&&b(a),a}if("string"==typeof a){var c=this._engine.findNode(a);if(!c)throw SceneJS_error.fatalError(SceneJS.errors.ILLEGAL_NODE_CONFIG,"Node#addNode - node not found: '"+a+"'");if(a=c,null!=a.parent)throw SceneJS_error.fatalError(SceneJS.errors.ILLEGAL_NODE_CONFIG,"Node#addNode - node argument is still attached to another parent");return this.nodes.push(a),a.parent=this,a._connectToScene(),this._engine.branchDirty(a),b&&b(a),a}if(a.type=a.type||"node","node"==a.type||this._engine.hasNodeType(a.type))return a=this._engine.createNode(a),this.nodes.push(a),a.parent=this,a._connectToScene(),this._engine.branchDirty(a),b&&b(a),a;var d=this;return this._engine.createNode(a,function(a){d.nodes.push(a),a.parent=d,a._connectToScene(),d._engine.branchDirty(a),b&&b(a)}),null},SceneJS.Node.prototype.insertNode=function(a,b){if(!a)throw SceneJS_error.fatalError(SceneJS.errors.ILLEGAL_NODE_CONFIG,"SceneJS.Node#insertNode - node argument is undefined");if(a._compile||(a=this._engine.createNode(a)),!a._compile)throw SceneJS_error.fatalError(SceneJS.errors.ILLEGAL_NODE_CONFIG,"SceneJS.Node#insertNode - node argument is not a SceneJS.Node");if(null!=a.parent)throw SceneJS_error.fatalError(SceneJS.errors.ILLEGAL_NODE_CONFIG,"SceneJS.Node#insertNode - node argument is still attached to another parent");if(void 0===b||null===b)a.addNodes(this.disconnectNodes()),this.addNode(a);else{if(b<0)throw SceneJS_error.fatalError(SceneJS.errors.ILLEGAL_NODE_CONFIG,"SceneJS.Node#insertNode - node index out of range: -1");b>=this.nodes.length?this.nodes.push(a):this.nodes.splice(b,0,a)}return a.parent=this,a._connectToScene(),a},SceneJS.Node.prototype.mapNodes=function(a){if(a(this))return this;for(var b,c=0;c0},SceneJS.Node.prototype.removeListeners=function(){return this._listeners={},this._numListeners=0,this},SceneJS.Node.prototype.getParent=function(a){return this.parent},SceneJS.Node.prototype.getParentOfType=function(a){for(var b=this.parent;b&&b.type!=a;)b=b.parent;return b},SceneJS.Node.prototype.eachParent=function(a){if(!a)throw"SceneJS.Node.eachParent param 'fn' is null or undefined";for(var b=0,c=this;c.parent;){if(a.call(c.parent,b++)===!0)return c.parent;c=c.parent}return null},SceneJS.Node.prototype.hasNode=function(a){if(null===a||void 0===a)throw"SceneJS.Node.hasNode param 'node' is null or undefined";var b,c=typeof a;if("number"==c)b=this.getNodeAt(a);else{if("string"!=c)throw"SceneJS.Node.hasNode param 'node' should be either an index number or an ID string";b=this.getNode(a)}return void 0!=b&&null!=b},SceneJS.Node.prototype.node=function(a){if(null===a||void 0===a)throw"SceneJS.Node.node param 'node' is null or undefined";var b,c=typeof a;if("number"==c)b=this.getNodeAt(a);else{if("string"!=c)throw"SceneJS.Node.node param 'node' should be either an index number or an ID string";b=this.getNode(a)}if(!b)throw"SceneJS.Node.node - node not found: '"+a+"'";return b},SceneJS.Node.prototype.eachNode=function(a,b){if(!a)throw"SceneJS.Node.eachNode param 'fn' is null or undefined";if("function"!=typeof a)throw"SceneJS.Node.eachNode param 'fn' should be a function";var c;b=b||{};var d=0;return b.andSelf&&a.call(this,d++)===!0?this:(b.depthFirst||b.breadthFirst?b.depthFirst&&(c=this._iterateEachNodeDepthFirst(a,this,d,!1)):c=this._iterateEachNode(a,this,d),c?c:void 0)},SceneJS.Node.prototype.numNodes=function(){return this.nodes.length},SceneJS.Node.prototype._iterateEachNode=function(a,b,c){for(var d,e=b.nodes.length,f=0;f0;)f.pop()(e);delete f[a]}return d},SceneJS_NodeFactory.prototype.getNode=function(a,b,c,d){b.type=b.type||"node";var e;if(e="node"==b.type?SceneJS.Node:SceneJS_NodeFactory.nodeTypes[b.type])return this._createNode(e,a,b,c,d);var f=this;this._getType(a,b.type,function(e){f._createNode(e,a,b,c,d)})},SceneJS_NodeFactory.prototype._createNode=function(a,b,c,d,e){var f=new a,g=c.id||c.nodeId;return g?this.nodes.addItem(g,f):g=this.nodes.addItem(f),f._construct(b,d,c,g),e&&e(f),f},SceneJS_NodeFactory.prototype._getType=function(a,b,c){var d=SceneJS_NodeFactory.nodeTypes[b];if(d)return void c(d);var e=SceneJS_NodeFactory._subs[b]||(SceneJS_NodeFactory._subs[b]=[]);if(e.push(c),!(e.length>1)){var f=SceneJS_sceneStatusModule.taskStarted(a.scene,"Loading plugin");e.push(function(){SceneJS_sceneStatusModule.taskFinished(f)});var g=SceneJS_configsModule.configs.pluginPath;if(!g)throw"no typePath config";this._loadScript(g+"/node/"+b+".js",function(){SceneJS_sceneStatusModule.taskFailed(f)})}},SceneJS_NodeFactory.prototype._loadScript=function(a,b){var c=document.createElement("script");c.type="text/javascript",c.src=a,c.onerror=b,document.getElementsByTagName("head")[0].appendChild(c)},SceneJS_NodeFactory.prototype.putNode=function(a){this.nodes.removeItem(a.id)},new function(){var a={type:"billboard",stateId:SceneJS._baseStateId++,empty:!0,hash:""};SceneJS_events.addListener(SceneJS_events.SCENE_COMPILING,function(b){b.engine.display.billboard=a,c=0});var b=[],c=0;SceneJS.Billboard=SceneJS_NodeFactory.createNodeType("billboard"),SceneJS.Billboard.prototype._init=function(a){1==this._core.useCount&&(this._core.spherical=a.spherical!==!1),this._core.hash="bb;"},SceneJS.Billboard.prototype.setSpherical=function(a){this._core.spherical=a,this._engine.branchDirty(this),this._engine.display.imageDirty=!0},SceneJS.Billboard.prototype.getSpherical=function(){return this._core.spherical},SceneJS.Billboard.prototype._compile=function(d){b[c++]=this._core,this._engine.display.billboard=this._core,this._compileNodes(d),this._engine.display.billboard=--c>0?b[c-1]:a},SceneJS.Billboard.prototype._destroy=function(){this._core&&this._engine._coreFactory.putCore(this._core)}},function(){function a(a){var b=a.optics;if("ortho"==b.type?a.matrix=SceneJS_math_orthoMat4c(b.left,b.right,b.bottom,b.top,b.near,b.far):"frustum"==b.type?a.matrix=SceneJS_math_frustumMatrix4(b.left,b.right,b.bottom,b.top,b.near,b.far):"frustumAngles"==b.type?a.matrix=SceneJS_math_frustumMatrix4FromAngles(b.left,b.right,b.down,b.up,b.near,b.far):"perspective"==b.type&&(a.matrix=SceneJS_math_perspectiveMatrix4(b.fovy*Math.PI/180,b.aspect,b.near,b.far)),a.pan){var c=a.pan,d=SceneJS_math_translationMat4v([c.x||0,c.y||0,c.z||0]);a.matrix=SceneJS_math_mulMat4(d,a.matrix,[])}a.mat?a.mat.set(a.matrix):a.mat=new Float32Array(a.matrix)}var b=SceneJS_math_perspectiveMatrix4(45,1,.1,1e4),c=new Float32Array(b),d={type:"camera",stateId:SceneJS._baseStateId++,matrix:b,mat:c,optics:{type:"perspective",fovy:45,aspect:1,near:.1,far:1e4},checkAspect:function(b,c){b.optics.aspect!=c&&(b.optics.aspect=c,a(this))}},e=[],f=0;SceneJS_events.addListener(SceneJS_events.SCENE_COMPILING,function(a){a.engine.display.projTransform=d,f=0}),SceneJS.Camera=SceneJS_NodeFactory.createNodeType("camera"),SceneJS.Camera.prototype._init=function(b){if(1==this._core.useCount){b.optics=b.optics||{};var c=this.getScene().getCanvas();b.optics.aspect=c.width/c.height,this.setOptics(b.optics),b.pan&&this.setPan(b.pan);var d=this;this._canvasSizeSub=this.getScene().on("canvasSize",function(b){d._core.optics.aspect=b.aspect,a(d._core),d._engine.display.imageDirty=!0})}},SceneJS.Camera.getDefaultMatrix=function(){return c},SceneJS.Camera.prototype.setOptics=function(b){var c=this._core;if(b){var d=b.type;if(d||c.optics&&(d=c.optics.type),d=d||"perspective","ortho"==d)c.optics=SceneJS._applyIf(SceneJS_math_ORTHO_OBJ,{type:d,left:b.left,bottom:b.bottom,near:b.near,right:b.right,top:b.top,far:b.far});else if("frustum"==d)c.optics={type:d,left:b.left||-1,bottom:b.bottom||-1,near:b.near||.1,right:b.right||1,top:b.top||1,far:b.far||1e4};else if("frustumAngles"==d)c.optics={type:d,left:b.left||22,down:b.down||22,near:b.near||.1,right:b.right||22,up:b.up||22,far:b.far||1e4};else{if("perspective"!=d)throw b.type?SceneJS_error.fatalError(SceneJS.errors.ILLEGAL_NODE_CONFIG,"SceneJS.Camera configuration invalid: optics type not supported - supported types are 'perspective', 'frustum', 'frustumAngles' and 'ortho'"):SceneJS_error.fatalError(SceneJS.errors.ILLEGAL_NODE_CONFIG,"SceneJS.Camera configuration invalid: optics type not specified - supported types are 'perspective', 'frustum', 'frustumAngles' and 'ortho'");c.optics={type:d,fovy:b.fovy||60,aspect:void 0==b.aspect?1:b.aspect,near:b.near||.1,far:b.far||1e4}}}else c.optics={type:"perspective",fovy:60,aspect:1,near:.1,far:1e4};this._core.optics.pan=b.pan,a(this._core),this.publish("matrix",this._core.matrix),this._engine.display.imageDirty=!0},SceneJS.Camera.prototype.setPan=function(b){this._core.pan=b,a(this._core),this.publish("matrix",this._core.matrix),this._engine.display.imageDirty=!0},SceneJS.Camera.prototype.getOptics=function(){var a={};for(var b in this._core.optics)this._core.optics.hasOwnProperty(b)&&(a[b]=this._core.optics[b]);return a},SceneJS.Camera.prototype.setMatrix=function(a){this._core.matrix=a,this._core.mat=a,this.publish("matrix",this._core.matrix),this._engine.display.imageDirty=!0},SceneJS.Camera.prototype.getMatrix=function(){return SceneJS._sliceArray(this._core.matrix,0)},SceneJS.Camera.prototype._compile=function(a){this._engine.display.projTransform=e[f++]=this._core,this._compileNodes(a),this._engine.display.projTransform=--f>0?e[f-1]:d,e[f]=null},SceneJS.Camera.prototype._destroy=function(){this.getScene().off(this._canvasSizeSub)}}(),function(){var a={type:"clips",stateId:SceneJS._baseStateId++,empty:!0,hash:"",clips:[]},b=[],c=0;SceneJS_events.addListener(SceneJS_events.SCENE_COMPILING,function(b){b.engine.display.clips=a,c=0}),SceneJS.Clips=SceneJS_NodeFactory.createNodeType("clips"),SceneJS.Clips.prototype._init=function(a){if(1==this._core.useCount){var b=a.clips;if(!b)throw SceneJS_error.fatalError(SceneJS.errors.NODE_CONFIG_EXPECTED,"clips node attribute missing : 'clips'");this._core.clips=this._core.clips||[];for(var c=0,d=b.length;c=this._core.clips.length)throw SceneJS_error.fatalError(SceneJS.errors.ILLEGAL_NODE_CONFIG,"Invalid argument to set 'clips': index out of range ("+this._core.clips.length+" clips defined)");this._setClip(b,a[c]||{})}this._engine.display.imageDirty=!0},SceneJS.Clips.prototype._setClip=function(a,b){var c=this._core.clips[a]||(this._core.clips[a]={});c.normalAndDist=[b.x||0,b.y||0,b.z||0,b.dist||0];var d=b.mode||c.mode||"disabled";if("inside"!=d&&"outside"!=d&&"disabled"!=d)throw SceneJS_error.fatalError(SceneJS.errors.ILLEGAL_NODE_CONFIG,"clips node invalid value for property 'mode': should be 'inside' or 'outside' or 'disabled'");c.mode=d,this._core.hash=null},SceneJS.Clips.prototype._compile=function(d){this._core.hash||(this._core.hash=this._core.clips.length),this._engine.display.clips=b[c++]=this._core,this._compileNodes(d),this._engine.display.clips=--c>0?b[c-1]:a,b[c]=null}}(),function(){var a={stateId:SceneJS._baseStateId++,type:"enable",enabled:!0},b=[],c=0;SceneJS_events.addListener(SceneJS_events.SCENE_COMPILING,function(b){b.engine.display.enable=a,c=0}),SceneJS.Enable=SceneJS_NodeFactory.createNodeType("enable"),SceneJS.Enable.prototype._init=function(a){1==this._core.useCount&&(this._core.enabled=!0,void 0!=a.enabled&&this.setEnabled(a.enabled))},SceneJS.Enable.prototype.setEnabled=function(a){return a!==this._core.enabled&&(this._core.enabled=a,this._engine.display.drawListDirty=!0,this.publish("enabled",a)),this},SceneJS.Enable.prototype.getEnabled=function(){return this._core.enabled},SceneJS.Enable.prototype._compile=function(d){this._engine.display.enable=b[c++]=this._core,this._compileNodes(d),this._engine.display.enable=--c>0?b[c-1]:a,b[c]=null}}(),function(){function a(a){return(a.reflective?"refl":"")+";"+(a.solid?"s":"")+";"+(a.skybox?"sky":"")+";"}var b={stateId:SceneJS._baseStateId++,type:"flags",picking:!0,clipping:!0,enabled:!0,transparent:!1,backfaces:!0,frontface:"ccw",reflective:!0,solid:!1,solidColor:[1,1,1],skybox:!1,hash:"refl;;;",clearColorBuffer:!1},c=[],d=0;SceneJS_events.addListener(SceneJS_events.SCENE_COMPILING,function(a){a.engine.display.flags=b,d=0}),SceneJS.Flags=SceneJS_NodeFactory.createNodeType("flags"),SceneJS.Flags.prototype._init=function(a){1==this._core.useCount&&(this._core.picking=!0,this._core.clipping=!0,this._core.enabled=!0,this._core.transparent=!1,this._core.backfaces=!0,this._core.frontface="ccw",this._core.reflective=!0,this._core.solid=!1,this._core.solidColor=[1,1,1],this._core.skybox=!1,a.flags&&this.setFlags(a.flags))},SceneJS.Flags.prototype.setFlags=function(c){var d=this._core;if(void 0!=c.picking&&(d.picking=!!c.picking,this._engine.display.drawListDirty=!0),void 0!=c.clipping&&(d.clipping=!!c.clipping,this._engine.display.imageDirty=!0),void 0!=c.clearColorBuffer&&(d.clearColorBuffer=c.clearColorBuffer,this._engine.display.imageDirty=!0),void 0!=c.enabled&&(d.enabled=!!c.enabled,this._engine.display.drawListDirty=!0),void 0!=c.transparent&&(d.transparent=!!c.transparent,this._engine.display.stateSortDirty=!0),void 0!=c.backfaces&&(d.backfaces=!!c.backfaces,this._engine.display.imageDirty=!0),void 0!=c.frontface&&(d.frontface=c.frontface,this._engine.display.imageDirty=!0),void 0!=c.reflective&&(d.reflective=c.reflective,this._engine.branchDirty(this),this._engine.display.imageDirty=!0),void 0!=c.solid&&(d.solid=c.solid,this._engine.branchDirty(this),this._engine.display.imageDirty=!0),void 0!=c.solidColor){var e=b.solidColor,f=c.solidColor;d.solidColor=f?[void 0!=f.r&&null!=f.r?f.r:e[0],void 0!=f.g&&null!=f.g?f.g:e[1],void 0!=f.b&&null!=f.b?f.b:e[2]]:b.solidColor,this._engine.display.imageDirty=!0}return void 0!=c.skybox&&(d.skybox=c.skybox,this._engine.branchDirty(this),this._engine.display.imageDirty=!0),d.hash=a(d),this},SceneJS.Flags.prototype.getFlags=function(){var a=this._core;return{picking:a.picking,clipping:a.clipping,enabled:a.enabled,transparent:a.transparent,backfaces:a.backfaces,frontface:a.frontface,reflective:a.reflective,solid:a.solid,solidColor:a.solidColor}},SceneJS.Flags.prototype.setPicking=function(a){return a=!!a,this._core.picking!=a&&(this._core.picking=a,this._engine.display.drawListDirty=!0),this},SceneJS.Flags.prototype.getPicking=function(){return this._core.picking},SceneJS.Flags.prototype.setClipping=function(a){return a=!!a,this._core.clipping!=a&&(this._core.clipping=a,this._engine.display.imageDirty=!0),this},SceneJS.Flags.prototype.getClipping=function(){return this._core.clipping},SceneJS.Flags.prototype.setEnabled=function(a){return a=!!a,this._core.enabled!=a&&(this._core.enabled=a,this._engine.display.drawListDirty=!0),this},SceneJS.Flags.prototype.getEnabled=function(){return this._core.enabled},SceneJS.Flags.prototype.setTransparent=function(a){return a=!!a,this._core.transparent!=a&&(this._core.transparent=a,this._engine.display.stateOrderDirty=!0),this},SceneJS.Flags.prototype.getTransparent=function(){return this._core.transparent},SceneJS.Flags.prototype.setBackfaces=function(a){return a=!!a,this._core.backfaces!=a&&(this._core.backfaces=a,this._engine.display.imageDirty=!0),this},SceneJS.Flags.prototype.getBackfaces=function(){return this._core.backfaces},SceneJS.Flags.prototype.setFrontface=function(a){return this._core.frontface!=a&&(this._core.frontface=a,this._engine.display.imageDirty=!0),this},SceneJS.Flags.prototype.getFrontface=function(){return this._core.frontface},SceneJS.Flags.prototype.setReflective=function(b){return b=!!b,this._core.reflective!=b&&(this._core.reflective=b,this._core.hash=a(this._core),this._engine.branchDirty(this),this._engine.display.imageDirty=!0),this},SceneJS.Flags.prototype.getReflective=function(){return this._core.reflective},SceneJS.Flags.prototype.setSolid=function(b){return b=!!b,this._core.solid!=b&&(this._core.solid=b,this._core.hash=a(this._core),this._engine.branchDirty(this),this._engine.display.imageDirty=!0),this},SceneJS.Flags.prototype.getSolid=function(){return this._core.solid},SceneJS.Flags.prototype.setSolidColor=function(a){var c=b.solidColor;return this._core.solidColor=a?[void 0!=a.r&&null!=a.r?a.r:c[0],void 0!=a.g&&null!=a.g?a.g:c[1],void 0!=a.b&&null!=a.b?a.b:c[2]]:b.solidColor,this._engine.display.imageDirty=!0,this},SceneJS.Flags.prototype.getSolidColor=function(){return{r:this._core.solidColor[0],g:this._core.solidColor[1],b:this._core.solidColor[2]}},SceneJS.Flags.prototype.setSkybox=function(b){return b=!!b,this._core.skybox!=b&&(this._core.skybox=b,this._core.hash=a(this._core),this._engine.branchDirty(this),this._engine.display.imageDirty=!0),this},SceneJS.Flags.prototype.getSkybox=function(){return this._core.skybox},SceneJS.Flags.prototype._compile=function(a){this._engine.display.flags=c[d++]=this._core,this._compileNodes(a),this._engine.display.flags=--d>0?c[d-1]:b,c[d]=null}}(),new function(){var a={type:"renderTarget",stateId:SceneJS._baseStateId++,targets:null},b={},c=[],d=0;SceneJS_events.addListener(SceneJS_events.SCENE_COMPILING,function(b){b.engine.display.renderTarget=a,d=0}),SceneJS_events.addListener(SceneJS_events.WEBGL_CONTEXT_RESTORED,function(){for(var a in b)b.hasOwnProperty(a)&&b[a]._core.renderBuf.webglRestored()}),SceneJS.ColorTarget=SceneJS_NodeFactory.createNodeType("colorTarget"),SceneJS.ColorTarget.prototype._init=function(a){b[this._core.coreId]=this,this._core.bufType="color",this._core.renderBuf=new SceneJS._webgl.RenderBuffer({canvas:this._engine.canvas})},SceneJS.ColorTarget.prototype._compile=function(b){this.__core||(this.__core=this._engine._coreFactory.getCore("renderTarget"));var e=this._engine.display.renderTarget;this._core.empty||(this.__core.targets=e&&e.targets?e.targets.concat([this._core]):[this._core]),c[d++]=this.__core,this._engine.display.renderTarget=this.__core,this._compileNodes(b),this._engine.display.renderTarget=--d>0?c[d-1]:a,c[d]=null},SceneJS.ColorTarget.prototype._destroy=function(){this._core&&(this._core.renderBuf&&this._core.renderBuf.destroy(),delete b[this._core.coreId])}},new function(){var a={type:"renderTarget",stateId:SceneJS._baseStateId++,targets:null},b={},c=[],d=0;SceneJS_events.addListener(SceneJS_events.SCENE_COMPILING,function(b){b.engine.display.renderTarget=a,d=0}),SceneJS_events.addListener(SceneJS_events.WEBGL_CONTEXT_RESTORED,function(){for(var a in b)b.hasOwnProperty(a)&&b[a]._buildNodeCore()}),SceneJS.DepthTarget=SceneJS_NodeFactory.createNodeType("depthTarget"),SceneJS.DepthTarget.prototype._init=function(a){b[this._core.coreId]=this,this._core.bufType="depth",this._core.renderBuf=new SceneJS._webgl.RenderBuffer({canvas:this._engine.canvas})},SceneJS.DepthTarget.prototype._compile=function(b){this.__core||(this.__core=this._engine._coreFactory.getCore("renderTarget"));var e=this._engine.display.renderTarget;this._core.empty||(this.__core.targets=e&&e.targets?e.targets.concat([this._core]):[this._core]),c[d++]=this.__core,this._engine.display.renderTarget=this.__core,this._compileNodes(b),this._engine.display.renderTarget=--d>0?c[d-1]:a,c[d]=null},SceneJS.DepthTarget.prototype._destroy=function(){this._core&&(this._core.renderBuf&&this._core.renderBuf.destroy(),delete b[this._core.coreId])}},new function(){function a(a,b){var c=a.STATIC_DRAW,d=b.arrays,e=SceneJS.getConfigs("enableInterleaving")!==!1,f=0,g=0,h=[],i=[],j=function(a,b){return 0==f?f=a.length/b:a.length/b!=f&&(e=!1),h.push(a),i.push(b),g+=b,4*(g-b)};if(d.positions&&(e&&(b.interleavedPositionOffset=j(d.positions,3)),b.vertexBuf=new SceneJS._webgl.ArrayBuffer(a,a.ARRAY_BUFFER,d.positions,d.positions.length,3,c)),d.normals&&(e&&(b.interleavedNormalOffset=j(d.normals,3)),b.normalBuf=new SceneJS._webgl.ArrayBuffer(a,a.ARRAY_BUFFER,d.normals,d.normals.length,3,c)),d.uvs){var k,l,m,n,o=d.uvs;if(e)for(b.interleavedUVOffsets=[],k=b.interleavedUVOffsets,l=0,m=o.length;l0&&b.uvBufs.push(new SceneJS._webgl.ArrayBuffer(a,a.ARRAY_BUFFER,n,n.length,2,c))}if(d.colors&&(e&&(b.interleavedColorOffset=j(d.colors,4)),b.colorBuf=new SceneJS._webgl.ArrayBuffer(a,a.ARRAY_BUFFER,d.colors,d.colors.length,4,c)),d.indices&&(b.indexBuf=new SceneJS._webgl.ArrayBuffer(a,a.ELEMENT_ARRAY_BUFFER,d.indices,d.indices.length,1,c)),g>0&&e){for(var p=[],q=h.length,l=0;ld&&(e-=e+c-d);for(var f=c,g=0;gthis._boundary.xmax&&(this._boundary.xmax=c),d>this._boundary.ymax&&(this._boundary.ymax=d),e>this._boundary.zmax&&(this._boundary.zmax=e);return this._boundary},SceneJS.Geometry.prototype._compile=function(a){if(this._core._loading)return void this._compileNodes(a);var d=this._core;if(d.vertexBuf||(d=this._inheritVBOs(d)),d.indexBuf||"points"===d.primitiveName){var e=[d.normalBuf?"t":"f",d.arrays&&d.arrays.tangents?"t":"f",d.colorBuf?"t":"f",d.primitive];e.push(";uvs");var f=d.uvBufs;if(f)for(var g=0,h=f.length;g=0;e--)if(b[e].vertexBuf)return d.vertexBuf=b[e].vertexBuf,d.boundary=b[e].boundary,d.normalBuf=b[e].normalBuf,d.uvBufs=b[e].uvBufs,d.colorBuf=b[e].colorBuf,d.interleavedBuf=b[e].interleavedBuf,d.interleavedStride=b[e].interleavedStride,d.interleavedPositionOffset=b[e].interleavedPositionOffset,d.interleavedNormalOffset=b[e].interleavedNormalOffset,d.interleavedUVOffsets=b[e].interleavedUVOffsets,d.interleavedColorOffset=b[e].interleavedColorOffset,d;return d},SceneJS.Geometry.prototype._destroy=function(){this._engine.display.removeObject(this.id),1==this._core.useCount&&(this._destroyNodeCore(),this._source&&this._source.destroy&&this._source.destroy(),this._engine.stats.memory.meshes--)},SceneJS.Geometry.prototype._destroyNodeCore=function(){document.getElementById(this._engine.canvas.canvasId)&&d(this._core);var a=this._core.arrays;a.positions&&(this._engine.stats.memory.positions-=a.positions.length/3),a.normals&&(this._engine.stats.memory.normals-=a.normals.length/3),a.colors&&(this._engine.stats.memory.colors-=a.colors.length/3),a.uvs&&a.uvs.length>0&&(this._engine.stats.memory.uvs-=a.uvs.length*(a.uvs[0].length/2)),a.indices&&(this._engine.stats.memory.indices-=a.indices.length)}},function(){var a={type:"stage",stateId:SceneJS._baseStateId++,priority:0,pickable:!0,enabled:!0},b=[],c=0;SceneJS_events.addListener(SceneJS_events.SCENE_COMPILING,function(b){b.engine.display.stage=a,c=0}),SceneJS.Stage=SceneJS_NodeFactory.createNodeType("stage"),SceneJS.Stage.prototype._init=function(a){1==this._core.useCount&&(this._core.priority=a.priority||0,this._core.enabled=a.enabled!==!1,this._core.pickable=!!a.pickable)},SceneJS.Stage.prototype.setPriority=function(a){a=a||0,this._core.priority!=a&&(this._core.priority=a,this._engine.display.stateOrderDirty=!0)},SceneJS.Stage.prototype.getPriority=function(){return this._core.priority},SceneJS.Stage.prototype.setEnabled=function(a){a=!!a,this._core.enabled!=a&&(this._core.enabled=a,this._engine.display.drawListDirty=!0)},SceneJS.Stage.prototype.getEnabled=function(){return this._core.enabled},SceneJS.Stage.prototype.getEnabled=function(){return this._core.enabled},SceneJS.Stage.prototype._compile=function(d){this._engine.display.stage=b[c++]=this._core,this._compileNodes(d),this._engine.display.stage=--c>0?b[c-1]:a,b[c]=null}}(),function(){var a={type:"layer",stateId:SceneJS._baseStateId++,priority:0,enabled:!0},b=[],c=0;SceneJS_events.addListener(SceneJS_events.SCENE_COMPILING,function(b){b.engine.display.layer=a,c=0}),SceneJS.Layer=SceneJS_NodeFactory.createNodeType("layer"),SceneJS.Layer.prototype._init=function(a){1==this._core.useCount&&(this._core.priority=a.priority||0,this._core.enabled=a.enabled!==!1)},SceneJS.Layer.prototype.setPriority=function(a){a=a||0,this._core.priority!=a&&(this._core.priority=a,this._engine.display.stateOrderDirty=!0)},SceneJS.Layer.prototype.getPriority=function(){return this._core.priority},SceneJS.Layer.prototype.setEnabled=function(a){a=!!a,this._core.enabled!=a&&(this._core.enabled=a,this._engine.display.drawListDirty=!0)},SceneJS.Layer.prototype.getEnabled=function(){return this._core.enabled},SceneJS.Layer.prototype.getEnabled=function(){return this._core.enabled},SceneJS.Layer.prototype.setClearDepth=function(a){a=a||0,this._core.clearDepth!=a&&(this._core.clearDepth=a,this._engine.display.drawListDirty=!0)},SceneJS.Layer.prototype.getClearDepth=function(){return this._core.clearDepth},SceneJS.Layer.prototype._compile=function(d){this._engine.display.layer=b[c++]=this._core,this._compileNodes(d),this._engine.display.layer=--c>0?b[c-1]:a,b[c]=null}}(),SceneJS.Library=SceneJS_NodeFactory.createNodeType("library"),SceneJS.Library.prototype._compile=function(a){},function(){function a(a){if(a.lights&&a.lights.length>0){for(var b,c=a.lights,d=[],e=0,f=c.length;e=this._core.lights.length)throw SceneJS_error.fatalError(SceneJS.errors.ILLEGAL_NODE_CONFIG,"Invalid argument to set 'lights': index out of range ("+this._core.lights.length+" lights defined)");this._setLight(b,a[c]||{})}this._engine.branchDirty(this)},SceneJS.Lights.prototype._setLight=function(a,b){var c=this._core.lights[a],d=!1,e=!1;if(b.mode&&b.mode!=c.mode){var f=b.mode;if("dir"!=f&&"point"!=f&&"ambient"!=f)throw SceneJS_error.fatalError(SceneJS.errors.ILLEGAL_NODE_CONFIG,"Light mode not supported - should be 'dir' or 'point' or 'ambient'");c.mode=f,c.diffuse="ambient"==f||(void 0==b.diffuse||b.diffuse),c.specular="ambient"!=f&&(void 0==b.specular||b.specular),e=!0}if(b.color){var g=b.color;c.color=[void 0!=g.r?g.r:1,void 0!=g.g?g.g:1,void 0!=g.b?g.b:1],d=!0}var h=b.pos;h&&(c.pos=[h.x||0,h.y||0,h.z||0],d=!0);var i=b.dir;if(i&&(c.dir=[i.x||0,i.y||0,i.z||0],d=!0),void 0!=b.innerCone&&b.innerCone!=c.innerCone&&(c.innerCone=b.innerCone,d=!0),void 0!=b.outerCone&&b.outerCone!=c.outerCone&&(c.outerCone=b.outerCone,d=!0),void 0!=b.constantAttenuation&&(c.attenuation[0]=b.constantAttenuation,d=!0),void 0!=b.linearAttenuation&&(c.attenuation[1]=b.linearAttenuation,d=!0),void 0!=b.quadraticAttenuation&&(c.attenuation[2]=b.quadraticAttenuation,d=!0),b.space&&b.space!=c.space){var j=b.space;if("view"!=j&&"world"!=j)throw SceneJS_error.fatalError(SceneJS.errors.ILLEGAL_NODE_CONFIG,"lights node invalid value for property 'space': '"+j+"' - should be 'view' or 'world'");c.space=j,this._core.hash=null,e=!0}void 0!=b.specular&&b.specular!=c.specular&&(c.specular=b.specular,e=!0),void 0!=b.diffuse&&b.diffuse!=c.diffuse&&(c.diffuse=b.diffuse,e=!0),e?this._engine.branchDirty(this):d&&(this._engine.display.imageDirty=!0),this._core.hash=null},SceneJS.Lights.prototype._compile=function(e){this._core.hash||a(this._core),this._engine.display.lights=c[d++]=this._core,this._compileNodes(e),this._engine.display.lights=--d>0?c[d-1]:b,c[d]=null}}(),function(){var a=SceneJS_math_lookAtMat4c(0,0,10,0,0,0,0,1,0),b=new Float32Array(a),c=SceneJS_math_transposeMat4(SceneJS_math_inverseMat4(b,SceneJS_math_mat4())),d=new Float32Array(c),e={type:"lookAt",stateId:SceneJS._baseStateId++,matrix:a,mat:b,normalMatrix:c,normalMat:d,lookAt:SceneJS_math_LOOKAT_ARRAYS},f=[],g=0;SceneJS_events.addListener(SceneJS_events.SCENE_COMPILING,function(a){a.engine.display.viewTransform=e,g=0}),SceneJS.Lookat=SceneJS_NodeFactory.createNodeType("lookAt"),SceneJS.Lookat.prototype._init=function(a){if(this._mat=null,this._xf={type:"lookat"},1==this._core.useCount){this._core.eyeX=0,this._core.eyeY=0,this._core.eyeZ=10,this._core.lookX=0,this._core.lookY=0,this._core.lookZ=0,this._core.upX=0,this._core.upY=1,this._core.upZ=0,a.eye||a.look||a.up?(this.setEye(a.eye),this.setLook(a.look),this.setUp(a.up)):(this.setEye({x:0,y:0,z:10}),this.setLook({x:0,y:0,z:0}),this.setUp({x:0,y:1,z:0}));var b=this._core,c=this;this._core.rebuild=function(){b.matrix=SceneJS_math_lookAtMat4c(b.eyeX,b.eyeY,b.eyeZ,b.lookX,b.lookY,b.lookZ,b.upX,b.upY,b.upZ),b.lookAt={eye:[b.eyeX,b.eyeY,b.eyeZ],look:[b.lookX,b.lookY,b.lookZ],up:[b.upX,b.upY,b.upZ]},b.mat?(b.mat.set(b.matrix),b.normalMat.set(SceneJS_math_transposeMat4(SceneJS_math_inverseMat4(b.matrix,SceneJS_math_mat4())))):(b.mat=new Float32Array(b.matrix),b.normalMat=new Float32Array(SceneJS_math_transposeMat4(SceneJS_math_inverseMat4(b.matrix,SceneJS_math_mat4())))),c.publish("matrix",b.matrix),b.dirty=!1},this._core.dirty=!0,this._tick=this.getScene().on("tick",function(){c._core.dirty&&c._core.rebuild()})}},SceneJS.Lookat.getDefaultMatrix=function(){return b},SceneJS.Lookat.prototype.setEye=function(a){return a=a||{},void 0!=a.x&&null!=a.x&&(this._core.eyeX=a.x),void 0!=a.y&&null!=a.y&&(this._core.eyeY=a.y),void 0!=a.z&&null!=a.z&&(this._core.eyeZ=a.z),this._core.dirty=!0,this._engine.display.imageDirty=!0,this},SceneJS.Lookat.prototype.incEye=function(a){return a=a||{},this._core.eyeX+=void 0!=a.x&&null!=a.x?a.x:0,this._core.eyeY+=void 0!=a.y&&null!=a.y?a.y:0,this._core.eyeZ+=void 0!=a.z&&null!=a.z?a.z:0,this._core.dirty=!0,this._engine.display.imageDirty=!0,this},SceneJS.Lookat.prototype.setEyeX=function(a){return this._core.eyeX=a||0,this._core.dirty=!0,this._engine.display.imageDirty=!0,this},SceneJS.Lookat.prototype.setEyeY=function(a){return this._core.eyeY=a||0,this._core.dirty=!0,this._engine.display.imageDirty=!0,this},SceneJS.Lookat.prototype.setEyeZ=function(a){return this._core.eyeZ=a||0,this._core.dirty=!0,this._engine.display.imageDirty=!0,this},SceneJS.Lookat.prototype.incEyeX=function(a){return this._core.eyeX+=a,this._core.dirty=!0,this._engine.display.imageDirty=!0,this},SceneJS.Lookat.prototype.incEyeY=function(a){return this._core.eyeY+=a,this._core.dirty=!0,this._engine.display.imageDirty=!0,this},SceneJS.Lookat.prototype.incEyeZ=function(a){return this._core.eyeZ+=a,this._core.dirty=!0,this._engine.display.imageDirty=!0,this},SceneJS.Lookat.prototype.getEye=function(){return{x:this._core.eyeX,y:this._core.eyeY,z:this._core.eyeZ}},SceneJS.Lookat.prototype.setLook=function(a){return a=a||{},void 0!=a.x&&null!=a.x&&(this._core.lookX=a.x),void 0!=a.y&&null!=a.y&&(this._core.lookY=a.y),void 0!=a.z&&null!=a.z&&(this._core.lookZ=a.z),this._core.dirty=!0,this._engine.display.imageDirty=!0,this},SceneJS.Lookat.prototype.incLook=function(a){return a=a||{},this._core.lookX+=void 0!=a.x&&null!=a.x?a.x:0,this._core.lookY+=void 0!=a.y&&null!=a.y?a.y:0,this._core.lookZ+=void 0!=a.z&&null!=a.z?a.z:0,this._core.dirty=!0,this._engine.display.imageDirty=!0,this},SceneJS.Lookat.prototype.setLookX=function(a){return this._core.lookX=a||0,this._core.dirty=!0,this._engine.display.imageDirty=!0,this},SceneJS.Lookat.prototype.setLookY=function(a){return this._core.lookY=a||0,this._core.dirty=!0,this._engine.display.imageDirty=!0,this},SceneJS.Lookat.prototype.setLookZ=function(a){return this._core.lookZ=a||0,this._core.dirty=!0,this._engine.display.imageDirty=!0,this},SceneJS.Lookat.prototype.incLookX=function(a){return this._core.lookX+=a,this._core.dirty=!0,this._engine.display.imageDirty=!0,this},SceneJS.Lookat.prototype.incLookY=function(a){return this._core.lookY+=a,this._core.dirty=!0,this._engine.display.imageDirty=!0,this},SceneJS.Lookat.prototype.incLookZ=function(a){return this._core.lookZ+=a,this._core.dirty=!0,this._engine.display.imageDirty=!0,this},SceneJS.Lookat.prototype.getLook=function(){return{x:this._core.lookX,y:this._core.lookY,z:this._core.lookZ}},SceneJS.Lookat.prototype.setUp=function(a){return a=a||{},void 0!=a.x&&null!=a.x&&(this._core.upX=a.x),void 0!=a.y&&null!=a.y&&(this._core.upY=a.y),void 0!=a.z&&null!=a.z&&(this._core.upZ=a.z),this._core.dirty=!0,this._engine.display.imageDirty=!0,this},SceneJS.Lookat.prototype.incUp=function(a){return a=a||{},this._core.upX+=void 0!=a.x&&null!=a.x?a.x:0,this._core.upY+=void 0!=a.y&&null!=a.y?a.y:0,this._core.upZ+=void 0!=a.z&&null!=a.z?a.z:0,this._core.dirty=!0,this._engine.display.imageDirty=!0,this},SceneJS.Lookat.prototype.setUpX=function(a){return this._core.upX=a||0,this._core.dirty=!0,this._engine.display.imageDirty=!0,this},SceneJS.Lookat.prototype.setUpY=function(a){return this._core.upY=a||0,this._core.dirty=!0,this._engine.display.imageDirty=!0,this},SceneJS.Lookat.prototype.setUpZ=function(a){return this._core.upZ=a||0,this._core.dirty=!0,this._engine.display.imageDirty=!0,this},SceneJS.Lookat.prototype.incUpX=function(a){return this._core.upX+=a,this._core.dirty=!0,this._engine.display.imageDirty=!0,this},SceneJS.Lookat.prototype.incUpY=function(a){return this._core.upY+=a,this._core.dirty=!0,this._engine.display.imageDirty=!0,this},SceneJS.Lookat.prototype.incUpZ=function(a){return this._core.upZ+=a,this._core.dirty=!0,this._engine.display.imageDirty=!0,this},SceneJS.Lookat.prototype.getUp=function(){return{x:this._core.upX,y:this._core.upY,z:this._core.upZ}},SceneJS.Lookat.prototype.setMatrix=function(a){var b=this._core;b.matrix=a,b.mat=a,b.mat?(b.mat.set(b.matrix),b.normalMat.set(SceneJS_math_transposeMat4(SceneJS_math_inverseMat4(b.matrix,SceneJS_math_mat4())))):(b.mat=new Float32Array(b.matrix),b.normalMat=new Float32Array(SceneJS_math_transposeMat4(SceneJS_math_inverseMat4(b.matrix,SceneJS_math_mat4())))),this.publish("matrix",b.matrix),this._engine.display.imageDirty=!0},SceneJS.Lookat.prototype.getMatrix=function(){return this._core.dirty&&this._core.rebuild(),SceneJS._sliceArray(this._core.matrix,0)},SceneJS.Lookat.prototype.getAttributes=function(){return{look:{x:this._core.lookX,y:this._core.lookY,z:this._core.lookZ},eye:{x:this._core.eyeX,y:this._core.eyeY,z:this._core.eyeZ},up:{x:this._core.upX,y:this._core.upY,z:this._core.upZ}}},SceneJS.Lookat.prototype._compile=function(a){this._engine.display.viewTransform=f[g++]=this._core,this._compileNodes(a),this._engine.display.viewTransform=--g>0?f[g-1]:e,f[g]=null},SceneJS.Lookat.prototype._destroy=function(){this.getScene().off(this._tick)}}(),new function(){var a={type:"material",stateId:SceneJS._baseStateId++,baseColor:[1,1,1],specularColor:[1,1,1],emitColor:[1,1,1],specular:1,shine:70,alpha:1,emit:0},b=[],c=0;SceneJS_events.addListener(SceneJS_events.SCENE_COMPILING,function(b){b.engine.display.material=a,c=0}),SceneJS.Material=SceneJS_NodeFactory.createNodeType("material"),SceneJS.Material.prototype._init=function(a){1==this._core.useCount&&(this.setBaseColor(a.color||a.baseColor),this.setSpecularColor(a.specularColor),this.setEmitColor(a.emitColor),this.setSpecular(a.specular),this.setShine(a.shine),this.setEmit(a.emit),this.setAlpha(a.alpha))},SceneJS.Material.prototype.setBaseColor=function(b){var c=a.baseColor;return this._core.baseColor=b?[void 0!=b.r&&null!=b.r?b.r:c[0],void 0!=b.g&&null!=b.g?b.g:c[1],void 0!=b.b&&null!=b.b?b.b:c[2]]:a.baseColor,this._engine.display.imageDirty=!0,this},SceneJS.Material.prototype.setColor=SceneJS.Material.prototype.setBaseColor,SceneJS.Material.prototype.getBaseColor=function(){return{r:this._core.baseColor[0],g:this._core.baseColor[1],b:this._core.baseColor[2]}},SceneJS.Material.prototype.getColor=SceneJS.Material.prototype.getBaseColor,SceneJS.Material.prototype.setSpecularColor=function(b){var c=a.specularColor;return this._core.specularColor=b?[void 0!=b.r&&null!=b.r?b.r:c[0],void 0!=b.g&&null!=b.g?b.g:c[1],void 0!=b.b&&null!=b.b?b.b:c[2]]:a.specularColor,this._engine.display.imageDirty=!0,this},SceneJS.Material.prototype.getSpecularColor=function(){return{r:this._core.specularColor[0],g:this._core.specularColor[1],b:this._core.specularColor[2]}},SceneJS.Material.prototype.setEmitColor=function(b){var c=a.emitColor;return this._core.emitColor=b?[void 0!=b.r&&null!=b.r?b.r:c[0],void 0!=b.g&&null!=b.g?b.g:c[1],void 0!=b.b&&null!=b.b?b.b:c[2]]:a.emitColor,this._engine.display.imageDirty=!0,this},SceneJS.Material.prototype.getEmitColor=function(){return{r:this._core.emitColor[0],g:this._core.emitColor[1],b:this._core.emitColor[2]}},SceneJS.Material.prototype.setSpecular=function(b){return this._core.specular=void 0!=b&&null!=b?b:a.specular,this._engine.display.imageDirty=!0,this},SceneJS.Material.prototype.getSpecular=function(){return this._core.specular},SceneJS.Material.prototype.setShine=function(b){return this._core.shine=void 0!=b&&null!=b?b:a.shine,this._engine.display.imageDirty=!0,this},SceneJS.Material.prototype.getShine=function(){return this._core.shine},SceneJS.Material.prototype.setEmit=function(b){return this._core.emit=void 0!=b&&null!=b?b:a.emit,this._engine.display.imageDirty=!0,this},SceneJS.Material.prototype.getEmit=function(){return this._core.emit},SceneJS.Material.prototype.setAlpha=function(b){return this._core.alpha=void 0!=b&&null!=b?b:a.alpha,this._engine.display.imageDirty=!0,this},SceneJS.Material.prototype.getAlpha=function(){return this._core.alpha},SceneJS.Material.prototype._compile=function(d){this._engine.display.material=b[c++]=this._core,this._compileNodes(d),this._engine.display.material=--c>0?b[c-1]:a,b[c]=null}},new function(){function a(a,b){var c=b.targets||[];if(c.length<2)throw SceneJS_error.fatalError(SceneJS.errors.ILLEGAL_NODE_CONFIG,"morphGeometry node should have at least two targets");var d=b.keys||[];if(d.length!=c.length)throw SceneJS_error.fatalError(SceneJS.errors.ILLEGAL_NODE_CONFIG,"morphGeometry node mismatch in number of keys and targets");var e=a._core,f=a._engine.canvas.gl,g=f.STATIC_DRAW;e.keys=d,e.targets=[],e.key1=0,e.key2=1;for(var h,i,j,k,l,m=0,n=c.length;mc[c.length-1])d=c.length-2,e=d+1;else{for(;c[d]>a;)d--,e--;for(;c[e]0?c[d-1]:b,c[d]=null},SceneJS.MorphGeometry.prototype._makeHash=function(){var a=this._core;if(a.targets.length>0){var b=a.targets[0],c="t",d="f";a.hash=[b.vertexBuf?c:d,b.normalBuf?c:d,b.uvBuf?c:d,b.uvBuf2?c:d].join("")}else a.hash=""},SceneJS.MorphGeometry.prototype._destroy=function(){if(1==this._core.useCount&&document.getElementById(this._engine.canvas.canvasId))for(var a,b=this._core,c=0,d=b.targets.length;c0?b[c-1]:a,b[c]=null}}(),new function(){function a(a){var c;if(f>0){c={};for(var d in a)a.hasOwnProperty(d)&&void 0!=a[d]&&(c[d]=g(d))}return b(a.props),{props:a,setProps:function(b){h(b,a)},restoreProps:function(a){c&&i(a,c)}}}function b(a){var b;for(var c in a)a.hasOwnProperty(c)&&(b=a[c],void 0!=b&&null!=b&&(k[c]?a[c]=k[c](null,b):l[c]&&(a[c]=l[c](null,b))))}var c,d={type:"renderer",stateId:SceneJS._baseStateId++,props:null},e=[],f=0;SceneJS_events.addListener(SceneJS_events.SCENE_COMPILING,function(a){c=a.engine.canvas,f=0,a.engine.display.renderer=e[f++]=d});var g=function(a){for(var b,c,d=f-1;d>=0;d--)if(b=e[d].props,b&&(c=b[a],void 0!=c&&null!=c))return b[a];return null},h=function(a,b){for(var c in b)if(b.hasOwnProperty(c)){var d=k[c];d&&d(a,b[c])}b.viewport&&l.viewport(a,b.viewport),b.scissor&&l.clear(a,b.scissor),b.clear&&l.clear(a,b.clear)},i=function(a,b){var c;for(var d in b)if(b.hasOwnProperty(d)&&(c=b[d],void 0!=c&&null!=c)){var e=k[d];e&&e(a,c)}b.viewport&&l.viewport(a,b.viewport),b.scissor&&l.clear(a,b.scissor)},j=function(a,b){if(!b)throw SceneJS_error.fatalError(SceneJS.errors.ILLEGAL_NODE_CONFIG,'Null SceneJS.State node config: "'+b+'"');var c=SceneJS._webgl.enumMap[b];if(!c)throw SceneJS_error.fatalError(SceneJS.errors.ILLEGAL_NODE_CONFIG,'Unrecognised SceneJS.State node config value: "'+b+'"');var d=a[c];if(!d)throw SceneJS_error.fatalError(SceneJS.errors.ILLEGAL_NODE_CONFIG,"This browser's WebGL does not support renderer node config value: \""+b+'"');return d},k={enableBlend:function(a,b){return a?void(b?a.enable(a.BLEND):a.disable(a.BLEND)):(null!=b&&void 0!=b||(b=!1),b)},blendColor:function(a,b){return a?void a.blendColor(b.r,b.g,b.b,b.a):(b=b||{},{r:b.r||0,g:b.g||0,b:b.b||0,a:void 0==b.a||null==b.a?1:b.a})},blendEquation:function(a,b){return a?void a.blendEquation(a,j(a,b)):b||"funcAdd"},blendEquationSeparate:function(a,b){return a?void a.blendEquation(j(a,b.rgb),j(a,b.alpha)):(b=b||{},{rgb:b.rgb||"funcAdd",alpha:b.alpha||"funcAdd"})},blendFunc:function(a,b){return a?void a.blendFunc(j(a,b.sfactor||"srcAlpha"),j(a,b.dfactor||"oneMinusSrcAlpha")):(b=b||{},{sfactor:b.sfactor||"srcAlpha",dfactor:b.dfactor||"oneMinusSrcAlpha"})},blendFuncSeparate:function(a,b){return a?void a.blendFuncSeparate(j(a,b.srcRGB||"zero"),j(a,b.dstRGB||"zero"),j(a,b.srcAlpha||"zero"),j(a,b.dstAlpha||"zero")):(b=b||{},{srcRGB:b.srcRGB||"zero",dstRGB:b.dstRGB||"zero",srcAlpha:b.srcAlpha||"zero",dstAlpha:b.dstAlpha||"zero"})},clearColor:function(a,b){return a?void a.clearColor(b.r,b.g,b.b,b.a):(b=b||{},{r:b.r||0,g:b.g||0,b:b.b||0,a:void 0==b.a||null==b.a?1:b.a})},clearDepth:function(a,b){return a?void a.clearDepth(b):null==b||void 0==b?1:b},clearStencil:function(a,b){return a?void a.clearStencil(b):b||0},colorMask:function(a,b){return a?void a.colorMask(b.r,b.g,b.b,b.a):(b=b||{},{r:b.r||0,g:b.g||0,b:b.b||0,a:void 0==b.a||null==b.a?1:b.a})},enableCullFace:function(a,b){return a?void(b?a.enable(a.CULL_FACE):a.disable(a.CULL_FACE)):b},cullFace:function(a,b){return a?void a.cullFace(j(a,b)):b||"back"},enableDepthTest:function(a,b){return a?void(b?a.enable(a.DEPTH_TEST):a.disable(a.DEPTH_TEST)):(null!=b&&void 0!=b||(b=!0),b)},depthFunc:function(a,b){return a?void a.depthFunc(j(a,b)):b||"less"},enableDepthMask:function(a,b){return a?void a.depthMask(b):(null!=b&&void 0!=b||(b=!0),b)},depthRange:function(a,b){return a?void a.depthRange(b.zNear,b.zFar):(b=b||{},{zNear:void 0==b.zNear||null==b.zNear?0:b.zNear,zFar:void 0==b.zFar||null==b.zFar?1:b.zFar})},frontFace:function(a,b){return a?void a.frontFace(j(a,b)):b||"ccw"},lineWidth:function(a,b){return a?void a.lineWidth(b):b||1},enableScissorTest:function(a,b){return a?void(b?a.enable(a.SCISSOR_TEST):(b=!1,a.disable(a.SCISSOR_TEST))):b}},l={viewport:function(a,b){return a?void a.viewport(b.x,b.y,b.width,b.height):(b=b||{},{x:b.x||1,y:b.y||1,width:b.width||c.canvas.width,height:b.height||c.canvas.height})},scissor:function(a,b){return a?void a.scissor(b.x,b.y,b.width,b.height):(b=b||{},{x:b.x||0,y:b.y||0,width:b.width||1,height:b.height||1})},clear:function(a,b){if(!a)return b=b||{};var c;b.color&&(c=a.COLOR_BUFFER_BIT),b.depth&&(c|=a.DEPTH_BUFFER_BIT),b.stencil&&(c|=a.STENCIL_BUFFER_BIT)}};SceneJS.Renderer=SceneJS_NodeFactory.createNodeType("renderer"),SceneJS.Renderer.prototype._init=function(a){if(1==this._core.useCount){for(var b in a)a.hasOwnProperty(b)&&(this._core[b]=a[b]);this._core.dirty=!0}},SceneJS.Renderer.prototype.setViewport=function(a){ -this._core.viewport=a?{x:a.x||1,y:a.y||1,width:a.width||1e3,height:a.height||1e3}:void 0,this._core.dirty=!0,this._engine.display.imageDirty=!0},SceneJS.Renderer.prototype.getViewport=function(){return this._core.viewport?{x:this._core.viewport.x,y:this._core.viewport.y,width:this._core.viewport.width,height:this._core.viewport.height}:void 0},SceneJS.Renderer.prototype.setScissor=function(a){this._core.scissor=a?{x:a.x||1,y:a.y||1,width:a.width||1e3,height:a.height||1e3}:void 0,this._core.dirty=!0,this._engine.display.imageDirty=!0},SceneJS.Renderer.prototype.getScissor=function(){return this._core.scissor?{x:this._core.scissor.x,y:this._core.scissor.y,width:this._core.scissor.width,height:this._core.scissor.height}:void 0},SceneJS.Renderer.prototype.setClear=function(a){this._core.clear=a?{r:a.r||0,g:a.g||0,b:a.b||0}:void 0,this._core.dirty=!0,this._engine.display.imageDirty=!0},SceneJS.Renderer.prototype.getClear=function(){return this._core.clear?{r:this._core.clear.r,g:this._core.clear.g,b:this._core.clear.b}:null},SceneJS.Renderer.prototype.setEnableBlend=function(a){this._core.enableBlend=a,this._core.dirty=!0,this._engine.display.imageDirty=!0},SceneJS.Renderer.prototype.getEnableBlend=function(){return this._core.enableBlend},SceneJS.Renderer.prototype.setBlendColor=function(a){this._core.blendColor=a?{r:a.r||0,g:a.g||0,b:a.b||0,a:void 0==a.a||null==a.a?1:a.a}:void 0,this._core.dirty=!0,this._engine.display.imageDirty=!0},SceneJS.Renderer.prototype.getBlendColor=function(){return this._core.blendColor?{r:this._core.blendColor.r,g:this._core.blendColor.g,b:this._core.blendColor.b,a:this._core.blendColor.a}:void 0},SceneJS.Renderer.prototype.setBlendEquation=function(a){this._core.blendEquation=a,this._core.dirty=!0,this._engine.display.imageDirty=!0},SceneJS.Renderer.prototype.getBlendEquation=function(){return this._core.blendEquation},SceneJS.Renderer.prototype.setBlendEquationSeparate=function(a){this._core.blendEquationSeparate=a?{rgb:a.rgb||"funcAdd",alpha:a.alpha||"funcAdd"}:void 0,this._core.dirty=!0,this._engine.display.imageDirty=!0},SceneJS.Renderer.prototype.getBlendEquationSeparate=function(){return this._core.blendEquationSeparate?{rgb:this._core.rgb,alpha:this._core.alpha}:void 0},SceneJS.Renderer.prototype.setBlendFunc=function(a){this._core.blendFunc=a?{sfactor:a.sfactor||"srcAlpha",dfactor:a.dfactor||"one"}:void 0,this._core.dirty=!0,this._engine.display.imageDirty=!0},SceneJS.Renderer.prototype.getBlendFunc=function(){return this._core.blendFunc?{sfactor:this._core.sfactor,dfactor:this._core.dfactor}:void 0},SceneJS.Renderer.prototype.setBlendFuncSeparate=function(a){this._core.blendFuncSeparate=a?{srcRGB:a.srcRGB||"zero",dstRGB:a.dstRGB||"zero",srcAlpha:a.srcAlpha||"zero",dstAlpha:a.dstAlpha||"zero"}:void 0,this._core.dirty=!0},SceneJS.Renderer.prototype.getBlendFuncSeparate=function(){return this._core.blendFuncSeparate?{srcRGB:this._core.blendFuncSeparate.srcRGB,dstRGB:this._core.blendFuncSeparate.dstRGB,srcAlpha:this._core.blendFuncSeparate.srcAlpha,dstAlpha:this._core.blendFuncSeparate.dstAlpha}:void 0},SceneJS.Renderer.prototype.setEnableCullFace=function(a){this._core.enableCullFace=a,this._core.dirty=!0},SceneJS.Renderer.prototype.getEnableCullFace=function(){return this._core.enableCullFace},SceneJS.Renderer.prototype.setCullFace=function(a){this._core.cullFace=a,this._core.dirty=!0},SceneJS.Renderer.prototype.getCullFace=function(){return this._core.cullFace},SceneJS.Renderer.prototype.setEnableDepthTest=function(a){this._core.enableDepthTest=a,this._core.dirty=!0},SceneJS.Renderer.prototype.getEnableDepthTest=function(){return this._core.enableDepthTest},SceneJS.Renderer.prototype.setDepthFunc=function(a){this._core.depthFunc=a,this._core.dirty=!0},SceneJS.Renderer.prototype.getDepthFunc=function(){return this._core.depthFunc},SceneJS.Renderer.prototype.setEnableDepthMask=function(a){this._core.enableDepthMask=a,this._core.dirty=!0},SceneJS.Renderer.prototype.getEnableDepthMask=function(){return this._core.enableDepthMask},SceneJS.Renderer.prototype.setClearDepth=function(a){this._core.clearDepth=a,this._core.dirty=!0},SceneJS.Renderer.prototype.getClearDepth=function(){return this._core.clearDepth},SceneJS.Renderer.prototype.setDepthRange=function(a){this._core.depthRange=a?{zNear:void 0==a.zNear||null==a.zNear?0:a.zNear,zFar:void 0==a.zFar||null==a.zFar?1:a.zFar}:void 0,this._core.dirty=!0},SceneJS.Renderer.prototype.getDepthRange=function(){return this._core.depthRange?{zNear:this._core.depthRange.zNear,zFar:this._core.depthRange.zFar}:void 0},SceneJS.Renderer.prototype.setFrontFace=function(a){this._core.frontFace=a,this._core.dirty=!0},SceneJS.Renderer.prototype.getFrontFace=function(){return this._core.frontFace},SceneJS.Renderer.prototype.setLineWidth=function(a){this._core.lineWidth=a,this._core.dirty=!0},SceneJS.Renderer.prototype.getLineWidth=function(){return this._core.lineWidth},SceneJS.Renderer.prototype.setEnableScissorTest=function(a){this._core.enableScissorTest=a,this._core.dirty=!0},SceneJS.Renderer.prototype.getEnableScissorTest=function(){return this._core.enableScissorTest},SceneJS.Renderer.prototype.setClearStencil=function(a){this._core.clearStencil=a,this._core.dirty=!0},SceneJS.Renderer.prototype.getClearStencil=function(){return this._core.clearStencil},SceneJS.Renderer.prototype.setColorMask=function(a){this._core.colorMask=a?{r:a.r||0,g:a.g||0,b:a.b||0,a:void 0==a.a||null==a.a?1:a.a}:void 0,this._core.dirty=!0},SceneJS.Renderer.prototype.getColorMask=function(){return this._core.colorMask?{r:this._core.colorMask.r,g:this._core.colorMask.g,b:this._core.colorMask.b,a:this._core.colorMask.a}:void 0},SceneJS.Renderer.prototype._compile=function(b){this._core.dirty&&(this._core.props=a(this._core),this._core.dirty=!1),this._engine.display.renderer=e[f++]=this._core,this._compileNodes(b),this._engine.display.renderer=--f>0?e[f-1]:d,e[f]=null}},function(){var a={less:"LESS",equal:"EQUAL",lequal:"LEQUAL",greater:"GREATER",notequal:"NOTEQUAL",gequal:"GEQUAL"},b={type:"depthBuffer",stateId:SceneJS._baseStateId++,enabled:!0,clearDepth:1,depthFunc:null,_depthFuncName:"less"},c=[],d=0;SceneJS_events.addListener(SceneJS_events.SCENE_COMPILING,function(a){null===b.depthFunc&&(b.depthFunc=a.engine.canvas.gl.LESS),a.engine.display.depthBuffer=b,d=0}),SceneJS.DepthBuf=SceneJS_NodeFactory.createNodeType("depthBuffer"),SceneJS.DepthBuf.prototype._init=function(a){void 0!=a.enabled?this.setEnabled(a.enabled):1==this._core.useCount&&this.setEnabled(!0),void 0!=a.clearDepth?this.setClearDepth(a.clearDepth):1==this._core.useCount&&this.setClearDepth(1),void 0!=a.depthFunc?this.setDepthFunc(a.depthFunc):1==this._core.useCount&&this.setDepthFunc("less"),void 0!=a.clear?this.setClear(a.clear):1==this._core.useCount&&this.setClear(!0)},SceneJS.DepthBuf.prototype.setEnabled=function(a){return this._core.enabled!=a&&(this._core.enabled=a,this._engine.display.imageDirty=!0),this},SceneJS.DepthBuf.prototype.getEnabled=function(){return this._core.enabled},SceneJS.DepthBuf.prototype.setClear=function(a){return this._core.clear!=a&&(this._core.clear=a,this._engine.display.imageDirty=!0),this},SceneJS.DepthBuf.prototype.getClear=function(){return this._core.clear},SceneJS.DepthBuf.prototype.setClearDepth=function(a){return this._core.clearDepth!=a&&(this._core.clearDepth=a,this._engine.display.imageDirty=!0),this},SceneJS.DepthBuf.prototype.getClearDepth=function(){return this._core.clearDepth},SceneJS.DepthBuf.prototype.setDepthFunc=function(b){if(this._core._depthFuncName!=b){var c=a[b];if(void 0==c)throw"unsupported value for 'clearFunc' attribute on depthBuffer node: '"+b+"' - supported values are 'less', 'equal', 'lequal', 'greater', 'notequal' and 'gequal'";this._core.depthFunc=this._engine.canvas.gl[c],this._core._depthFuncName=b,this._engine.display.imageDirty=!0}return this},SceneJS.DepthBuf.prototype.getDepthFunc=function(){return this._core._depthFuncName},SceneJS.DepthBuf.prototype._compile=function(a){this._engine.display.depthBuffer=c[d++]=this._core,this._compileNodes(a),this._engine.display.depthBuffer=--d>0?c[d-1]:b,c[d]=null}}(),function(){var a={never:"NEVER",less:"LESS",equal:"EQUAL",lequal:"LEQUAL",greater:"GREATER",notequal:"NOTEQUAL",gequal:"GEQUAL",always:"ALWAYS",keep:"KEEP",zero:"ZERO",replace:"REPLACE",incr:"INCR",incr_wrap:"INCR_WRAP",decr:"DECR",decr_wrap:"DECR_WRAP",invert:"INVERT",front:"FRONT",back:"BACK",front_and_back:"FRONT_AND_BACK"},b={type:"stencilBuffer",stateId:SceneJS._baseStateId++,enabled:!1,clearStencil:0,stencilFuncFuncFront:null,stencilFuncRefFront:0,stencilFuncMaskFront:255,stencilFuncFuncBack:null,stencilFuncRefBack:0,stencilFuncMaskBack:255,stencilOpSfailFront:null,stencilOpDpfailFront:null,stencilOpDppassFront:null,stencilOpSfailBack:null,stencilOpDpfailBack:null,stencilOpDppassBack:null,_stencilFuncFuncStateFront:"always",_stencilFuncRefStateFront:0,_stencilFuncMaskStateFront:255,_stencilFuncFuncStateBack:"always",_stencilFuncRefStateBack:0,_stencilFuncMaskStateBack:255,_stencilOpSfailStateFront:"keep",_stencilOpDpfailStateFront:"keep",_stencilOpDppassStateFront:"keep",_stencilOpSfailStateBack:"keep",_stencilOpDpfailStateBack:"keep",_stencilOpDppassStateBack:"keep"},c=[],d=0;SceneJS_events.addListener(SceneJS_events.SCENE_COMPILING,function(a){null===b.stencilFuncFuncFront&&(b.stencilFuncFuncFront=a.engine.canvas.gl.ALWAYS),null===b.stencilFuncFuncBack&&(b.stencilFuncFuncBack=a.engine.canvas.gl.ALWAYS),null===b.stencilOpSfailFront&&(b.stencilOpSfailFront=a.engine.canvas.gl.KEEP,b.stencilOpDpfailFront=a.engine.canvas.gl.KEEP,b.stencilOpDppassFront=a.engine.canvas.gl.KEEP),null===b.stencilOpSfailBack&&(b.stencilOpSfailBack=a.engine.canvas.gl.KEEP,b.stencilOpDpfailBack=a.engine.canvas.gl.KEEP,b.stencilOpDppassBack=a.engine.canvas.gl.KEEP),a.engine.display.stencilBuffer=b,d=0}),SceneJS.StencilBuf=SceneJS_NodeFactory.createNodeType("stencilBuffer"),SceneJS.StencilBuf.prototype._init=function(a){void 0!=a.enabled?this.setEnabled(a.enabled):1==this._core.useCount&&this.setEnabled(!0),void 0!=a.clearStencil?this.setClearStencil(a.clearStencil):1==this._core.useCount&&this.setClearStencil(0),void 0!=a.stencilFunc?this.setStencilFunc(a.stencilFunc):1==this._core.useCount&&this.setStencilFunc({face:"front_back",func:"always",ref:1,mask:255}),void 0!=a.stencilOp?this.setStencilOp(a.stencilOp):1==this._core.useCount&&this.setStencilOp({face:"front_back",sfail:"keep",dpfail:"keep",dppass:"keep"}),void 0!=a.clear&&this.setClear(a.clear)},SceneJS.StencilBuf.prototype.setEnabled=function(a){return this._core.enabled!=a&&(this._core.enabled=a,this._engine.display.imageDirty=!0),this},SceneJS.StencilBuf.prototype.getEnabled=function(){return this._core.enabled},SceneJS.StencilBuf.prototype.setClear=function(a){return this._core.clear!=a&&(this._core.clear=a,this._engine.display.imageDirty=!0),this},SceneJS.StencilBuf.prototype.getClear=function(){return this._core.clear},SceneJS.StencilBuf.prototype.setClearStencil=function(a){return this._core.clearStencil!=a&&(this._core.clearStencil=a,this._engine.display.imageDirty=!0),this},SceneJS.StencilBuf.prototype.getClearStencil=function(){return this._core.clearStencil},SceneJS.StencilBuf.prototype.setStencilFunc=function(b){var c=!1,d=!1,e=b.func||"always",f=void 0!==b.ref?b.ref:1,g=void 0!==b.mask?b.mask:255,h=e,i=f,j=g,k=b.face||"front_and_back";if(b.front||b.back?(b.front&&(c=!0,e=b.front.func||"always",f=void 0!==b.front.ref?b.front.ref:1,g=void 0!==b.front.mask?b.front.mask:255),b.back&&(d=!0,h=b.back.func||"always",i=void 0!==b.back.ref?b.back.ref:1,j=void 0!==b.back.mask?b.back.mask:255)):(c="front"===k||"front_and_back"===k,d="back"===k||"front_and_back"===k),f!==i||g!==j)throw"WebGL only allow same value for stencil ref and mask of front and back faces";if(c&&(this._core._stencilFuncFuncStateFront!=e||this._core._stencilFuncRefStateFront!=f||this._core._stencilFuncMaskStateFront!=g)){var l=a[e];if(void 0==l)throw"unsupported value for 'stencilFunc' attribute on stencilBuffer node: '"+stencilFunc.func+"' - supported values are 'keep', 'always', 'less', 'equal', 'lequal', 'greater', 'notequal' and 'gequal'";this._core.stencilFuncFuncFront=this._engine.canvas.gl[l],this._core.stencilFuncRefFront=f,this._core.stencilFuncMaskFront=g,this._core._stencilFuncFuncStateFront=e,this._core._stencilFuncRefStateFront=f,this._core._stencilFuncMaskStateFront=g,this._engine.display.imageDirty=!0}if(d&&(this._core._stencilFuncFuncStateBack!=h||this._core._stencilFuncRefStateBack!=i||this._core._stencilFuncMaskStateBack!=j)){var l=a[h];if(void 0==l)throw"unsupported value for 'stencilFunc' attribute on stencilBuffer node: '"+stencilFunc.func+"' - supported values are 'keep', 'always', 'less', 'equal', 'lequal', 'greater', 'notequal' and 'gequal'";this._core.stencilFuncFuncBack=this._engine.canvas.gl[l],this._core.stencilFuncRefBack=i,this._core.stencilFuncMaskBack=j,this._core._stencilFuncFuncStateBack=h,this._core._stencilFuncRefStateBack=i,this._core._stencilFuncMaskStateBack=j,this._engine.display.imageDirty=!0}return this},SceneJS.StencilBuf.prototype.setStencilOp=function(b){var c=!1,d=!1,e=b.sfail||"keep",f=b.dpfail||"keep",g=b.dppass||"keep",h=e,i=f,j=g,k=b.face||"front_and_back";if(b.front||b.back?(b.front&&(c=!0,e=b.front.sfail||"keep",f=b.front.dpfail||"keep",g=b.front.dppass||"keep"),b.back&&(d=!0,h=b.back.sfail||"keep",i=b.back.dpfail||"keep",j=b.back.dppass||"keep")):(c="front"===k||"front_and_back"===k,d="back"===k||"front_and_back"===k),c&&(this._core._stencilOpSfailStateFront!=e||this._core._stencilOpDpfailStateFront!=f||this._core._stencilOpDppassStateFront!=g)){var l=a[e],m=a[f],n=a[g];if(void 0==l||void 0==m||void 0==n)throw"unsupported value for 'StencilOp' attribute on stencilBuffer node - supported values are 'keep', 'zero', 'replace', 'incr', 'incr_wrap', 'decr', 'decr_wrap', 'invert'";this._core.stencilOpSfailFront=this._engine.canvas.gl[l],this._core.stencilOpDpfailFront=this._engine.canvas.gl[m],this._core.stencilOpDppassFront=this._engine.canvas.gl[n],this._core._stencilOpSfailStateFront=e,this._core._stencilOpSfailStateFront=f,this._core._stencilOpSfailStateFront=g,this._engine.display.imageDirty=!0}if(d&&(this._core._stencilOpSfailStateBack!=h||this._core._stencilOpDpfailStateBack!=i||this._core._stencilOpDppassStateBack!=j)){var l=a[h],m=a[i],n=a[j];if(void 0==l||void 0==m||void 0==n)throw"unsupported value for 'StencilOp' attribute on stencilBuffer node - supported values are 'keep', 'zero', 'replace', 'incr', 'incr_wrap', 'decr', 'decr_wrap', 'invert'";this._core.stencilOpSfailBack=this._engine.canvas.gl[l],this._core.stencilOpDpfailBack=this._engine.canvas.gl[m],this._core.stencilOpDppassBack=this._engine.canvas.gl[n],this._core._stencilOpSfailStateBack=h,this._core._stencilOpSfailStateBack=i,this._core._stencilOpSfailStateBack=j,this._engine.display.imageDirty=!0}return this},SceneJS.StencilBuf.prototype.getStencilFuncFront=function(){return{func:this._core._stencilFuncFuncStateFront,ref:this._core._stencilFuncRefStateFront,mask:this._core._stencilFuncMaskStateFront}},SceneJS.StencilBuf.prototype.getStencilFuncBack=function(){return{func:this._core._stencilFuncFuncStateBack,ref:this._core._stencilFuncRefStateBack,mask:this._core._stencilFuncMaskStateBack}},SceneJS.StencilBuf.prototype.getStencilOpFront=function(){return{sfail:this._core._stencilOpSfailStateFront,dpfail:this._core._stencilOpDpfailStateFront,dppass:this._core._stencilOpDppassStateFront}},SceneJS.StencilBuf.prototype.getStencilOpBack=function(){return{sfail:this._core._stencilOpSfailStateBack,dpfail:this._core._stencilOpDpfailStateBack,dppass:this._core._stencilOpDppassStateBack}},SceneJS.StencilBuf.prototype._compile=function(a){this._engine.display.stencilBuffer=c[d++]=this._core,this._compileNodes(a),this._engine.display.stencilBuffer=--d>0?c[d-1]:b,c[d]=null}}(),function(){var a={type:"colorBuffer",stateId:SceneJS._baseStateId++,blendEnabled:!1,colorMask:{r:!0,g:!0,b:!0,a:!0}},b=[],c=0;SceneJS_events.addListener(SceneJS_events.SCENE_COMPILING,function(b){b.engine.display.colorBuffer=a,c=0}),SceneJS.ColorBuffer=SceneJS_NodeFactory.createNodeType("colorBuffer"),SceneJS.ColorBuffer.prototype._init=function(a){void 0!=a.blendEnabled?this.setBlendEnabled(a.blendEnabled):1==this._core.useCount&&this.setBlendEnabled(!1),this.setColorMask(a)},SceneJS.ColorBuffer.prototype.setBlendEnabled=function(a){this._core.blendEnabled!=a&&(this._core.blendEnabled=a,this._engine.display.imageDirty=!0),this._engine.display.imageDirty=!0},SceneJS.ColorBuffer.prototype.getBlendEnabled=function(){return this._core.blendEnabled},SceneJS.ColorBuffer.prototype.setColorMask=function(a){this._core.colorMask={r:void 0==a.r||null==a.r||a.r,g:void 0==a.g||null==a.g||a.g,b:void 0==a.b||null==a.b||a.b,a:void 0==a.a||null==a.a||a.a},this._engine.display.imageDirty=!0},SceneJS.ColorBuffer.prototype.getColorMask=function(){return this._core.colorMask},SceneJS.ColorBuffer.prototype._compile=function(d){this._engine.display.colorBuffer=b[c++]=this._core,this._compileNodes(d),this._engine.display.colorBuffer=--c>0?b[c-1]:a,b[c]=null,this._engine.display.imageDirty=!0}}(),function(){var a={type:"view",stateId:SceneJS._baseStateId++,scissorTestEnabled:!1},b=[],c=0;SceneJS_events.addListener(SceneJS_events.SCENE_COMPILING,function(b){b.engine.display.view=a,c=0}),SceneJS.View=SceneJS_NodeFactory.createNodeType("view"),SceneJS.View.prototype._init=function(a){void 0!=a.scissorTestEnabled?this.setScissorTestEnabled(a.scissorTestEnabled):1==this._core.useCount&&this.setScissorTestEnabled(!1)},SceneJS.View.prototype.setScissorTestEnabled=function(a){return this._core.scissorTestEnabled!=a&&(this._core.scissorTestEnabled=a,this._engine.display.imageDirty=!0),this},SceneJS.View.prototype.getScissorTestEnabled=function(){return this._core.scissorTestEnabled},SceneJS.View.prototype._compile=function(d){this._engine.display.view=b[c++]=this._core,this._compileNodes(d),this._engine.display.view=--c>0?b[c-1]:a,b[c]=null}}(),SceneJS.Scene=SceneJS_NodeFactory.createNodeType("scene"),SceneJS.Scene.prototype._init=function(a){a.tagMask&&this.setTagMask(a.tagMask),this._tagSelector=null,this.transparent=a.transparent===!0,this.stats=this._engine.stats},SceneJS.Scene.prototype.loseWebGLContext=function(){this._engine.loseWebGLContext()},SceneJS.Scene.prototype.getCanvas=function(){return this._engine.canvas.canvas},SceneJS.Scene.prototype.getGL=function(){return this._engine.canvas.gl},SceneJS.Scene.prototype.getWebGL2Supported=function(){return this._engine.canvas.webgl2},SceneJS.Scene.prototype.getZBufferDepth=function(){var a=this._engine.canvas.gl;return a.getParameter(a.DEPTH_BITS)},SceneJS.Scene.prototype.setResolutionScaling=function(a){return this._engine.canvas.setResolutionScaling(a)},SceneJS.Scene.prototype.setTagMask=function(a){a=a||"XXXXXXXXXXXXXXXXXXXXXXXXXX",this._tagSelector||(this._tagSelector={}),this._tagSelector.mask=a,this._tagSelector.regex=a?new RegExp(a):null,this._engine.display.selectTags(this._tagSelector)},SceneJS.Scene.prototype.getTagMask=function(){return this._tagSelector?this._tagSelector.mask:null},SceneJS.Scene.prototype.setNumPasses=function(a){this._engine.setNumPasses(a)},SceneJS.Scene.prototype.setClearEachPass=function(a){this._engine.setClearEachPass(a)},SceneJS.Scene.prototype.setBindOutputFrameBuffer=function(a,b){this._engine.display.bindOutputFramebuffer=a,this._engine.display.unbindOutputFramebuffer=b},SceneJS.Scene.prototype.renderFrame=function(a){return this._engine.renderFrame(a)},SceneJS.Scene.prototype.pauseCompilation=function(){return this._engine.pauseCompilation()},SceneJS.Scene.prototype.resumeCompilation=function(){return this._engine.resumeCompilation()},SceneJS.Scene.prototype.compile=function(){return this._engine.compile()},SceneJS.Scene.prototype.needFrame=function(){this._engine.display.imageDirty=!0},SceneJS.Scene.prototype.start=function(a){this._engine.start(a)},SceneJS.Scene.prototype.setFPS=function(a){this._engine.fps=a},SceneJS.Scene.prototype.pause=function(a){this._engine.pause(a)},SceneJS.Scene.prototype.isRunning=function(){return this._engine.running},SceneJS.Scene.prototype.pick=function(a){var b=this._engine.pick(a);return this.renderFrame({force:!0}),b?(this.publish("pick",b),b):void this.publish("nopick")},SceneJS.Scene.prototype.readPixels=function(a,b,c){return this._engine.readPixels(a,b,c)},SceneJS.Scene.prototype._destroy=function(){this.destroyed||(delete SceneJS._engines[this.id],SceneJS._engineIds.removeItem(this.id),this.destroyed=!0)},SceneJS.Scene.prototype.isActive=function(){return!this._engine.destroyed},SceneJS.Scene.prototype.stop=function(){this._engine.stop()},SceneJS.Scene.prototype.containsNode=function(a){return!!this._engine.findNode(a)},SceneJS.Scene.prototype.findNodes=function(a){return this._engine.findNodes(a)},SceneJS.Scene.prototype.findNode=function(a,b){return this.getNode(a,b)},SceneJS.Scene.prototype.getNode=function(a,b){var c=this._engine.findNode(a);return c?(b&&b(c),c):b?void this.once("nodes/"+a,b):null},SceneJS.Scene.prototype.hasCore=function(a,b){return this._engine.hasCore(a,b)},SceneJS.Scene.prototype.setDepthSort=function(a){this._engine.setDepthSort(a)},SceneJS.Scene.prototype.getStatus=function(){var a=SceneJS_sceneStatusModule.sceneStatus[this.id];return a?SceneJS._shallowClone(a):{destroyed:!0}},new function(){function a(a){for(var b,c,d={},e=0;e0){var l={type:"shader",stateId:c[i-1],hash:c.slice(0,i).join("."),shaders:{fragment:{code:f.slice(0,i).join(""),hooks:a(g)},vertex:{code:d.slice(0,i).join(""),hooks:a(e)}},paramsStack:h.slice(0,i)};k.display.shader=l}else k.display.shader=b;j=!1}}),SceneJS.Shader=SceneJS_NodeFactory.createNodeType("shader"),SceneJS.Shader.prototype._init=function(a){1==this._core.useCount&&(this._setShaders(a.shaders),this.setParams(a.params))},SceneJS.Shader.prototype._setShaders=function(a){a=a||[],this._core.shaders={};for(var b,c=0,d=a.length;c0){var g={type:"shaderParams",stateId:c[e-1],paramsStack:d.slice(0,e)};f.display.shaderParams=g}else f.display.shaderParams=b;a=!1}}),SceneJS.ShaderParams=SceneJS_NodeFactory.createNodeType("shaderParams"),SceneJS.ShaderParams.prototype._init=function(a){1==this._core.useCount&&this.setParams(a.params)},SceneJS.ShaderParams.prototype.setParams=function(a){a=a||{};var b=this._core;b.params||(b.params={});for(var c in a)a.hasOwnProperty(c)&&(b.params[c]=a[c]);this._engine.display.imageDirty=!0},SceneJS.ShaderParams.prototype.getParams=function(){var a=this._core.params;if(!a)return{};var b={};for(var c in a)a.hasOwnProperty(c)&&(b[c]=a[c]);return b},SceneJS.ShaderParams.prototype._compile=function(b){c[e]=this._core.coreId,d[e]=this._core.params,e++,a=!0,this._compileNodes(b),e--,a=!0}},function(){var a={type:"style",stateId:SceneJS._baseStateId++,lineWidth:1},b=[],c=0;SceneJS_events.addListener(SceneJS_events.SCENE_COMPILING,function(b){b.engine.display.style=a,c=0}),SceneJS.Style=SceneJS_NodeFactory.createNodeType("style"),SceneJS.Style.prototype._init=function(a){void 0!=a.lineWidth&&this.setLineWidth(a.lineWidth)},SceneJS.Style.prototype.setLineWidth=function(a){return this._core.lineWidth!=a&&(this._core.lineWidth=a,this._engine.display.imageDirty=!0),this},SceneJS.Style.prototype.getLineWidth=function(){return this._core.lineWidth},SceneJS.Style.prototype._compile=function(d){this._engine.display.style=b[c++]=this._core,this._compileNodes(d),this._engine.display.style=--c>0?b[c-1]:a,b[c]=null}}(),function(){var a={type:"tag",stateId:SceneJS._baseStateId++,tag:null},b=[],c=0;SceneJS_events.addListener(SceneJS_events.SCENE_COMPILING,function(b){b.engine.display.tag=a,c=0}),SceneJS.Tag=SceneJS_NodeFactory.createNodeType("tag"),SceneJS.Tag.prototype._init=function(a){if(1==this._core.useCount){if(!a.tag)throw SceneJS_error.fatalError(SceneJS.errors.NODE_CONFIG_EXPECTED,"tag node attribute missing : 'tag'");this.setTag(a.tag)}},SceneJS.Tag.prototype.setTag=function(a){var b=this._core;b.tag=a,b.pattern=null,b.matched=!1,this._engine.display.drawListDirty=!0},SceneJS.Tag.prototype.getTag=function(){return this._core.tag},SceneJS.Tag.prototype._compile=function(d){this._engine.display.tag=b[c++]=this._core,this._compileNodes(d),this._engine.display.tag=--c>0?b[c-1]:a,b[c]=null}}(),new function(){var a={type:"texture",stateId:SceneJS._baseStateId++,empty:!0,hash:""},b=[],c=0;SceneJS_events.addListener(SceneJS_events.SCENE_COMPILING,function(b){b.engine.display.texture=a,c=0}),SceneJS.Texture=SceneJS_NodeFactory.createNodeType("_texture"),SceneJS.Texture.prototype._init=function(a){if(1==this._core.useCount){this._core.layers=[],this._core.params={};var b=void 0==a.waitForLoad||a.waitForLoad;if(!a.layers)throw SceneJS_error.fatalError(SceneJS.errors.NODE_CONFIG_EXPECTED,"texture layers missing");if(!SceneJS._isArray(a.layers))throw SceneJS_error.fatalError(SceneJS.errors.NODE_CONFIG_EXPECTED,"texture layers should be an array");for(var c,d=this._engine.canvas.gl,e=0;e>b;return a+1},SceneJS.Texture.prototype._setLayerTexture=function(a,b,c){b.texture=new SceneJS._webgl.Texture2D(a,{texture:c,minFilter:this._getGLOption("minFilter",a,b,a.LINEAR_MIPMAP_NEAREST),magFilter:this._getGLOption("magFilter",a,b,a.LINEAR),wrapS:this._getGLOption("wrapS",a,b,a.REPEAT),wrapT:this._getGLOption("wrapT",a,b,a.REPEAT),update:null}),this.destroyed&&b.texture.destroy(),this._engine.display.imageDirty=!0},SceneJS.Texture.prototype._getGLOption=function(a,b,c,d){var e=c[a];if(void 0==e)return d;var f=SceneJS._webgl.enumMap[e];if(void 0==f)throw SceneJS_error.fatalError(SceneJS.errors.ILLEGAL_NODE_CONFIG,"Unrecognised value for texture node property '"+a+"' value: '"+e+"'");var g=b[f]; -return g},SceneJS.Texture.prototype._getOption=function(a,b){return void 0==a?b:a},SceneJS.Texture.prototype.setLayer=function(a){if(void 0==a.index||null==a.index)throw SceneJS_error.fatalError(SceneJS.errors.ILLEGAL_NODE_CONFIG,"Invalid texture set layer argument: index null or undefined");if(a.index<0||a.index>=this._core.layers.length)throw SceneJS_error.fatalError(SceneJS.errors.ILLEGAL_NODE_CONFIG,"Invalid texture set layer argument: index out of range ("+this._core.layers.length+" layers defined)");this._setLayer(parseInt(a.index),a),this._engine.display.imageDirty=!0},SceneJS.Texture.prototype.setLayers=function(a){var b;for(var c in a)if(a.hasOwnProperty(c)&&(void 0!=c||null!=c)){if(b=parseInt(c),b<0||b>=this._core.layers.length)throw SceneJS_error.fatalError(SceneJS.errors.ILLEGAL_NODE_CONFIG,"Invalid texture set layer argument: index out of range ("+this._core.layers.length+" layers defined)");this._setLayer(b,a[c]||{})}this._engine.display.imageDirty=!0},SceneJS.Texture.prototype._setLayer=function(a,b){b=b||{};var c=this._core.layers[a];if(void 0!=b.blendFactor&&null!=b.blendFactor&&(c.blendFactor=b.blendFactor),b.source){var d=c._source;d&&d.configure&&d.configure(b.source)}(b.translate||b.rotate||b.scale)&&this._setLayerTransform(b,c)},SceneJS.Texture.prototype._setLayerTransform=function(a,b){var c,d;if(a.translate){var e=a.translate;void 0!=e.x&&(b.translate.x=e.x),void 0!=e.y&&(b.translate.y=e.y),c=SceneJS_math_translationMat4v([e.x||0,e.y||0,0])}if(a.scale){var f=a.scale;void 0!=f.x&&(b.scale.x=f.x),void 0!=f.y&&(b.scale.y=f.y),d=SceneJS_math_scalingMat4v([f.x||1,f.y||1,1]),c=c?SceneJS_math_mulMat4(c,d):d}if(a.rotate){var g=a.rotate;void 0!=g.z&&(b.rotate.z=g.z||0),d=SceneJS_math_rotationMat4v(.0174532925*g.z,[0,0,1]),c=c?SceneJS_math_mulMat4(c,d):d}c&&(b.matrix=c,b.matrixAsArray?b.matrixAsArray.set(b.matrix):b.matrixAsArray=new Float32Array(b.matrix),b.matrixAsArray=new Float32Array(b.matrix))},SceneJS.Texture.prototype._compile=function(d){this._core.hash||this._makeHash(),this._engine.display.texture=b[c++]=this._core,this._compileNodes(d),this._engine.display.texture=--c>0?b[c-1]:a,b[c]=null},SceneJS.Texture.prototype._makeHash=function(){var a,b=this._core;if(b.layers&&b.layers.length>0){for(var c,d=b.layers,e=[],f=0,g=d.length;f'");var e=0;if("uv"!==d&&(e=d.substring(2),isNaN(e)))throw SceneJS_error.fatalError(SceneJS.errors.NODE_CONFIG_EXPECTED,"texture applyFrom value invalid - should be 'uv'");if(b.applyTo){var f=b.applyTo;if("baseColor"!=f&&"color"!=f&&"specular"!=f&&"emit"!=f&&"alpha"!=f&&"normals"!=f&&"shine"!=f)throw SceneJS_error.fatalError(SceneJS.errors.NODE_CONFIG_EXPECTED,"texture applyTo value is unsupported - should be either 'color', 'baseColor', 'specular' or 'normals'")}if(b.blendMode&&"add"!=b.blendMode&&"multiply"!=b.blendMode)throw SceneJS_error.fatalError(SceneJS.errors.NODE_CONFIG_EXPECTED,"texture layer blendMode value is unsupported - should be either 'add' or 'multiply'");"color"==b.applyTo&&(b.applyTo="baseColor"),SceneJS._apply({waitForLoad:void 0==b.waitForLoad||b.waitForLoad,texture:null,minFilter:b.minFilter,magFilter:b.magFilter,wrapS:b.wrapS,wrapT:b.wrapT,uvLayerIdx:e,isNormalMap:"normals"===b.applyTo,applyFrom:d,applyTo:b.applyTo?b.applyTo:"baseColor",blendMode:b.blendMode?b.blendMode:"multiply",blendFactor:void 0!=b.blendFactor&&null!=b.blendFactor?b.blendFactor:1,translate:b.translate?SceneJS._apply(b.translate,{x:0,y:0}):{x:0,y:0},scale:b.scale?SceneJS._apply(b.scale,{x:1,y:1}):{x:1,y:1},rotate:b.rotate||0,matrix:null,_matrixDirty:!0,buildMatrix:a},this._core),a.call(this._core),b.src?(this._initTexture(b.preloadColor),this._core.src=b.src,this._loadTexture(b.src,b.preloadSrc)):b.image?(this._initTexture(b.preloadColor),this._core.image=b.image,this._setTextureImage(b.image)):b.target&&this.getScene().getNode(b.target,function(a){c.setTarget(a)}),this._core.webglRestored=function(){c._core.image?(c._initTexture(b.preloadColor),c._setTextureImage(c._core.image)):c._core.src?(c._initTexture(b.preloadColor),c._loadTexture(c._core.src)):c._core.target},this._engine.stats.memory.textures++}},SceneJS.TextureMap.prototype._initTexture=function(a){var b=this._engine.canvas.gl;a=a||{r:.57735,g:.57735,b:.57735},a.a=void 0===a.a?1:a.a,a=new Uint8Array([Math.floor(255*a.r),Math.floor(255*a.g),Math.floor(255*a.b),Math.floor(255*a.a)]);var c=b.createTexture();b.bindTexture(b.TEXTURE_2D,c),b.texImage2D(b.TEXTURE_2D,0,b.RGBA,1,1,0,b.RGBA,b.UNSIGNED_BYTE,a),this._setCoreTexture(c)},SceneJS.TextureMap.prototype._loadTexture=function(a,b){var c=this,d=SceneJS_sceneStatusModule.taskStarted(this,"Loading texture"),e=new Image,f=!1,g=!1;if(b){var h=new Image;h.onload=function(){f||(c._setTextureImage(h),SceneJS_sceneStatusModule.taskFinished(d),g=!0,c._engine.display.imageDirty=!0)},this._fetchImage(h,b)}e.onload=function(){c._setTextureImage(e),g||SceneJS_sceneStatusModule.taskFinished(d),f=!0,c._engine.display.imageDirty=!0},e.onerror=function(){SceneJS_sceneStatusModule.taskFailed(d)},this._fetchImage(e,a)},SceneJS.TextureMap.prototype._fetchImage=function(a,b){0==b.indexOf("data")?a.src=b:(a.crossOrigin="Anonymous",a.src=b)},SceneJS.TextureMap.prototype._setTextureImage=function(a){var b=this._engine.canvas.gl,c=this._core,d=c.texture&&c.texture.texture?c.texture.texture:b.createTexture();b.bindTexture(b.TEXTURE_2D,d);var e=SceneJS_configsModule.configs.maxTextureSize;e&&(a=SceneJS._webgl.clampImageSize(a,e)),b.texImage2D(b.TEXTURE_2D,0,b.RGBA,b.RGBA,b.UNSIGNED_BYTE,SceneJS._webgl.ensureImageSizePowerOfTwo(a)),c.image=a,this._setCoreTexture(d)},SceneJS.TextureMap.prototype._setCoreTexture=function(a){var b=this._engine.canvas.gl;this._core.texture=new SceneJS._webgl.Texture2D(b,{texture:a,minFilter:this._getGLOption("minFilter",b.LINEAR_MIPMAP_NEAREST),magFilter:this._getGLOption("magFilter",b.LINEAR),wrapS:this._getGLOption("wrapS",b.REPEAT),wrapT:this._getGLOption("wrapT",b.REPEAT),update:null}),this.destroyed&&this._core.texture.destroy(),this._engine.display.imageDirty=!0},SceneJS.TextureMap.prototype._getGLOption=function(a,b){var c=this._engine.canvas.gl,d=this._core[a];if(void 0==d)return b;var e=SceneJS._webgl.enumMap[d];if(void 0==e)throw SceneJS_error.fatalError(SceneJS.errors.ILLEGAL_NODE_CONFIG,"Unrecognised value for texture node property '"+a+"' value: '"+d+"'");return c[e]},SceneJS.TextureMap.prototype._getOption=function(a,b){return void 0==a?b:a},SceneJS.TextureMap.prototype.setSrc=function(a){this._core.image=null,this._core.src=a,this._core.target=null,this._loadTexture(a)},SceneJS.TextureMap.prototype.setImage=function(a){this._core.image=a,this._core.src=null,this._core.target=null,this._setTextureImage(a)},SceneJS.TextureMap.prototype.setTarget=function(a){return"colorTarget"!=a.type&&"depthTarget"!=a.type?void console.log("Target node type not compatible: "+a.type):(delete this._core.src,this._core.target=a,this._core.src=null,this._core.image=null,this._core.texture=a._core.renderBuf.getTexture(),this._core.texture.bufType=a._core.bufType,void(this._engine.display.imageDirty=!0))},SceneJS.TextureMap.prototype.setBlendFactor=function(a){this._core.blendFactor=a,this._engine.display.imageDirty=!0},SceneJS.TextureMap.prototype.getBlendFactor=function(){return this._core.blendFactor},SceneJS.TextureMap.prototype.setTranslate=function(a){this._core.translate||(this._core.translate={x:0,y:0}),this._core.translate.x=a.x,this._core.translate.y=a.y,this._core._matrixDirty=!0,this._engine.display.imageDirty=!0},SceneJS.TextureMap.prototype.getTranslate=function(){return this._core.translate},SceneJS.TextureMap.prototype.setScale=function(a){this._core.scale||(this._core.scale={x:0,y:0}),this._core.scale.x=a.x,this._core.scale.y=a.y,this._core._matrixDirty=!0,this._engine.display.imageDirty=!0},SceneJS.TextureMap.prototype.getScale=function(){return this._core.scale},SceneJS.TextureMap.prototype.setRotate=function(a){this._core.rotate=a,this._core._matrixDirty=!0,this._engine.display.imageDirty=!0},SceneJS.TextureMap.prototype.getRotate=function(){return this._core.rotate},SceneJS.TextureMap.prototype.getMatrix=function(){return this._core._matrixDirty&&this._core.buildMatrix.call(this.core)(),this.core.matrix},SceneJS.TextureMap.prototype._compile=function(a){this.__core||(this.__core=this._engine._coreFactory.getCore("texture"));var e=this._engine.display.texture;this._core.empty||(this.__core.layers=e&&e.layers?e.layers.concat([this._core]):[this._core]),this._makeHash(this.__core),c[d++]=this.__core,this._engine.display.texture=this.__core,this._compileNodes(a),this._engine.display.texture=--d>0?c[d-1]:b,c[d]=null},SceneJS.TextureMap.prototype._makeHash=function(a){var b;if(a.layers&&a.layers.length>0){for(var c,d=a.layers,e=[],f=0,g=d.length;f0?b[c-1]:a,b[c]=null},SceneJS.Fresnel.prototype._makeHash=function(a){var b=[];a.diffuse&&b.push("d;"),a.specular&&b.push("s;"),a.alpha&&b.push("a;"),a.reflect&&b.push("r;"),a.emit&&b.push("e;"),a.fragment&&b.push("f;"),b=b.join(""),a.hash!=b&&(a.hash=b)},SceneJS.Fresnel.prototype._destroy=function(){this._core&&this._engine._coreFactory.putCore(this._core)}},function(){var a={type:"cubemap",stateId:SceneJS._baseStateId++,empty:!0,texture:null,hash:""},b=[],c=0;SceneJS_events.addListener(SceneJS_events.SCENE_COMPILING,function(b){b.engine.display.cubemap=a,c=0}),SceneJS.Reflect=SceneJS_NodeFactory.createNodeType("reflect"),SceneJS.Reflect.prototype._init=function(a){if(1==this._core.useCount){if(this._core.hash="y",a.blendMode&&"add"!=a.blendMode&&"multiply"!=a.blendMode)throw SceneJS_error.fatalError(SceneJS.errors.NODE_CONFIG_EXPECTED,"reflection blendMode value is unsupported - should be either 'add' or 'multiply'");this._core.blendMode=a.blendMode||"multiply",this._core.intensity=void 0!=a.intensity&&null!=a.intensity?a.intensity:1,this._core.applyTo="reflect";for(var b=this,c=this._engine.canvas.gl,d=c.createTexture(),e=[c.TEXTURE_CUBE_MAP_POSITIVE_X,c.TEXTURE_CUBE_MAP_NEGATIVE_X,c.TEXTURE_CUBE_MAP_POSITIVE_Y,c.TEXTURE_CUBE_MAP_NEGATIVE_Y,c.TEXTURE_CUBE_MAP_POSITIVE_Z,c.TEXTURE_CUBE_MAP_NEGATIVE_Z],f=[],g=SceneJS_sceneStatusModule.taskStarted(this,"Loading reflection texture"),h=!1,i=0;i0?b[c-1]:a,b[c]=null},SceneJS.Reflect.prototype._makeHash=function(a){var b;if(a.layers&&a.layers.length>0){for(var c,d=a.layers,e=[],f=0,g=d.length;f'");var d=0;if("uv"!==c&&(d=c.substring(2),isNaN(d)))throw SceneJS_error.fatalError(SceneJS.errors.NODE_CONFIG_EXPECTED,"texture applyFrom value invalid - should be 'uv'");this._core.uvLayerIdx=d,a.src?(this._initTexture(),this._core.src=a.src,this._loadTexture(a.src)):a.image?(this._initTexture(a.preloadColor),this._core.image=a.image,this._setTextureImage(a.image)):a.target&&this.getScene().getNode(a.target,function(a){b.setTarget(a)}),this._core.webglRestored=function(){b._core.image?(b._initTexture(),b._setTextureImage(b._core.image)):b._core.src?(b._initTexture(),b._loadTexture(b._core.src)):b._core.target},this.setRegionColor(a.regionColor),this.setHighlightFactor(a.highlightFactor),this.setHideAlpha(a.hideAlpha),this.setRegionData(a.regionData),this.setMode(a.mode)}},SceneJS.RegionMap.prototype._initTexture=function(){var a=this._engine.canvas.gl,b={r:.57735,g:.57735,b:.57735};b.a=void 0===b.a?1:b.a,b=new Uint8Array([Math.floor(255*b.r),Math.floor(255*b.g),Math.floor(255*b.b),Math.floor(255*b.a)]);var c=a.createTexture();a.bindTexture(a.TEXTURE_2D,c),a.texImage2D(a.TEXTURE_2D,0,a.RGBA,1,1,0,a.RGBA,a.UNSIGNED_BYTE,b),this._setCoreTexture(c)},SceneJS.RegionMap.prototype._loadTexture=function(a){var b=this,c=SceneJS_sceneStatusModule.taskStarted(this,"Loading texture"),d=new Image,e=!1,f=!1;d.onload=function(){b._setTextureImage(d),f||SceneJS_sceneStatusModule.taskFinished(c),e=!0,b._engine.display.imageDirty=!0},d.onerror=function(){SceneJS_sceneStatusModule.taskFailed(c)},this._fetchImage(d,a)},SceneJS.RegionMap.prototype._fetchImage=function(a,b){0==b.indexOf("data")?a.src=b:(a.crossOrigin="Anonymous",a.src=b)},SceneJS.RegionMap.prototype._setTextureImage=function(a){var b=this._engine.canvas.gl,c=this._core.texture?this._core.texture.texture:b.createTexture();b.bindTexture(b.TEXTURE_2D,c),b.texImage2D(b.TEXTURE_2D,0,b.RGBA,b.RGBA,b.UNSIGNED_BYTE,SceneJS._webgl.ensureImageSizePowerOfTwo(a)),this._core.image=a,this._setCoreTexture(c)},SceneJS.RegionMap.prototype._setCoreTexture=function(a){var b=this._engine.canvas.gl;this._core.texture=new SceneJS._webgl.Texture2D(b,{texture:a,minFilter:this._getGLOption("minFilter",b.NEAREST_MIPMAP_NEAREST),magFilter:this._getGLOption("magFilter",b.NEAREST),wrapS:this._getGLOption("wrapS",b.REPEAT),wrapT:this._getGLOption("wrapT",b.REPEAT),isDepth:this._getOption(this._core.isDepth,!1),depthMode:this._getGLOption("depthMode",b.LUMINANCE),depthCompareMode:this._getGLOption("depthCompareMode",b.COMPARE_R_TO_TEXTURE),depthCompareFunc:this._getGLOption("depthCompareFunc",b.LEQUAL),flipY:this._getOption(this._core.flipY,!0),width:this._getOption(this._core.width,1),height:this._getOption(this._core.height,1),internalFormat:this._getGLOption("internalFormat",b.ALPHA),sourceFormat:this._getGLOption("sourceFormat",b.ALPHA),sourceType:this._getGLOption("sourceType",b.UNSIGNED_BYTE),update:null}),this.destroyed&&this._core.texture.destroy(),this._engine.display.imageDirty=!0},SceneJS.RegionMap.prototype._getGLOption=function(a,b){var c=this._engine.canvas.gl,d=this._core[a];if(void 0==d)return b;var e=SceneJS._webgl.enumMap[d];if(void 0==e)throw SceneJS_error.fatalError(SceneJS.errors.ILLEGAL_NODE_CONFIG,"Unrecognised value for texture node property '"+a+"' value: '"+d+"'");return c[e]},SceneJS.RegionMap.prototype._getOption=function(a,b){return void 0==a?b:a},SceneJS.RegionMap.prototype.setSrc=function(a){this._core.image=null,this._core.src=a,this._core.target=null,this._loadTexture(a)},SceneJS.RegionMap.prototype.setImage=function(a){this._core.image=a,this._core.src=null,this._core.target=null,this._setTextureImage(a)},SceneJS.RegionMap.prototype.setTarget=function(a){return"colorTarget"!=a.type&&"depthTarget"!=a.type?void console.log("Target node type not compatible: "+a.type):(delete this._core.src,this._core.target=a,this._core.src=null,this._core.image=null,this._core.texture=a._core.renderBuf.getTexture(),this._core.texture.bufType=a._core.bufType,void(this._engine.display.imageDirty=!0))},SceneJS.RegionMap.prototype.setRegionColor=function(b){var c=a.regionColor;return this._core.regionColor=b?[void 0!=b.r&&null!=b.r?b.r:c[0],void 0!=b.g&&null!=b.g?b.g:c[1],void 0!=b.b&&null!=b.b?b.b:c[2]]:a.regionColor,this._engine.display.imageDirty=!0,this},SceneJS.RegionMap.prototype.setHighlightFactor=function(b){var c=a.highlightFactor;return this._core.highlightFactor=b?[void 0!=b.r&&null!=b.r?b.r:c[0],void 0!=b.g&&null!=b.g?b.g:c[1],void 0!=b.b&&null!=b.b?b.b:c[2]]:a.highlightFactor,this._engine.display.imageDirty=!0,this},SceneJS.RegionMap.prototype.setHideAlpha=function(b){return this._core.hideAlpha=void 0!=b?b:a.hideAlpha,this._engine.display.imageDirty=!0,this},SceneJS.RegionMap.prototype.setMode=function(b){return this._core.mode=b&&c[b]?b:a.mode,this._engine.branchDirty(this),this._engine.display.imageDirty=!0,this._core.hash="reg-"+b,this},SceneJS.RegionMap.prototype.setRegionData=function(b){return this._core.regionData=b?b:a.regionData,this},SceneJS.RegionMap.prototype._compile=function(a){var b=this._engine.display.regionMap;this._engine.display.regionMap=this._core,this._compileNodes(a),this._engine.display.regionMap=b},SceneJS.RegionMap.prototype._destroy=function(){1==this._core.useCount&&this._core.texture&&!this._core.target&&(this._core.texture.destroy(),this._core.texture=null)}},SceneJS.XForm=SceneJS_NodeFactory.createNodeType("xform"),SceneJS.XForm.prototype._init=function(a){1==this._core.useCount&&(SceneJS_modelXFormStack.buildCore(this._core),this.setElements(a.elements),this.xformParent=null,this.xformChildren=[])},SceneJS.XForm.prototype.getModelMatrix=function(){return this._core.dirty&&this._core.build(),this._core.matrix},SceneJS.XForm.prototype.getWorldMatrix=function(){return this._core.dirty&&this._core.build(),Array.apply([],this._core.mat)},SceneJS.XForm.prototype.setElements=function(a){if(a=a||SceneJS_math_identityMat4(),16!=a.length)throw SceneJS_error.fatalError(SceneJS.errors.ILLEGAL_NODE_CONFIG,"SceneJS.XForm elements should number 16");var b=this._core;if(b.matrix)for(var c=0;c<16;c++)b.matrix[c]=a[c];else b.matrix=a;return b.setDirty(),this._engine.display.imageDirty=!0,this},SceneJS.XForm.prototype._compile=function(a){var b,c,d=this._core;for(d.numCores=0,b=0,c=this.xformChildren.length;b0?a.display.modelTransform=f[g-1]:a.display.modelTransform=e,h=!1)}),this.buildCore=function(a){function b(a){a.dirty=!0,a.matrixDirty=!0;for(var c=0,d=a.numCores;c0?f[g-1]:e,f[g]=null,h=!0}};SceneJS.Types=new function(){this.addType=function(a,b){SceneJS_NodeFactory.createNodeType(a,b,function(a){var c;for(var d in b)if(b.hasOwnProperty(d))switch(c=b[d],d){case"init":case"construct":!function(){var c=b[d];a.prototype._init=function(a){c.call(this,a)},a.prototype._fromPlugin=!0}();break;case"destroy":case"destruct":a.prototype._destroy=c;break;default:a.prototype[d]=c}})},this.hasType=function(a){return!!SceneJS_NodeFactory.nodeTypes[a]}};var SceneJS_Display=function(a,b){this.stats=a||{},this._canvas=b.canvas,this._programFactory=new SceneJS_ProgramFactory(this.stats,{canvas:b.canvas}),this._chunkFactory=new SceneJS_ChunkFactory,this.transparent=b.transparent===!0,this.depthSort=b.depthSort===!0,this.enable=null,this.flags=null,this.layer=null,this.stage=null,this.renderer=null,this.depthBuffer=null,this.stencilBuffer=null,this.colorBuffer=null,this.view=null,this.lights=null,this.material=null,this.texture=null,this.fresnel=null,this.cubemap=null,this.modelTransform=null,this.viewTransform=null,this.projTransform=null,this.billboard=null,this.regionMap=null,this.renderTarget=null,this.clips=null,this.morphGeometry=null,this.name=null,this.tag=null,this.renderListeners=null,this.shader=null,this.shaderParams=null,this.style=null,this.geometry=null,this._objectFactory=new SceneJS_ObjectFactory,this._objects={},this._ambientColor=[0,0,0,1],this._objectList=[],this._objectListLen=0,this._objectPickList=[null],this._objectPickListLen=1,this._drawList=[],this._drawListLen=0,this._pickDrawList=[],this._pickDrawListLen=0,this._targetList=[],this._targetListLen=0,this._objectDrawList=[],this._objectDrawListLen=0,this._drawListTransparentIndex=-1,this._frameCtx={pickNames:[],regionData:[],canvas:this._canvas,VAO:null},this._frameCtx.renderListenerCtx=new SceneJS.RenderContext(this._frameCtx),this.objectListDirty=!0,this.stateOrderDirty=!0,this.stateSortDirty=!0,this.drawListDirty=!0,this.imageDirty=!0,this.bindOutputFrameBuffer=null,this.unbindOutputFrameBuffer=null};SceneJS_Display.prototype.webglRestored=function(){this._programFactory.webglRestored(),this._chunkFactory.webglRestored();var a=this._canvas.gl;this.pickBuf&&this.pickBuf.webglRestored(a),this.imageDirty=!0},SceneJS_Display.prototype.buildObject=function(a){var b=this._objects[a];b||(b=this._objects[a]=this._objectFactory.getObject(a),this.objectListDirty=!0),b.modelTransform=this.modelTransform,b.viewTransform=this.viewTransform,b.projTransform=this.projTransform,b.stage=this.stage,b.layer=this.layer,b.renderTarget=this.renderTarget,b.texture=this.texture,b.cubemap=this.cubemap,b.geometry=this.geometry,b.morphGeometry=this.morphGeometry,b.enable=this.enable,b.flags=this.flags,b.tag=this.tag,b.name=this.name;var c=[this.geometry.hash,this.shader.hash,this.clips.hash,this.morphGeometry.hash,this.texture.hash,this.fresnel.hash,this.cubemap.hash,this.lights.hash,this.flags.hash,this.regionMap.hash,this.billboard.hash].join(";");b.program&&c==b.hash||(b.program&&this._programFactory.putProgram(b.program),b.program=this._programFactory.getProgram(c,this),b.hash=c),this._setChunk(b,0,"program"),this._setChunk(b,1,"xform",this.modelTransform),this._setChunk(b,2,"lookAt",this.viewTransform),this._setChunk(b,3,"camera",this.projTransform),this._setChunk(b,4,"flags",this.flags),this._setChunk(b,5,"shader",this.shader),this._setChunk(b,6,"shaderParams",this.shaderParams),this._setChunk(b,7,"style",this.style),this._setChunk(b,8,"depthBuffer",this.depthBuffer),this._setChunk(b,9,"stencilBuffer",this.stencilBuffer),this._setChunk(b,10,"colorBuffer",this.colorBuffer),this._setChunk(b,11,"view",this.view),this._setChunk(b,12,"lights",this.lights),this._setChunk(b,13,"material",this.material),this._setChunk(b,14,"texture",this.texture),this._setChunk(b,15,"regionMap",this.regionMap),this._setChunk(b,16,"fresnel",this.fresnel),this._setChunk(b,17,"cubemap",this.cubemap),this._setChunk(b,18,"clips",this.clips),this._setChunk(b,19,"renderer",this.renderer),this._setChunk(b,20,"geometry",this.morphGeometry,this.geometry),this._setChunk(b,21,"listeners",this.renderListeners),this._setChunk(b,22,"draw",this.geometry),this.stateOrderDirty=!0},SceneJS_Display.prototype._setChunk=function(a,b,c,d,e){var f,g=this._chunkFactory.chunkTypes[c];if(d){if(d.empty){var h=a.chunks[b];return h&&this._chunkFactory.putChunk(h),void(a.chunks[b]=null)}f=g.prototype.programGlobal?"_"+d.stateId:"p"+a.program.id+"_"+d.stateId,e&&(f+="__"+e.stateId)}else f="p"+a.program.id;f=b+"__"+f;var h=a.chunks[b];if(h){if(h.id==f)return;this._chunkFactory.putChunk(h)}a.chunks[b]=this._chunkFactory.getChunk(f,c,a.program,d,e),"lights"==c&&this._setAmbient(d)},SceneJS_Display.prototype._setAmbient=function(a){for(var b,c=a.lights,d=0,e=c.length;dthis._objectListLen)for(i=this._objectListLen;ithis._drawListLen)for(a=this._drawListLen;athis._pickDrawListLen)for(a=this._pickDrawListLen;athis._objectDrawListLen)for(a=this._objectDrawListLen;athis._objectPickListLen)for(a=this._objectPickListLen;a0&&ha[0].positions)this._lerpTargets(ga.keys,ga.targets,"positions",_,aa,ba,ga.factor,d,e,f);else{var ia=Z.arrays.positions;d[0]=ia[ca],d[1]=ia[ca+1],d[2]=ia[ca+2],e[0]=ia[da],e[1]=ia[da+1],e[2]=ia[da+2],f[0]=ia[ea],f[1]=ia[ea+1],f[2]=ia[ea+2]}var ja=G.position=SceneJS_math_rayPlaneIntersect(a,b,d,e,f,SceneJS_math_vec3());m.set(ja),m[3]=1,SceneJS_math_transformVector4(C.modelTransform.mat,m,n),G.worldPos=SceneJS._sliceArray(n,0,3);var ka=G.barycentric=SceneJS_math_cartesianToBarycentric2(ja,d,e,f,SceneJS_math_vec3()),la=!1;if(ha&&ha.length>0&&ha[0].normals&&(this._lerpTargets(ga.keys,ga.targets,"normals",_,aa,ba,ga.factor,g,h,i),la=!0),!la){var ma=Z.arrays.normals;ma&&(g[0]=ma[ca],g[1]=ma[ca+1],g[2]=ma[ca+2],h[0]=ma[da],h[1]=ma[da+1],h[2]=ma[da+2],i[0]=ma[ea],i[1]=ma[ea+1],i[2]=ma[ea+2],la=!0)}la&&(G.normal=SceneJS_math_addVec3(SceneJS_math_addVec3(SceneJS_math_mulVec3Scalar(g,ka[0],o),SceneJS_math_mulVec3Scalar(h,ka[1],p),q),SceneJS_math_mulVec3Scalar(i,ka[2],r),SceneJS_math_vec3()));var na=Z.arrays.uvs;if(na&&na.length>0){G.uvs=[];var oa,pa,qa=2*_,ra=2*aa,sa=2*ba;for(D=0,E=na.length;D0&&(G.uv=G.uvs[0])}}}return F.unbind(),G},SceneJS_Display.prototype._lerpTargets=function(a,b,c,d,e,f,g,h,i,j){for(var k=0;k=0?this._drawListTransparentIndex:this._drawListLen,f=0;f 0.0) { discard; }"),m("}")}return m(" if (SCENEJS_uPickMode == 0.0) {"),m(" gl_FragColor = SCENEJS_uPickColor; "),m(" } else if (SCENEJS_uPickMode == 1.0) {"),m(" gl_FragColor = SCENEJS_vColor; "),m(" } else {"),m(G?" gl_FragColor = texture2D(SCENEJS_uRegionMapSampler, vec2(SCENEJS_vRegionMapUV.s, 1.0 - SCENEJS_vRegionMapUV.t));":" gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);"),m(" }"),m("}"),n()}function c(){return!p.regionMap.empty&&e()}function d(){return!!(p.texture.layers&&p.texture.layers.length>0)&&e()}function e(){return!!p.geometry.uvBufs||!(!p.morphGeometry.targets||!p.morphGeometry.targets[0].uvBuf&&!p.morphGeometry.targets[0].uvBuf2)}function f(a){return a.flags.reflective&&a.cubemap.layers&&a.cubemap.layers.length>0&&a.geometry.normalBuf}function g(a){return!!a.geometry.normalBuf||!(!a.morphGeometry.targets||!a.morphGeometry.targets[0].normalBuf)}function h(a){if(a.texture){var b=a.texture.layers;if(!b)return!1;for(var c=0,d=b.length;c 0.0) { discard; }"),m("}")}z&&(m("vec3 worldEyeVec = normalize(SCENEJS_uWorldEye - SCENEJS_vWorldVertex.xyz);"),w&&m("vec3 worldNormal = normalize(SCENEJS_vWorldNormal); "),A&&(m(" if (gl_FrontFacing == false) {"),m(" gl_FragColor = vec4(SCENEJS_uSolidColor.xyz, 1.0);"),m(" return;"),m(" }"))),m(" vec3 ambient= SCENEJS_uAmbientColor;"),c.viewPos&&m(c.viewPos+"(SCENEJS_vViewVertex);"),z&&c.viewNormal&&m(c.viewNormal+"(SCENEJS_vViewNormal);"),p.geometry.colorBuf?(m(" vec3 color = SCENEJS_vColor.rgb;"),m(" float colorA = SCENEJS_vColor.a;")):m(" vec3 color = SCENEJS_uMaterialColor;"),m(" float alpha = SCENEJS_uMaterialAlpha;"),m(" float emit = SCENEJS_uMaterialEmit;"),m(" float specular = SCENEJS_uMaterialSpecular;"),m(" vec3 specularColor = SCENEJS_uMaterialSpecularColor;"),m(" vec3 emitColor = SCENEJS_uMaterialEmitColor;"),m(" float shine = SCENEJS_uMaterialShine;"),c.materialBaseColor&&m("color="+c.materialBaseColor+"(color);"),c.materialAlpha&&m("alpha="+c.materialAlpha+"(alpha);"),c.materialEmit&&m("emit="+c.materialEmit+"(emit);"),c.materialSpecular&&m("specular="+c.materialSpecular+"(specular);"),c.materialSpecularColor&&m("specularColor="+c.materialSpecularColor+"(specularColor);"),c.materialShine&&m("shine="+c.materialShine+"(shine);"),z&&(m(" float attenuation = 1.0;"),m(D?" vec3 viewNormalVec = vec3(0.0, 1.0, 0.0);":" vec3 viewNormalVec = normalize(SCENEJS_vViewNormal);"),m("vec3 viewEyeVec = normalize(SCENEJS_vViewEyeVec);"));var r;if(x&&(m(" vec4 texturePos;"),m(" vec2 textureCoord=vec2(0.0,0.0);"),x))for(var j=0,q=p.texture.layers.length;j tolerance) {"),m(" fragColor.a = SCENEJS_uRegionMapHideAlpha;"),m("}"))),c.pixelColor&&m("fragColor="+c.pixelColor+"(fragColor);"),I&&(m(" if (SCENEJS_uDepthMode) {"),m(" float depth = length(SCENEJS_vViewVertex) / (SCENEJS_uZFar - SCENEJS_uZNear);"),m(" const vec4 bias = vec4(1.0 / 255.0,"),m(" 1.0 / 255.0,"),m(" 1.0 / 255.0,"),m(" 0.0);"),m(" float r = depth;"),m(" float g = fract(r * 255.0);"),m(" float b = fract(g * 255.0);"),m(" float a = fract(b * 255.0);"),m(" vec4 colour = vec4(r, g, b, a);"),m(" fragColor = colour - (colour.yzww * bias);"),m(" }")),i&&(m("float fragmentFresnel = fresnel(worldEyeVec, worldNormal, SCENEJS_uFragmentFresnelEdgeBias, SCENEJS_uFragmentFresnelCenterBias, SCENEJS_uFragmentFresnelPower);"),m("fragColor.rgb *= mix(SCENEJS_uFragmentFresnelEdgeColor.rgb, SCENEJS_uFragmentFresnelCenterColor.rgb, fragmentFresnel);")),I||m("fragColor.rgb *= fragColor.a;"),m("gl_FragColor = fragColor;"),m("}"),n()}function l(){L=[]}function m(a){L.push(a||"")}function n(){return L}function o(a){return a.getShaderPrecisionFormat?a.getShaderPrecisionFormat(a.FRAGMENT_SHADER,a.HIGH_FLOAT).precision>0?"highp":a.getShaderPrecisionFormat(a.FRAGMENT_SHADER,a.MEDIUM_FLOAT).precision>0?"mediump":"lowp":"mediump"}var p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I,J,K={},L="";this.getSource=function(e,l){var m=K[e];return m?(m.useCount++,m):(p=l,q=p.fresnel.diffuse,r=p.fresnel.specular,s=p.fresnel.alpha,t=p.fresnel.reflect,u=p.fresnel.emit,v=p.fresnel.fragment,w=q||r||s||t||u||v,x=d(p),y=f(p),z=g(p),A=p.flags.solid,B=p.flags.skybox,C=!p.billboard.empty,D=h(p),E=p.clips.clips.length>0,F=!!p.morphGeometry.targets,G=c(),H=G&&"info"!==p.regionMap.mode,I=i(),J="points"===p.geometry.primitiveName,m=new SceneJS_ProgramSource(e,a(p),b(p),j(p),k(p)),K[e]=m,m)},this.putSource=function(a){var b=K[a];b&&0==--b.useCount&&(K[b.hash]=null)}},SceneJS_ProgramSource=function(a,b,c,d,e){this.hash=a,this.pickVertexSrc=b,this.pickFragmentSrc=c,this.drawVertexSrc=d,this.drawFragmentSrc=e,this.useCount=0},SceneJS_ProgramFactory=function(a,b){this.stats=a,this._canvas=b.canvas,this._programs={},this._nextProgramId=0};SceneJS_ProgramFactory.prototype.getProgram=function(a,b){var c=this._programs[a];if(!c){var d=SceneJS_ProgramSourceFactory.getSource(a,b);c=new SceneJS_Program(this.stats,this._nextProgramId++,a,d,this._canvas.gl),this._programs[a]=c,this.stats.memory.programs++}return c.useCount++,c},SceneJS_ProgramFactory.prototype.putProgram=function(a){--a.useCount<=0&&(a.draw.destroy(),a.pick.destroy(),SceneJS_ProgramSourceFactory.putSource(a.hash),delete this._programs[a.hash],this.stats.memory.programs--)},SceneJS_ProgramFactory.prototype.webglRestored=function(){var a,b=this._canvas.gl;for(var c in this._programs)this._programs.hasOwnProperty(c)&&(a=this._programs[c],a&&a.build&&a.build(b))},SceneJS_ProgramFactory.prototype.destroy=function(){};var SceneJS_Program=function(a,b,c,d,e){this.stats=a,this.id=b,this.hash=d.hash,this.source=d,this.gl=e,this.draw=null,this.pick=null,this.useCount=0,this.build(e)};SceneJS_Program.prototype.build=function(a){this.gl=a,this.draw=new SceneJS._webgl.Program(this.stats,a,[this.source.drawVertexSrc.join("\n")],[this.source.drawFragmentSrc.join("\n")]),this.pick=new SceneJS._webgl.Program(this.stats,a,[this.source.pickVertexSrc.join("\n")],[this.source.pickFragmentSrc.join("\n")])};var SceneJS_ObjectFactory=function(){};SceneJS_ObjectFactory.prototype._freeObjects=[],SceneJS_ObjectFactory.prototype._numFreeObjects=0,SceneJS_ObjectFactory.prototype.getObject=function(a){var b;return this._numFreeObjects>0?(b=this._freeObjects[--this._numFreeObjects],b.id=a,b):new SceneJS_Object(a)},SceneJS_ObjectFactory.prototype.putObject=function(a){};var SceneJS_Object=function(a){this.id=a,this.hash=null,this.sortKey1=null,this.sortKey2=null,this.chunks=[],this.chunksLen=0,this.program=null,this.layer=null,this.texture=null,this.flags=null,this.tag=null,this.centroid=null};!function(){var a=new SceneJS_math_vec4;SceneJS_Object.prototype.getDepth=function(){this.centroid||(this.centroid=this._calculateCentroid(this));var b=this.modelTransform.mat,c=this.viewTransform.mat,d=SceneJS_math_transformVector4(b,this.centroid,a);return SceneJS_math_transformVector4(c,d,d),-d[2]},SceneJS_Object.prototype._calculateCentroid=function(){for(var a=SceneJS_math_vec4(),b=this.geometry.arrays.positions,c=this.geometry.arrays.indices,d=1/0,e=1/0,f=1/0,g=-(1/0),h=-(1/0),i=-(1/0),j=Math.min,k=Math.max,l=0,m=c.length;l>24&255,e=a.pickIndex>>16&255,f=a.pickIndex>>8&255,g=255&a.pickIndex;a.pickIndex++,this._uPickColor.setValue([g/255,f/255,e/255,d/255])}b.indexBuf?c.drawElements(b.primitive,b.indexBuf.numItems,b.indexBuf.itemType,0):c.drawArrays(b.primitive,0,b.vertexBuf.numItems/3)}else if(a.pickTriangle){var h=b.getPickPositions();h&&c.drawArrays(b.primitive,0,h.numItems/3)}}}),SceneJS_ChunkFactory.createChunkType({type:"flags",build:function(){var a=this.program.draw;this._uClippingDraw=a.getUniform("SCENEJS_uClipping"),this._uSolidDraw=a.getUniform("SCENEJS_uSolid"),this._uSolidColorDraw=a.getUniform("SCENEJS_uSolidColor");var b=this.program.pick;this._uClippingPick=b.getUniform("SCENEJS_uClipping")},drawAndPick:function(a){var b=this.program.gl,c=this.core.backfaces;a.backfaces!=c&&(c?b.disable(b.CULL_FACE):b.enable(b.CULL_FACE),a.backfaces=c);var d=this.core.frontface;a.frontface!=d&&("ccw"==d?b.frontFace(b.CCW):b.frontFace(b.CW),a.frontface=d);var e=a.picking;if(e)this._uClippingPick&&this._uClippingPick.setValue(this.core.clipping);else{var f=this.core.transparent;a.transparent!=f&&(f?(b.enable(b.BLEND),b.blendFunc(b.ONE,b.ONE_MINUS_SRC_ALPHA),a.blendEnabled=!0):(b.disable(b.BLEND),a.blendEnabled=!1),a.transparent=f),this._uClippingDraw&&this._uClippingDraw.setValue(this.core.clipping),this._uSolidDraw&&this._uSolidDraw.setValue(this.core.solid),this._uSolidColorDraw&&this._uSolidColorDraw.setValue(this.core.solidColor),this.core.clearColorBuffer&&b.clear(b.COLOR_BUFFER_BIT)}}}),SceneJS_ChunkFactory.createChunkType({type:"renderTarget",programGlobal:!0,draw:function(a){var b=this.program.gl;a.renderBuf&&(b.flush(),a.renderBuf.unbind(),a.renderBuf=null);var c=this.core.renderBuf;return c?(c.bind(),a.depthMode="depth"===this.core.bufType,a.depthMode||a.blendEnabled&&(b.enable(b.BLEND),b.blendFunc(b.ONE,b.ONE_MINUS_SRC_ALPHA)),b.viewport(0,0,b.drawingBufferWidth,b.drawingBufferHeight),b.clearColor(a.ambientColor[0],a.ambientColor[1],a.ambientColor[2],1),b.clear(b.COLOR_BUFFER_BIT|b.DEPTH_BUFFER_BIT),void(a.renderBuf=c)):void(a.depthMode=!1)}}),SceneJS_ChunkFactory.createChunkType({type:"geometry",build:function(){var a=this.program.draw;this._aRegionMapUVDraw=a.getAttribute("SCENEJS_aRegionMapUV"),this._aVertexDraw=a.getAttribute("SCENEJS_aVertex"),this._aNormalDraw=a.getAttribute("SCENEJS_aNormal"),this._aUVDraw=[];for(var b,c=0;c<1e3&&(b=a.getAttribute("SCENEJS_aUVCoord"+c),b);c++)this._aUVDraw.push(b);this._aTangentDraw=a.getAttribute("SCENEJS_aTangent"),this._aColorDraw=a.getAttribute("SCENEJS_aVertexColor"),this._aMorphVertexDraw=a.getAttribute("SCENEJS_aMorphVertex"),this._aMorphNormalDraw=a.getAttribute("SCENEJS_aMorphNormal"),this._aMorphTangentDraw=a.getAttribute("SCENEJS_aMorphTangent"),this._uMorphFactorDraw=a.getUniform("SCENEJS_uMorphFactor"),this._uPointSizeDraw=a.getUniform("SCENEJS_uPointSize");var d=this.program.pick;this._aRegionMapUVPick=d.getAttribute("SCENEJS_aRegionMapUV"),this._aVertexPick=d.getAttribute("SCENEJS_aVertex"),this._aColorPick=d.getAttribute("SCENEJS_aColor"),this._aMorphVertexPick=d.getAttribute("SCENEJS_aMorphVertex"),this._uMorphFactorPick=d.getUniform("SCENEJS_uMorphFactor"),this._uPointSizePick=a.getUniform("SCENEJS_uPointSize"),this.VAO=null,this.VAOMorphKey1=0,this.VAOMorphKey2=0,this.VAOHasInterleavedBuf=!1},recycle:function(){if(this.VAO){var a=this.program.gl.getExtension("OES_vertex_array_object");a.deleteVertexArrayOES(this.VAO),this.VAO=null}},morphDraw:function(a){this.VAOMorphKey1=this.core.key1,this.VAOMorphKey2=this.core.key2;var b=this.core.key1,c=this.core.key2,d=this.core.targets[b],e=this.core.targets[c];if(this._aMorphVertexDraw?(this._aVertexDraw.bindFloatArrayBuffer(d.vertexBuf),this._aMorphVertexDraw.bindFloatArrayBuffer(e.vertexBuf),a.bindArray+=2):this._aVertexDraw&&(this._aVertexDraw.bindFloatArrayBuffer(this.core2.vertexBuf),a.bindArray++),this._aMorphNormalDraw?(this._aNormalDraw.bindFloatArrayBuffer(d.normalBuf),this._aMorphNormalDraw.bindFloatArrayBuffer(e.normalBuf),a.bindArray+=2):this._aNormalDraw&&(this._aNormalDraw.bindFloatArrayBuffer(this.core2.normalBuf),a.bindArray++),this._aMorphTangentDraw||this._aTangentDraw){var f=a.normalMapUVLayerIdx;f>=0&&(this._aMorphTangentDraw?(this._aTangentDraw.bindFloatArrayBuffer(this.core.getTangents(b,this.core2.arrays.indices,this.core2.arrays.uvs[f])),this._aMorphTangentDraw.bindFloatArrayBuffer(this.core.getTangents(c,this.core2.arrays.indices,this.core2.arrays.uvs[f])),a.bindArray+=2):this._aTangentDraw)}for(var g,h=0,i=this._aUVDraw.length;h=0&&(this._aTangentDraw.bindFloatArrayBuffer(this.core2.getTangents(g)),a.bindArray++)}}if(this._aRegionMapUVDraw){var h=a.regionMapUVLayerIdx;if(h>=0){var i=this.core2.uvBufs;h=0;d--)if(b[d](c)===!0)return!0}}),SceneJS_ChunkFactory.createChunkType({type:"lookAt",build:function(){this._uvMatrixDraw=this.program.draw.getUniform("SCENEJS_uVMatrix"),this._uVNMatrixDraw=this.program.draw.getUniform("SCENEJS_uVNMatrix"),this._uWorldEyeDraw=this.program.draw.getUniform("SCENEJS_uWorldEye"),this._uWorldLookDraw=this.program.draw.getUniform("SCENEJS_uWorldLook"),this._uvMatrixPick=this.program.pick.getUniform("SCENEJS_uVMatrix")},draw:function(a){this.core.dirty&&this.core.rebuild();this.program.gl;this._uvMatrixDraw&&this._uvMatrixDraw.setValue(this.core.mat),this._uVNMatrixDraw&&this._uVNMatrixDraw.setValue(this.core.normalMat),this._uWorldEyeDraw&&this._uWorldEyeDraw.setValue(this.core.lookAt.eye),this._uWorldLookDraw&&this._uWorldLookDraw.setValue(this.core.lookAt.look),a.viewMat=this.core.mat},pick:function(a){this._uvMatrixPick&&this._uvMatrixPick.setValue(a.pickMatrix||this.core.mat),a.viewMat=this.core.mat}}),SceneJS_ChunkFactory.createChunkType({type:"material",build:function(){var a=this.program.draw;this._uMaterialBaseColor=a.getUniform("SCENEJS_uMaterialColor"),this._uMaterialSpecularColor=a.getUniform("SCENEJS_uMaterialSpecularColor"),this._uMaterialEmitColor=a.getUniform("SCENEJS_uMaterialEmitColor"),this._uMaterialSpecular=a.getUniform("SCENEJS_uMaterialSpecular"),this._uMaterialShine=a.getUniform("SCENEJS_uMaterialShine"),this._uMaterialEmit=a.getUniform("SCENEJS_uMaterialEmit"),this._uMaterialAlpha=a.getUniform("SCENEJS_uMaterialAlpha")},draw:function(){this.program.gl;this._uMaterialBaseColor&&this._uMaterialBaseColor.setValue(this.core.baseColor),this._uMaterialSpecularColor&&this._uMaterialSpecularColor.setValue(this.core.specularColor),this._uMaterialEmitColor&&this._uMaterialEmitColor.setValue(this.core.emitColor),this._uMaterialSpecular&&this._uMaterialSpecular.setValue(this.core.specular),this._uMaterialShine&&this._uMaterialShine.setValue(this.core.shine),this._uMaterialEmit&&this._uMaterialEmit.setValue(this.core.emit),this._uMaterialAlpha&&this._uMaterialAlpha.setValue(this.core.alpha)}}),SceneJS_ChunkFactory.createChunkType({type:"program",build:function(){this._depthModeDraw=this.program.draw.getUniform("SCENEJS_uDepthMode"),this._pickMode=this.program.pick.getUniform("SCENEJS_uPickMode")},draw:function(a){var b=this.program.draw;b.bind(),a.textureUnit=0;var c=this.program.gl;if(this._depthModeDraw&&this._depthModeDraw.setValue(a.depthMode),!a.VAO)for(var d=0;d<10;d++)c.disableVertexAttribArray(d);a.drawProgram=this.program.draw,a.useProgram++},pick:function(a){var b=this.program.pick;b.bind();var c=this.program.gl;a.pickObject?this._pickMode.setValue(0):a.pickTriangle?this._pickMode.setValue(1):this._pickMode.setValue(2),a.textureUnit=0;for(var d=0;d<10;d++)c.disableVertexAttribArray(d)}}),SceneJS_ChunkFactory.createChunkType({type:"renderer",build:function(){},drawAndPick:function(a){if(this.core.props){var b=this.program.gl;a.renderer&&(a.renderer.props.restoreProps(b),a.renderer=this.core),this.core.props.setProps(b)}}}),SceneJS_ChunkFactory.createChunkType({type:"regionMap",build:function(){this._uRegionMapRegionColor=this.program.draw.getUniform("SCENEJS_uRegionMapRegionColor"),this._uRegionMapHighlightFactor=this.program.draw.getUniform("SCENEJS_uRegionMapHighlightFactor"),this._uRegionMapHideAlpha=this.program.draw.getUniform("SCENEJS_uRegionMapHideAlpha"),this._uRegionMapSampler="SCENEJS_uRegionMapSampler"},draw:function(a){var b=this.core.texture;b&&(this.program.draw.bindTexture(this._uRegionMapSampler,b,a.textureUnit),a.textureUnit=(a.textureUnit+1)%SceneJS.WEBGL_INFO.MAX_TEXTURE_UNITS);var c=this.program.gl,d="hide"===this.core.mode||"isolate"===this.core.mode;a.transparent!=d&&(d?(c.enable(c.BLEND),c.blendFunc(c.ONE,c.ONE_MINUS_SRC_ALPHA),a.blendEnabled=!0):(c.disable(c.BLEND),a.blendEnabled=!1),a.transparent=d),b?(this._uRegionMapRegionColor&&this._uRegionMapRegionColor.setValue(this.core.regionColor),this._uRegionMapHighlightFactor&&this._uRegionMapHighlightFactor.setValue(this.core.highlightFactor),this._uRegionMapHideAlpha&&this._uRegionMapHideAlpha.setValue(this.core.hideAlpha),a.regionMapUVLayerIdx=this.core.uvLayerIdx):a.regionMapUVLayerIdx=-1},pick:function(a){var b=this.core.texture;b?(a.regionData=this.core.regionData,a.textureUnit=0,this.program.pick.bindTexture(this._uRegionMapSampler,b,a.textureUnit),a.textureUnit=(a.textureUnit+1)%SceneJS.WEBGL_INFO.MAX_TEXTURE_UNITS,a.regionMapUVLayerIdx=this.core.uvLayerIdx):a.regionMapUVLayerIdx=-1}}),SceneJS_ChunkFactory.createChunkType({type:"depthBuffer",programGlobal:!0,drawAndPick:function(a){var b=this.program.gl,c=this.core.enabled;a.depthbufEnabled!=c&&(c?b.enable(b.DEPTH_TEST):b.disable(b.DEPTH_TEST),a.depthbufEnabled=c);var d=this.core.clearDepth;a.clearDepth!=d&&(b.clearDepth(d),a.clearDepth=d);var e=this.core.depthFunc;a.depthFunc!=e&&(b.depthFunc(e),a.depthFunc=e),this.core.clear&&b.clear(b.DEPTH_BUFFER_BIT)}}),SceneJS_ChunkFactory.createChunkType({type:"stencilBuffer",programGlobal:!0,drawAndPick:function(a){var b=this.program.gl,c=this.core.enabled;a.stencilbufEnabled!=c&&(c?b.enable(b.STENCIL_TEST):b.disable(b.STENCIL_TEST),a.stencilbufEnabled=c);var d=this.core.clearStencil;void 0!==d&&a.clearStencil!=d&&(b.clearStencil(d),a.clearStencil=d);var e=this.core.stencilFuncFuncFront,f=this.core.stencilFuncRefFront,g=this.core.stencilFuncMaskFront;e&&(a.stencilFuncFuncFront==e&&a.stencilFuncRefFront==f&&a.stencilFuncMaskFront==g||(b.stencilFuncSeparate(b.FRONT,e,f,g),a.stencilFuncFuncFront=e,a.stencilFuncRefFront=f,a.stencilFuncMaskFront=g));var h=this.core.stencilFuncFuncBack,i=this.core.stencilFuncRefBack,j=this.core.stencilFuncMaskBack;h&&(a.stencilFuncFuncBack==h&&a.stencilFuncRefBack==i&&a.stencilFuncMaskBack==j||(b.stencilFuncSeparate(b.BACK,h,i,j),a.stencilFuncFuncBack=h,a.stencilFuncRefBack=i,a.stencilFuncMaskBack=j));var k=this.core.stencilOpSfailFront,l=this.core.stencilOpDpfailFront,m=this.core.stencilOpDppassFront;k&&(a.stencilOpSfailFront==k&&a.stencilOpDpfailFront==l&&a.stencilOpDppassFront==m||(b.stencilOpSeparate(b.FRONT,k,l,m),a.stencilOpSfailFront=k,a.stencilOpDpfailFront=l,a.stencilOpDppassFront=m));var n=this.core.stencilOpSfailBack,o=this.core.stencilOpDpfailBack,p=this.core.stencilOpDppassBack;n&&(a.stencilOpSfailBack==n&&a.stencilOpDpfailBack==o&&a.stencilOpDppassBack==p||(b.stencilOpSeparate(b.BACK,n,o,p),a.stencilOpSfailBack=n,a.stencilOpDpfailBack=o,a.stencilOpDppassBack=p)),this.core.clear&&b.clear(b.STENCIL_BUFFER_BIT)}}),SceneJS_ChunkFactory.createChunkType({type:"colorBuffer",programGlobal:!0,build:function(){},drawAndPick:function(a){if(!a.transparent){var b=this.core.blendEnabled,c=this.program.gl;a.blendEnabled!=b&&(b?c.enable(c.BLEND):c.disable(c.BLEND),a.blendEnabled=b);var d=this.core.colorMask;c.colorMask(d.r,d.g,d.b,d.a)}}}),SceneJS_ChunkFactory.createChunkType({type:"view",programGlobal:!0,build:function(){},drawAndPick:function(a){var b=this.core.scissorTestEnabled;if(a.scissorTestEnabled!=b){var c=this.program.gl;b?c.enable(c.SCISSOR_TEST):c.disable(c.SCISSOR_TEST),a.scissorTestEnabled=b}}}),SceneJS_ChunkFactory.createChunkType({type:"shader",build:function(){},drawAndPick:function(a){var b=this.core.paramsStack;if(b)for(var c,d,e=a.picking?this.program.pick:this.program.draw,f=0,g=b.length;f=0;f--){var g=a[f];if("node"==g.type||this._engine.hasNodeType(g.type)){if(c=this.addNode(g),d[f]=c,0==--e)return b&&b(a),a}else{var h=this;!function(){var c=f;h.addNode(g,function(f){d[c]=f,0==--e&&b&&b(a)})}()}}return null},SceneJS.Node.prototype.addNode=function(a,b){if(a=a||{},a._compile){if(null!=a.parent)throw SceneJS_error.fatalError(SceneJS.errors.ILLEGAL_NODE_CONFIG,"Node#addNode - node argument is still attached to another parent");return this.nodes.push(a),a.parent=this,a._connectToScene(),this._engine.branchDirty(a),b&&b(a),a}if("string"==typeof a){var c=this._engine.findNode(a);if(!c)throw SceneJS_error.fatalError(SceneJS.errors.ILLEGAL_NODE_CONFIG,"Node#addNode - node not found: '"+a+"'");if(a=c,null!=a.parent)throw SceneJS_error.fatalError(SceneJS.errors.ILLEGAL_NODE_CONFIG,"Node#addNode - node argument is still attached to another parent");return this.nodes.push(a),a.parent=this,a._connectToScene(),this._engine.branchDirty(a),b&&b(a),a}if(a.type=a.type||"node","node"==a.type||this._engine.hasNodeType(a.type))return a=this._engine.createNode(a),this.nodes.push(a),a.parent=this,a._connectToScene(),this._engine.branchDirty(a),b&&b(a),a;var d=this;return this._engine.createNode(a,function(a){d.nodes.push(a),a.parent=d,a._connectToScene(),d._engine.branchDirty(a),b&&b(a)}),null},SceneJS.Node.prototype.insertNode=function(a,b){if(!a)throw SceneJS_error.fatalError(SceneJS.errors.ILLEGAL_NODE_CONFIG,"SceneJS.Node#insertNode - node argument is undefined");if(a._compile||(a=this._engine.createNode(a)),!a._compile)throw SceneJS_error.fatalError(SceneJS.errors.ILLEGAL_NODE_CONFIG,"SceneJS.Node#insertNode - node argument is not a SceneJS.Node");if(null!=a.parent)throw SceneJS_error.fatalError(SceneJS.errors.ILLEGAL_NODE_CONFIG,"SceneJS.Node#insertNode - node argument is still attached to another parent");if(void 0===b||null===b)a.addNodes(this.disconnectNodes()),this.addNode(a);else{if(b<0)throw SceneJS_error.fatalError(SceneJS.errors.ILLEGAL_NODE_CONFIG,"SceneJS.Node#insertNode - node index out of range: -1");b>=this.nodes.length?this.nodes.push(a):this.nodes.splice(b,0,a)}return a.parent=this,a._connectToScene(),a},SceneJS.Node.prototype.mapNodes=function(a){if(a(this))return this;for(var b,c=0;c0},SceneJS.Node.prototype.removeListeners=function(){return this._listeners={},this._numListeners=0,this},SceneJS.Node.prototype.getParent=function(a){return this.parent},SceneJS.Node.prototype.getParentOfType=function(a){for(var b=this.parent;b&&b.type!=a;)b=b.parent;return b},SceneJS.Node.prototype.eachParent=function(a){if(!a)throw"SceneJS.Node.eachParent param 'fn' is null or undefined";for(var b=0,c=this;c.parent;){if(a.call(c.parent,b++)===!0)return c.parent;c=c.parent}return null},SceneJS.Node.prototype.hasNode=function(a){if(null===a||void 0===a)throw"SceneJS.Node.hasNode param 'node' is null or undefined";var b,c=typeof a;if("number"==c)b=this.getNodeAt(a);else{if("string"!=c)throw"SceneJS.Node.hasNode param 'node' should be either an index number or an ID string";b=this.getNode(a)}return void 0!=b&&null!=b},SceneJS.Node.prototype.node=function(a){if(null===a||void 0===a)throw"SceneJS.Node.node param 'node' is null or undefined";var b,c=typeof a;if("number"==c)b=this.getNodeAt(a);else{if("string"!=c)throw"SceneJS.Node.node param 'node' should be either an index number or an ID string";b=this.getNode(a)}if(!b)throw"SceneJS.Node.node - node not found: '"+a+"'";return b},SceneJS.Node.prototype.eachNode=function(a,b){if(!a)throw"SceneJS.Node.eachNode param 'fn' is null or undefined";if("function"!=typeof a)throw"SceneJS.Node.eachNode param 'fn' should be a function";var c;b=b||{};var d=0;return b.andSelf&&a.call(this,d++)===!0?this:(b.depthFirst||b.breadthFirst?b.depthFirst&&(c=this._iterateEachNodeDepthFirst(a,this,d,!1)):c=this._iterateEachNode(a,this,d),c?c:void 0)},SceneJS.Node.prototype.numNodes=function(){return this.nodes.length},SceneJS.Node.prototype._iterateEachNode=function(a,b,c){for(var d,e=b.nodes.length,f=0;f0;)f.pop()(e);delete f[a]}return d},SceneJS_NodeFactory.prototype.getNode=function(a,b,c,d){b.type=b.type||"node";var e;if(e="node"==b.type?SceneJS.Node:SceneJS_NodeFactory.nodeTypes[b.type])return this._createNode(e,a,b,c,d);var f=this;this._getType(a,b.type,function(e){f._createNode(e,a,b,c,d)})},SceneJS_NodeFactory.prototype._createNode=function(a,b,c,d,e){var f=new a,g=c.id||c.nodeId;return g?this.nodes.addItem(g,f):g=this.nodes.addItem(f),f._construct(b,d,c,g),e&&e(f),f},SceneJS_NodeFactory.prototype._getType=function(a,b,c){var d=SceneJS_NodeFactory.nodeTypes[b];if(d)return void c(d);var e=SceneJS_NodeFactory._subs[b]||(SceneJS_NodeFactory._subs[b]=[]);if(e.push(c),!(e.length>1)){var f=SceneJS_sceneStatusModule.taskStarted(a.scene,"Loading plugin");e.push(function(){SceneJS_sceneStatusModule.taskFinished(f)});var g=SceneJS_configsModule.configs.pluginPath;if(!g)throw"no typePath config";this._loadScript(g+"/node/"+b+".js",function(){SceneJS_sceneStatusModule.taskFailed(f)})}},SceneJS_NodeFactory.prototype._loadScript=function(a,b){var c=document.createElement("script");c.type="text/javascript",c.src=a,c.onerror=b,document.getElementsByTagName("head")[0].appendChild(c)},SceneJS_NodeFactory.prototype.putNode=function(a){this.nodes.removeItem(a.id)},new function(){var a={type:"billboard",stateId:SceneJS._baseStateId++,empty:!0,hash:""};SceneJS_events.addListener(SceneJS_events.SCENE_COMPILING,function(b){b.engine.display.billboard=a,c=0});var b=[],c=0;SceneJS.Billboard=SceneJS_NodeFactory.createNodeType("billboard"),SceneJS.Billboard.prototype._init=function(a){1==this._core.useCount&&(this._core.spherical=a.spherical!==!1),this._core.hash="bb;"},SceneJS.Billboard.prototype.setSpherical=function(a){this._core.spherical=a,this._engine.branchDirty(this),this._engine.display.imageDirty=!0},SceneJS.Billboard.prototype.getSpherical=function(){return this._core.spherical},SceneJS.Billboard.prototype._compile=function(d){b[c++]=this._core,this._engine.display.billboard=this._core,this._compileNodes(d),this._engine.display.billboard=--c>0?b[c-1]:a},SceneJS.Billboard.prototype._destroy=function(){this._core&&this._engine._coreFactory.putCore(this._core)}},function(){function a(a){var b=a.optics;if("ortho"==b.type?a.matrix=SceneJS_math_orthoMat4c(b.left,b.right,b.bottom,b.top,b.near,b.far):"frustum"==b.type?a.matrix=SceneJS_math_frustumMatrix4(b.left,b.right,b.bottom,b.top,b.near,b.far):"frustumAngles"==b.type?a.matrix=SceneJS_math_frustumMatrix4FromAngles(b.left,b.right,b.down,b.up,b.near,b.far):"perspective"==b.type&&(a.matrix=SceneJS_math_perspectiveMatrix4(b.fovy*Math.PI/180,b.aspect,b.near,b.far)),a.pan){var c=a.pan,d=SceneJS_math_translationMat4v([c.x||0,c.y||0,c.z||0]);a.matrix=SceneJS_math_mulMat4(d,a.matrix,[])}a.mat?a.mat.set(a.matrix):a.mat=new Float32Array(a.matrix)}var b=SceneJS_math_perspectiveMatrix4(45,1,.1,1e4),c=new Float32Array(b),d={type:"camera",stateId:SceneJS._baseStateId++,matrix:b,mat:c,optics:{type:"perspective",fovy:45,aspect:1,near:.1,far:1e4},checkAspect:function(b,c){b.optics.aspect!=c&&(b.optics.aspect=c,a(this))}},e=[],f=0;SceneJS_events.addListener(SceneJS_events.SCENE_COMPILING,function(a){a.engine.display.projTransform=d,f=0}),SceneJS.Camera=SceneJS_NodeFactory.createNodeType("camera"),SceneJS.Camera.prototype._init=function(b){if(1==this._core.useCount){b.optics=b.optics||{};var c=this.getScene().getCanvas();b.optics.aspect=c.width/c.height,this.setOptics(b.optics),b.pan&&this.setPan(b.pan);var d=this;this._canvasSizeSub=this.getScene().on("canvasSize",function(b){d._core.optics.aspect=b.aspect,a(d._core),d._engine.display.imageDirty=!0})}},SceneJS.Camera.getDefaultMatrix=function(){return c},SceneJS.Camera.prototype.setOptics=function(b){var c=this._core;if(b){var d=b.type;if(d||c.optics&&(d=c.optics.type),d=d||"perspective","ortho"==d)c.optics=SceneJS._applyIf(SceneJS_math_ORTHO_OBJ,{type:d,left:b.left,bottom:b.bottom,near:b.near,right:b.right,top:b.top,far:b.far});else if("frustum"==d)c.optics={type:d,left:b.left||-1,bottom:b.bottom||-1,near:b.near||.1,right:b.right||1,top:b.top||1,far:b.far||1e4};else if("frustumAngles"==d)c.optics={type:d,left:b.left||22,down:b.down||22,near:b.near||.1,right:b.right||22,up:b.up||22,far:b.far||1e4};else{if("perspective"!=d)throw b.type?SceneJS_error.fatalError(SceneJS.errors.ILLEGAL_NODE_CONFIG,"SceneJS.Camera configuration invalid: optics type not supported - supported types are 'perspective', 'frustum', 'frustumAngles' and 'ortho'"):SceneJS_error.fatalError(SceneJS.errors.ILLEGAL_NODE_CONFIG,"SceneJS.Camera configuration invalid: optics type not specified - supported types are 'perspective', 'frustum', 'frustumAngles' and 'ortho'");c.optics={type:d,fovy:b.fovy||60,aspect:void 0==b.aspect?1:b.aspect,near:b.near||.1,far:b.far||1e4}}}else c.optics={type:"perspective",fovy:60,aspect:1,near:.1,far:1e4};this._core.optics.pan=b.pan,a(this._core),this.publish("matrix",this._core.matrix),this._engine.display.imageDirty=!0},SceneJS.Camera.prototype.setPan=function(b){this._core.pan=b,a(this._core),this.publish("matrix",this._core.matrix),this._engine.display.imageDirty=!0},SceneJS.Camera.prototype.getOptics=function(){var a={};for(var b in this._core.optics)this._core.optics.hasOwnProperty(b)&&(a[b]=this._core.optics[b]);return a},SceneJS.Camera.prototype.setMatrix=function(a){this._core.matrix=a,this._core.mat=a,this.publish("matrix",this._core.matrix),this._engine.display.imageDirty=!0},SceneJS.Camera.prototype.getMatrix=function(){return SceneJS._sliceArray(this._core.matrix,0)},SceneJS.Camera.prototype.setMatrix=function(a){this._core.matrix=a,this._core.mat=a,this.publish("matrix",this._core.matrix),this._engine.display.imageDirty=!0},SceneJS.Camera.prototype._compile=function(a){this._engine.display.projTransform=e[f++]=this._core,this._compileNodes(a),this._engine.display.projTransform=--f>0?e[f-1]:d,e[f]=null},SceneJS.Camera.prototype._destroy=function(){this.getScene().off(this._canvasSizeSub)}}(),function(){var a={type:"clips",stateId:SceneJS._baseStateId++,empty:!0,hash:"",clips:[]},b=[],c=0;SceneJS_events.addListener(SceneJS_events.SCENE_COMPILING,function(b){b.engine.display.clips=a,c=0}),SceneJS.Clips=SceneJS_NodeFactory.createNodeType("clips"),SceneJS.Clips.prototype._init=function(a){if(1==this._core.useCount){var b=a.clips;if(!b)throw SceneJS_error.fatalError(SceneJS.errors.NODE_CONFIG_EXPECTED,"clips node attribute missing : 'clips'");this._core.clips=this._core.clips||[];for(var c=0,d=b.length;c=this._core.clips.length)throw SceneJS_error.fatalError(SceneJS.errors.ILLEGAL_NODE_CONFIG,"Invalid argument to set 'clips': index out of range ("+this._core.clips.length+" clips defined)");this._setClip(b,a[c]||{})}this._engine.display.imageDirty=!0},SceneJS.Clips.prototype._setClip=function(a,b){var c=this._core.clips[a]||(this._core.clips[a]={});c.normalAndDist=[b.x||0,b.y||0,b.z||0,b.dist||0];var d=b.mode||c.mode||"disabled";if("inside"!=d&&"outside"!=d&&"disabled"!=d)throw SceneJS_error.fatalError(SceneJS.errors.ILLEGAL_NODE_CONFIG,"clips node invalid value for property 'mode': should be 'inside' or 'outside' or 'disabled'");c.mode=d,this._core.hash=null},SceneJS.Clips.prototype._compile=function(d){this._core.hash||(this._core.hash=this._core.clips.length),this._engine.display.clips=b[c++]=this._core,this._compileNodes(d),this._engine.display.clips=--c>0?b[c-1]:a,b[c]=null}}(),function(){var a={stateId:SceneJS._baseStateId++,type:"enable",enabled:!0},b=[],c=0;SceneJS_events.addListener(SceneJS_events.SCENE_COMPILING,function(b){b.engine.display.enable=a,c=0}),SceneJS.Enable=SceneJS_NodeFactory.createNodeType("enable"),SceneJS.Enable.prototype._init=function(a){1==this._core.useCount&&(this._core.enabled=!0,void 0!=a.enabled&&this.setEnabled(a.enabled))},SceneJS.Enable.prototype.setEnabled=function(a){return a!==this._core.enabled&&(this._core.enabled=a,this._engine.display.drawListDirty=!0,this.publish("enabled",a)),this},SceneJS.Enable.prototype.getEnabled=function(){return this._core.enabled},SceneJS.Enable.prototype._compile=function(d){this._engine.display.enable=b[c++]=this._core,this._compileNodes(d),this._engine.display.enable=--c>0?b[c-1]:a,b[c]=null}}(),function(){function a(a){return(a.reflective?"refl":"")+";"+(a.solid?"s":"")+";"+(a.skybox?"sky":"")+";"}var b={stateId:SceneJS._baseStateId++,type:"flags",picking:!0,clipping:!0,enabled:!0,transparent:!1,backfaces:!0,frontface:"ccw",reflective:!0,solid:!1,solidColor:[1,1,1],skybox:!1,hash:"refl;;;",clearColorBuffer:!1},c=[],d=0;SceneJS_events.addListener(SceneJS_events.SCENE_COMPILING,function(a){a.engine.display.flags=b,d=0}),SceneJS.Flags=SceneJS_NodeFactory.createNodeType("flags"),SceneJS.Flags.prototype._init=function(a){1==this._core.useCount&&(this._core.picking=!0,this._core.clipping=!0,this._core.enabled=!0,this._core.transparent=!1,this._core.backfaces=!0,this._core.frontface="ccw",this._core.reflective=!0,this._core.solid=!1,this._core.solidColor=[1,1,1],this._core.skybox=!1,a.flags&&this.setFlags(a.flags))},SceneJS.Flags.prototype.setFlags=function(c){var d=this._core;if(void 0!=c.picking&&(d.picking=!!c.picking,this._engine.display.drawListDirty=!0),void 0!=c.clipping&&(d.clipping=!!c.clipping,this._engine.display.imageDirty=!0),void 0!=c.clearColorBuffer&&(d.clearColorBuffer=c.clearColorBuffer,this._engine.display.imageDirty=!0),void 0!=c.enabled&&(d.enabled=!!c.enabled,this._engine.display.drawListDirty=!0),void 0!=c.transparent&&(d.transparent=!!c.transparent,this._engine.display.stateSortDirty=!0),void 0!=c.backfaces&&(d.backfaces=!!c.backfaces,this._engine.display.imageDirty=!0),void 0!=c.frontface&&(d.frontface=c.frontface,this._engine.display.imageDirty=!0),void 0!=c.reflective&&(d.reflective=c.reflective,this._engine.branchDirty(this),this._engine.display.imageDirty=!0),void 0!=c.solid&&(d.solid=c.solid,this._engine.branchDirty(this),this._engine.display.imageDirty=!0),void 0!=c.solidColor){var e=b.solidColor,f=c.solidColor;d.solidColor=f?[void 0!=f.r&&null!=f.r?f.r:e[0],void 0!=f.g&&null!=f.g?f.g:e[1],void 0!=f.b&&null!=f.b?f.b:e[2]]:b.solidColor,this._engine.display.imageDirty=!0}return void 0!=c.skybox&&(d.skybox=c.skybox,this._engine.branchDirty(this),this._engine.display.imageDirty=!0),d.hash=a(d),this},SceneJS.Flags.prototype.getFlags=function(){var a=this._core;return{picking:a.picking,clipping:a.clipping,enabled:a.enabled,transparent:a.transparent,backfaces:a.backfaces,frontface:a.frontface,reflective:a.reflective,solid:a.solid,solidColor:a.solidColor}},SceneJS.Flags.prototype.setPicking=function(a){return a=!!a,this._core.picking!=a&&(this._core.picking=a,this._engine.display.drawListDirty=!0),this},SceneJS.Flags.prototype.getPicking=function(){return this._core.picking},SceneJS.Flags.prototype.setClipping=function(a){return a=!!a,this._core.clipping!=a&&(this._core.clipping=a,this._engine.display.imageDirty=!0),this},SceneJS.Flags.prototype.getClipping=function(){return this._core.clipping},SceneJS.Flags.prototype.setEnabled=function(a){return a=!!a,this._core.enabled!=a&&(this._core.enabled=a,this._engine.display.drawListDirty=!0),this},SceneJS.Flags.prototype.getEnabled=function(){return this._core.enabled},SceneJS.Flags.prototype.setTransparent=function(a){return a=!!a,this._core.transparent!=a&&(this._core.transparent=a,this._engine.display.stateOrderDirty=!0),this},SceneJS.Flags.prototype.getTransparent=function(){return this._core.transparent},SceneJS.Flags.prototype.setBackfaces=function(a){return a=!!a,this._core.backfaces!=a&&(this._core.backfaces=a,this._engine.display.imageDirty=!0),this},SceneJS.Flags.prototype.getBackfaces=function(){return this._core.backfaces},SceneJS.Flags.prototype.setFrontface=function(a){return this._core.frontface!=a&&(this._core.frontface=a,this._engine.display.imageDirty=!0),this},SceneJS.Flags.prototype.getFrontface=function(){return this._core.frontface},SceneJS.Flags.prototype.setReflective=function(b){return b=!!b,this._core.reflective!=b&&(this._core.reflective=b,this._core.hash=a(this._core),this._engine.branchDirty(this),this._engine.display.imageDirty=!0),this},SceneJS.Flags.prototype.getReflective=function(){return this._core.reflective},SceneJS.Flags.prototype.setSolid=function(b){return b=!!b,this._core.solid!=b&&(this._core.solid=b,this._core.hash=a(this._core),this._engine.branchDirty(this),this._engine.display.imageDirty=!0),this},SceneJS.Flags.prototype.getSolid=function(){return this._core.solid},SceneJS.Flags.prototype.setSolidColor=function(a){var c=b.solidColor;return this._core.solidColor=a?[void 0!=a.r&&null!=a.r?a.r:c[0],void 0!=a.g&&null!=a.g?a.g:c[1],void 0!=a.b&&null!=a.b?a.b:c[2]]:b.solidColor,this._engine.display.imageDirty=!0,this},SceneJS.Flags.prototype.getSolidColor=function(){return{r:this._core.solidColor[0],g:this._core.solidColor[1],b:this._core.solidColor[2]}},SceneJS.Flags.prototype.setSkybox=function(b){return b=!!b,this._core.skybox!=b&&(this._core.skybox=b,this._core.hash=a(this._core),this._engine.branchDirty(this),this._engine.display.imageDirty=!0),this},SceneJS.Flags.prototype.getSkybox=function(){return this._core.skybox},SceneJS.Flags.prototype._compile=function(a){this._engine.display.flags=c[d++]=this._core,this._compileNodes(a),this._engine.display.flags=--d>0?c[d-1]:b,c[d]=null}}(),new function(){var a={type:"renderTarget",stateId:SceneJS._baseStateId++,targets:null},b={},c=[],d=0;SceneJS_events.addListener(SceneJS_events.SCENE_COMPILING,function(b){b.engine.display.renderTarget=a,d=0}),SceneJS_events.addListener(SceneJS_events.WEBGL_CONTEXT_RESTORED,function(){for(var a in b)b.hasOwnProperty(a)&&b[a]._core.renderBuf.webglRestored()}),SceneJS.ColorTarget=SceneJS_NodeFactory.createNodeType("colorTarget"),SceneJS.ColorTarget.prototype._init=function(a){b[this._core.coreId]=this,this._core.bufType="color",this._core.renderBuf=new SceneJS._webgl.RenderBuffer({canvas:this._engine.canvas})},SceneJS.ColorTarget.prototype._compile=function(b){this.__core||(this.__core=this._engine._coreFactory.getCore("renderTarget"));var e=this._engine.display.renderTarget;this._core.empty||(this.__core.targets=e&&e.targets?e.targets.concat([this._core]):[this._core]),c[d++]=this.__core,this._engine.display.renderTarget=this.__core,this._compileNodes(b),this._engine.display.renderTarget=--d>0?c[d-1]:a,c[d]=null},SceneJS.ColorTarget.prototype._destroy=function(){this._core&&(this._core.renderBuf&&this._core.renderBuf.destroy(),delete b[this._core.coreId])}},new function(){var a={type:"renderTarget",stateId:SceneJS._baseStateId++,targets:null},b={},c=[],d=0;SceneJS_events.addListener(SceneJS_events.SCENE_COMPILING,function(b){b.engine.display.renderTarget=a,d=0}),SceneJS_events.addListener(SceneJS_events.WEBGL_CONTEXT_RESTORED,function(){for(var a in b)b.hasOwnProperty(a)&&b[a]._buildNodeCore()}),SceneJS.DepthTarget=SceneJS_NodeFactory.createNodeType("depthTarget"),SceneJS.DepthTarget.prototype._init=function(a){b[this._core.coreId]=this,this._core.bufType="depth",this._core.renderBuf=new SceneJS._webgl.RenderBuffer({canvas:this._engine.canvas})},SceneJS.DepthTarget.prototype._compile=function(b){this.__core||(this.__core=this._engine._coreFactory.getCore("renderTarget"));var e=this._engine.display.renderTarget;this._core.empty||(this.__core.targets=e&&e.targets?e.targets.concat([this._core]):[this._core]),c[d++]=this.__core,this._engine.display.renderTarget=this.__core,this._compileNodes(b),this._engine.display.renderTarget=--d>0?c[d-1]:a,c[d]=null},SceneJS.DepthTarget.prototype._destroy=function(){this._core&&(this._core.renderBuf&&this._core.renderBuf.destroy(),delete b[this._core.coreId])}},new function(){function a(a,b){var c=a.STATIC_DRAW,d=b.arrays,e=SceneJS.getConfigs("enableInterleaving")!==!1,f=0,g=0,h=[],i=[],j=function(a,b){return 0==f?f=a.length/b:a.length/b!=f&&(e=!1),h.push(a),i.push(b),g+=b,4*(g-b)};if(d.positions&&(e&&(b.interleavedPositionOffset=j(d.positions,3)),b.vertexBuf=new SceneJS._webgl.ArrayBuffer(a,a.ARRAY_BUFFER,d.positions,d.positions.length,3,c)),d.normals&&(e&&(b.interleavedNormalOffset=j(d.normals,3)),b.normalBuf=new SceneJS._webgl.ArrayBuffer(a,a.ARRAY_BUFFER,d.normals,d.normals.length,3,c)),d.uvs){var k,l,m,n,o=d.uvs;if(e)for(b.interleavedUVOffsets=[],k=b.interleavedUVOffsets,l=0,m=o.length;l0&&b.uvBufs.push(new SceneJS._webgl.ArrayBuffer(a,a.ARRAY_BUFFER,n,n.length,2,c))}if(d.colors&&(e&&(b.interleavedColorOffset=j(d.colors,4)),b.colorBuf=new SceneJS._webgl.ArrayBuffer(a,a.ARRAY_BUFFER,d.colors,d.colors.length,4,c)),d.indices&&(b.indexBuf=new SceneJS._webgl.ArrayBuffer(a,a.ELEMENT_ARRAY_BUFFER,d.indices,d.indices.length,1,c)),g>0&&e){for(var p=[],q=h.length,l=0;ld&&(e-=e+c-d);for(var f=c,g=0;gthis._boundary.xmax&&(this._boundary.xmax=c),d>this._boundary.ymax&&(this._boundary.ymax=d),e>this._boundary.zmax&&(this._boundary.zmax=e);return this._boundary},SceneJS.Geometry.prototype._compile=function(a){if(this._core._loading)return void this._compileNodes(a);var d=this._core;if(d.vertexBuf||(d=this._inheritVBOs(d)),d.indexBuf||"points"===d.primitiveName){var e=[d.normalBuf?"t":"f",d.arrays&&d.arrays.tangents?"t":"f",d.colorBuf?"t":"f",d.primitive];e.push(";uvs");var f=d.uvBufs;if(f)for(var g=0,h=f.length;g=0;e--)if(b[e].vertexBuf)return d.vertexBuf=b[e].vertexBuf,d.boundary=b[e].boundary,d.normalBuf=b[e].normalBuf,d.uvBufs=b[e].uvBufs,d.colorBuf=b[e].colorBuf,d.interleavedBuf=b[e].interleavedBuf,d.interleavedStride=b[e].interleavedStride,d.interleavedPositionOffset=b[e].interleavedPositionOffset,d.interleavedNormalOffset=b[e].interleavedNormalOffset,d.interleavedUVOffsets=b[e].interleavedUVOffsets,d.interleavedColorOffset=b[e].interleavedColorOffset,d;return d},SceneJS.Geometry.prototype._destroy=function(){this._engine.display.removeObject(this.id),1==this._core.useCount&&(this._destroyNodeCore(),this._source&&this._source.destroy&&this._source.destroy(),this._engine.stats.memory.meshes--)},SceneJS.Geometry.prototype._destroyNodeCore=function(){document.getElementById(this._engine.canvas.canvasId)&&d(this._core);var a=this._core.arrays;a.positions&&(this._engine.stats.memory.positions-=a.positions.length/3),a.normals&&(this._engine.stats.memory.normals-=a.normals.length/3),a.colors&&(this._engine.stats.memory.colors-=a.colors.length/3),a.uvs&&a.uvs.length>0&&(this._engine.stats.memory.uvs-=a.uvs.length*(a.uvs[0].length/2)),a.indices&&(this._engine.stats.memory.indices-=a.indices.length)}},function(){var a={type:"stage",stateId:SceneJS._baseStateId++,priority:0,pickable:!0,enabled:!0},b=[],c=0;SceneJS_events.addListener(SceneJS_events.SCENE_COMPILING,function(b){b.engine.display.stage=a,c=0}),SceneJS.Stage=SceneJS_NodeFactory.createNodeType("stage"),SceneJS.Stage.prototype._init=function(a){1==this._core.useCount&&(this._core.priority=a.priority||0,this._core.enabled=a.enabled!==!1,this._core.pickable=!!a.pickable)},SceneJS.Stage.prototype.setPriority=function(a){a=a||0,this._core.priority!=a&&(this._core.priority=a,this._engine.display.stateOrderDirty=!0)},SceneJS.Stage.prototype.getPriority=function(){return this._core.priority},SceneJS.Stage.prototype.setEnabled=function(a){a=!!a,this._core.enabled!=a&&(this._core.enabled=a,this._engine.display.drawListDirty=!0)},SceneJS.Stage.prototype.getEnabled=function(){return this._core.enabled},SceneJS.Stage.prototype.getEnabled=function(){return this._core.enabled},SceneJS.Stage.prototype._compile=function(d){this._engine.display.stage=b[c++]=this._core,this._compileNodes(d),this._engine.display.stage=--c>0?b[c-1]:a,b[c]=null}}(),function(){var a={type:"layer",stateId:SceneJS._baseStateId++,priority:0,enabled:!0},b=[],c=0;SceneJS_events.addListener(SceneJS_events.SCENE_COMPILING,function(b){b.engine.display.layer=a,c=0}),SceneJS.Layer=SceneJS_NodeFactory.createNodeType("layer"),SceneJS.Layer.prototype._init=function(a){1==this._core.useCount&&(this._core.priority=a.priority||0,this._core.enabled=a.enabled!==!1)},SceneJS.Layer.prototype.setPriority=function(a){a=a||0,this._core.priority!=a&&(this._core.priority=a,this._engine.display.stateOrderDirty=!0)},SceneJS.Layer.prototype.getPriority=function(){return this._core.priority},SceneJS.Layer.prototype.setEnabled=function(a){a=!!a,this._core.enabled!=a&&(this._core.enabled=a,this._engine.display.drawListDirty=!0)},SceneJS.Layer.prototype.getEnabled=function(){return this._core.enabled},SceneJS.Layer.prototype.getEnabled=function(){return this._core.enabled},SceneJS.Layer.prototype.setClearDepth=function(a){a=a||0,this._core.clearDepth!=a&&(this._core.clearDepth=a,this._engine.display.drawListDirty=!0)},SceneJS.Layer.prototype.getClearDepth=function(){return this._core.clearDepth},SceneJS.Layer.prototype._compile=function(d){this._engine.display.layer=b[c++]=this._core,this._compileNodes(d),this._engine.display.layer=--c>0?b[c-1]:a,b[c]=null}}(),SceneJS.Library=SceneJS_NodeFactory.createNodeType("library"),SceneJS.Library.prototype._compile=function(a){},function(){function a(a){if(a.lights&&a.lights.length>0){for(var b,c=a.lights,d=[],e=0,f=c.length;e=this._core.lights.length)throw SceneJS_error.fatalError(SceneJS.errors.ILLEGAL_NODE_CONFIG,"Invalid argument to set 'lights': index out of range ("+this._core.lights.length+" lights defined)");this._setLight(b,a[c]||{})}this._engine.branchDirty(this)},SceneJS.Lights.prototype._setLight=function(a,b){var c=this._core.lights[a],d=!1,e=!1;if(b.mode&&b.mode!=c.mode){var f=b.mode;if("dir"!=f&&"point"!=f&&"ambient"!=f)throw SceneJS_error.fatalError(SceneJS.errors.ILLEGAL_NODE_CONFIG,"Light mode not supported - should be 'dir' or 'point' or 'ambient'");c.mode=f,c.diffuse="ambient"==f||(void 0==b.diffuse||b.diffuse),c.specular="ambient"!=f&&(void 0==b.specular||b.specular),e=!0}if(b.color){var g=b.color;c.color=[void 0!=g.r?g.r:1,void 0!=g.g?g.g:1,void 0!=g.b?g.b:1],d=!0}var h=b.pos;h&&(c.pos=[h.x||0,h.y||0,h.z||0],d=!0);var i=b.dir;if(i&&(c.dir=[i.x||0,i.y||0,i.z||0],d=!0),void 0!=b.innerCone&&b.innerCone!=c.innerCone&&(c.innerCone=b.innerCone,d=!0),void 0!=b.outerCone&&b.outerCone!=c.outerCone&&(c.outerCone=b.outerCone,d=!0),void 0!=b.constantAttenuation&&(c.attenuation[0]=b.constantAttenuation,d=!0),void 0!=b.linearAttenuation&&(c.attenuation[1]=b.linearAttenuation,d=!0),void 0!=b.quadraticAttenuation&&(c.attenuation[2]=b.quadraticAttenuation,d=!0),b.space&&b.space!=c.space){var j=b.space;if("view"!=j&&"world"!=j)throw SceneJS_error.fatalError(SceneJS.errors.ILLEGAL_NODE_CONFIG,"lights node invalid value for property 'space': '"+j+"' - should be 'view' or 'world'");c.space=j,this._core.hash=null,e=!0}void 0!=b.specular&&b.specular!=c.specular&&(c.specular=b.specular,e=!0),void 0!=b.diffuse&&b.diffuse!=c.diffuse&&(c.diffuse=b.diffuse,e=!0),e?this._engine.branchDirty(this):d&&(this._engine.display.imageDirty=!0),this._core.hash=null},SceneJS.Lights.prototype._compile=function(e){this._core.hash||a(this._core),this._engine.display.lights=c[d++]=this._core,this._compileNodes(e),this._engine.display.lights=--d>0?c[d-1]:b,c[d]=null}}(),function(){var a=SceneJS_math_lookAtMat4c(0,0,10,0,0,0,0,1,0),b=new Float32Array(a),c=SceneJS_math_transposeMat4(SceneJS_math_inverseMat4(b,SceneJS_math_mat4())),d=new Float32Array(c),e={type:"lookAt",stateId:SceneJS._baseStateId++,matrix:a,mat:b,normalMatrix:c,normalMat:d,lookAt:SceneJS_math_LOOKAT_ARRAYS},f=[],g=0;SceneJS_events.addListener(SceneJS_events.SCENE_COMPILING,function(a){a.engine.display.viewTransform=e,g=0}),SceneJS.Lookat=SceneJS_NodeFactory.createNodeType("lookAt"),SceneJS.Lookat.prototype._init=function(a){if(this._mat=null,this._xf={type:"lookat"},1==this._core.useCount){this._core.eyeX=0,this._core.eyeY=0,this._core.eyeZ=10,this._core.lookX=0,this._core.lookY=0,this._core.lookZ=0,this._core.upX=0,this._core.upY=1,this._core.upZ=0,a.eye||a.look||a.up?(this.setEye(a.eye),this.setLook(a.look),this.setUp(a.up)):(this.setEye({x:0,y:0,z:10}),this.setLook({x:0,y:0,z:0}),this.setUp({x:0,y:1,z:0}));var b=this._core,c=this;this._core.rebuild=function(){b.matrix=SceneJS_math_lookAtMat4c(b.eyeX,b.eyeY,b.eyeZ,b.lookX,b.lookY,b.lookZ,b.upX,b.upY,b.upZ),b.lookAt={eye:[b.eyeX,b.eyeY,b.eyeZ],look:[b.lookX,b.lookY,b.lookZ],up:[b.upX,b.upY,b.upZ]},b.mat?(b.mat.set(b.matrix),b.normalMat.set(SceneJS_math_transposeMat4(SceneJS_math_inverseMat4(b.matrix,SceneJS_math_mat4())))):(b.mat=new Float32Array(b.matrix),b.normalMat=new Float32Array(SceneJS_math_transposeMat4(SceneJS_math_inverseMat4(b.matrix,SceneJS_math_mat4())))),c.publish("matrix",b.matrix),b.dirty=!1},this._core.dirty=!0,this._tick=this.getScene().on("tick",function(){c._core.dirty&&c._core.rebuild()})}},SceneJS.Lookat.getDefaultMatrix=function(){return b},SceneJS.Lookat.prototype.setEye=function(a){return a=a||{},void 0!=a.x&&null!=a.x&&(this._core.eyeX=a.x),void 0!=a.y&&null!=a.y&&(this._core.eyeY=a.y),void 0!=a.z&&null!=a.z&&(this._core.eyeZ=a.z),this._core.dirty=!0,this._engine.display.imageDirty=!0,this},SceneJS.Lookat.prototype.incEye=function(a){return a=a||{},this._core.eyeX+=void 0!=a.x&&null!=a.x?a.x:0,this._core.eyeY+=void 0!=a.y&&null!=a.y?a.y:0,this._core.eyeZ+=void 0!=a.z&&null!=a.z?a.z:0,this._core.dirty=!0,this._engine.display.imageDirty=!0,this},SceneJS.Lookat.prototype.setEyeX=function(a){return this._core.eyeX=a||0,this._core.dirty=!0,this._engine.display.imageDirty=!0,this},SceneJS.Lookat.prototype.setEyeY=function(a){return this._core.eyeY=a||0,this._core.dirty=!0,this._engine.display.imageDirty=!0,this},SceneJS.Lookat.prototype.setEyeZ=function(a){return this._core.eyeZ=a||0,this._core.dirty=!0,this._engine.display.imageDirty=!0,this},SceneJS.Lookat.prototype.incEyeX=function(a){return this._core.eyeX+=a,this._core.dirty=!0,this._engine.display.imageDirty=!0,this},SceneJS.Lookat.prototype.incEyeY=function(a){return this._core.eyeY+=a,this._core.dirty=!0,this._engine.display.imageDirty=!0,this},SceneJS.Lookat.prototype.incEyeZ=function(a){return this._core.eyeZ+=a,this._core.dirty=!0,this._engine.display.imageDirty=!0,this},SceneJS.Lookat.prototype.getEye=function(){return{x:this._core.eyeX,y:this._core.eyeY,z:this._core.eyeZ}},SceneJS.Lookat.prototype.setLook=function(a){return a=a||{},void 0!=a.x&&null!=a.x&&(this._core.lookX=a.x),void 0!=a.y&&null!=a.y&&(this._core.lookY=a.y),void 0!=a.z&&null!=a.z&&(this._core.lookZ=a.z),this._core.dirty=!0,this._engine.display.imageDirty=!0,this},SceneJS.Lookat.prototype.incLook=function(a){return a=a||{},this._core.lookX+=void 0!=a.x&&null!=a.x?a.x:0,this._core.lookY+=void 0!=a.y&&null!=a.y?a.y:0,this._core.lookZ+=void 0!=a.z&&null!=a.z?a.z:0,this._core.dirty=!0,this._engine.display.imageDirty=!0,this},SceneJS.Lookat.prototype.setLookX=function(a){return this._core.lookX=a||0,this._core.dirty=!0,this._engine.display.imageDirty=!0,this},SceneJS.Lookat.prototype.setLookY=function(a){return this._core.lookY=a||0,this._core.dirty=!0,this._engine.display.imageDirty=!0,this},SceneJS.Lookat.prototype.setLookZ=function(a){return this._core.lookZ=a||0,this._core.dirty=!0,this._engine.display.imageDirty=!0,this},SceneJS.Lookat.prototype.incLookX=function(a){return this._core.lookX+=a,this._core.dirty=!0,this._engine.display.imageDirty=!0,this},SceneJS.Lookat.prototype.incLookY=function(a){return this._core.lookY+=a,this._core.dirty=!0,this._engine.display.imageDirty=!0,this},SceneJS.Lookat.prototype.incLookZ=function(a){return this._core.lookZ+=a,this._core.dirty=!0,this._engine.display.imageDirty=!0,this},SceneJS.Lookat.prototype.getLook=function(){return{x:this._core.lookX,y:this._core.lookY,z:this._core.lookZ}},SceneJS.Lookat.prototype.setUp=function(a){return a=a||{},void 0!=a.x&&null!=a.x&&(this._core.upX=a.x),void 0!=a.y&&null!=a.y&&(this._core.upY=a.y),void 0!=a.z&&null!=a.z&&(this._core.upZ=a.z),this._core.dirty=!0,this._engine.display.imageDirty=!0,this},SceneJS.Lookat.prototype.incUp=function(a){return a=a||{},this._core.upX+=void 0!=a.x&&null!=a.x?a.x:0,this._core.upY+=void 0!=a.y&&null!=a.y?a.y:0,this._core.upZ+=void 0!=a.z&&null!=a.z?a.z:0,this._core.dirty=!0,this._engine.display.imageDirty=!0,this},SceneJS.Lookat.prototype.setUpX=function(a){return this._core.upX=a||0,this._core.dirty=!0,this._engine.display.imageDirty=!0,this},SceneJS.Lookat.prototype.setUpY=function(a){return this._core.upY=a||0,this._core.dirty=!0,this._engine.display.imageDirty=!0,this},SceneJS.Lookat.prototype.setUpZ=function(a){return this._core.upZ=a||0,this._core.dirty=!0,this._engine.display.imageDirty=!0,this},SceneJS.Lookat.prototype.incUpX=function(a){return this._core.upX+=a,this._core.dirty=!0,this._engine.display.imageDirty=!0,this},SceneJS.Lookat.prototype.incUpY=function(a){return this._core.upY+=a,this._core.dirty=!0,this._engine.display.imageDirty=!0,this},SceneJS.Lookat.prototype.incUpZ=function(a){return this._core.upZ+=a,this._core.dirty=!0,this._engine.display.imageDirty=!0,this},SceneJS.Lookat.prototype.getUp=function(){return{x:this._core.upX,y:this._core.upY,z:this._core.upZ}},SceneJS.Lookat.prototype.setMatrix=function(a){var b=this._core;b.matrix=a,b.mat=a,b.mat?(b.mat.set(b.matrix),b.normalMat.set(SceneJS_math_transposeMat4(SceneJS_math_inverseMat4(b.matrix,SceneJS_math_mat4())))):(b.mat=new Float32Array(b.matrix),b.normalMat=new Float32Array(SceneJS_math_transposeMat4(SceneJS_math_inverseMat4(b.matrix,SceneJS_math_mat4())))),this.publish("matrix",b.matrix),this._engine.display.imageDirty=!0},SceneJS.Lookat.prototype.getMatrix=function(){return this._core.dirty&&this._core.rebuild(),SceneJS._sliceArray(this._core.matrix,0)},SceneJS.Lookat.prototype.setMatrix=function(a){this._core.matrix=a,this._core.mat=a,this.publish("matrix",this._core.matrix),this._engine.display.imageDirty=!0},SceneJS.Lookat.prototype.getAttributes=function(){return{look:{x:this._core.lookX,y:this._core.lookY,z:this._core.lookZ},eye:{x:this._core.eyeX,y:this._core.eyeY,z:this._core.eyeZ},up:{x:this._core.upX,y:this._core.upY,z:this._core.upZ}}},SceneJS.Lookat.prototype._compile=function(a){this._engine.display.viewTransform=f[g++]=this._core,this._compileNodes(a),this._engine.display.viewTransform=--g>0?f[g-1]:e,f[g]=null},SceneJS.Lookat.prototype._destroy=function(){this.getScene().off(this._tick)}}(),new function(){var a={type:"material",stateId:SceneJS._baseStateId++,baseColor:[1,1,1],specularColor:[1,1,1],emitColor:[1,1,1],specular:1,shine:70,alpha:1,emit:0},b=[],c=0;SceneJS_events.addListener(SceneJS_events.SCENE_COMPILING,function(b){b.engine.display.material=a,c=0}),SceneJS.Material=SceneJS_NodeFactory.createNodeType("material"),SceneJS.Material.prototype._init=function(a){1==this._core.useCount&&(this.setBaseColor(a.color||a.baseColor),this.setSpecularColor(a.specularColor),this.setEmitColor(a.emitColor),this.setSpecular(a.specular),this.setShine(a.shine),this.setEmit(a.emit),this.setAlpha(a.alpha))},SceneJS.Material.prototype.setBaseColor=function(b){var c=a.baseColor;return this._core.baseColor=b?[void 0!=b.r&&null!=b.r?b.r:c[0],void 0!=b.g&&null!=b.g?b.g:c[1],void 0!=b.b&&null!=b.b?b.b:c[2]]:a.baseColor,this._engine.display.imageDirty=!0,this},SceneJS.Material.prototype.setColor=SceneJS.Material.prototype.setBaseColor,SceneJS.Material.prototype.getBaseColor=function(){return{r:this._core.baseColor[0],g:this._core.baseColor[1],b:this._core.baseColor[2]}},SceneJS.Material.prototype.getColor=SceneJS.Material.prototype.getBaseColor,SceneJS.Material.prototype.setSpecularColor=function(b){var c=a.specularColor;return this._core.specularColor=b?[void 0!=b.r&&null!=b.r?b.r:c[0],void 0!=b.g&&null!=b.g?b.g:c[1],void 0!=b.b&&null!=b.b?b.b:c[2]]:a.specularColor,this._engine.display.imageDirty=!0,this},SceneJS.Material.prototype.getSpecularColor=function(){return{r:this._core.specularColor[0],g:this._core.specularColor[1],b:this._core.specularColor[2]}},SceneJS.Material.prototype.setEmitColor=function(b){var c=a.emitColor;return this._core.emitColor=b?[void 0!=b.r&&null!=b.r?b.r:c[0],void 0!=b.g&&null!=b.g?b.g:c[1],void 0!=b.b&&null!=b.b?b.b:c[2]]:a.emitColor,this._engine.display.imageDirty=!0,this},SceneJS.Material.prototype.getEmitColor=function(){return{r:this._core.emitColor[0],g:this._core.emitColor[1],b:this._core.emitColor[2]}},SceneJS.Material.prototype.setSpecular=function(b){return this._core.specular=void 0!=b&&null!=b?b:a.specular,this._engine.display.imageDirty=!0,this},SceneJS.Material.prototype.getSpecular=function(){return this._core.specular},SceneJS.Material.prototype.setShine=function(b){return this._core.shine=void 0!=b&&null!=b?b:a.shine,this._engine.display.imageDirty=!0,this},SceneJS.Material.prototype.getShine=function(){return this._core.shine},SceneJS.Material.prototype.setEmit=function(b){return this._core.emit=void 0!=b&&null!=b?b:a.emit,this._engine.display.imageDirty=!0,this},SceneJS.Material.prototype.getEmit=function(){return this._core.emit},SceneJS.Material.prototype.setAlpha=function(b){return this._core.alpha=void 0!=b&&null!=b?b:a.alpha,this._engine.display.imageDirty=!0,this},SceneJS.Material.prototype.getAlpha=function(){return this._core.alpha},SceneJS.Material.prototype._compile=function(d){this._engine.display.material=b[c++]=this._core,this._compileNodes(d),this._engine.display.material=--c>0?b[c-1]:a,b[c]=null}},new function(){function a(a,b){var c=b.targets||[];if(c.length<2)throw SceneJS_error.fatalError(SceneJS.errors.ILLEGAL_NODE_CONFIG,"morphGeometry node should have at least two targets");var d=b.keys||[];if(d.length!=c.length)throw SceneJS_error.fatalError(SceneJS.errors.ILLEGAL_NODE_CONFIG,"morphGeometry node mismatch in number of keys and targets");var e=a._core,f=a._engine.canvas.gl,g=f.STATIC_DRAW;e.keys=d,e.targets=[],e.key1=0,e.key2=1;for(var h,i,j,k,l,m=0,n=c.length;mc[c.length-1])d=c.length-2,e=d+1;else{for(;c[d]>a;)d--,e--;for(;c[e]0?c[d-1]:b,c[d]=null},SceneJS.MorphGeometry.prototype._makeHash=function(){var a=this._core;if(a.targets.length>0){var b=a.targets[0],c="t",d="f";a.hash=[b.vertexBuf?c:d,b.normalBuf?c:d,b.uvBuf?c:d,b.uvBuf2?c:d].join("")}else a.hash=""},SceneJS.MorphGeometry.prototype._destroy=function(){if(1==this._core.useCount&&document.getElementById(this._engine.canvas.canvasId))for(var a,b=this._core,c=0,d=b.targets.length;c0?b[c-1]:a,b[c]=null}}(),new function(){function a(a){var c;if(f>0){c={};for(var d in a)a.hasOwnProperty(d)&&void 0!=a[d]&&(c[d]=g(d))}return b(a.props),{props:a,setProps:function(b){h(b,a)},restoreProps:function(a){c&&i(a,c)}}}function b(a){var b;for(var c in a)a.hasOwnProperty(c)&&(b=a[c],void 0!=b&&null!=b&&(k[c]?a[c]=k[c](null,b):l[c]&&(a[c]=l[c](null,b))))}var c,d={type:"renderer",stateId:SceneJS._baseStateId++,props:null},e=[],f=0;SceneJS_events.addListener(SceneJS_events.SCENE_COMPILING,function(a){c=a.engine.canvas,f=0,a.engine.display.renderer=e[f++]=d});var g=function(a){for(var b,c,d=f-1;d>=0;d--)if(b=e[d].props,b&&(c=b[a],void 0!=c&&null!=c))return b[a];return null},h=function(a,b){for(var c in b)if(b.hasOwnProperty(c)){var d=k[c];d&&d(a,b[c])}b.viewport&&l.viewport(a,b.viewport),b.scissor&&l.clear(a,b.scissor),b.clear&&l.clear(a,b.clear)},i=function(a,b){var c;for(var d in b)if(b.hasOwnProperty(d)&&(c=b[d],void 0!=c&&null!=c)){var e=k[d];e&&e(a,c)}b.viewport&&l.viewport(a,b.viewport),b.scissor&&l.clear(a,b.scissor)},j=function(a,b){if(!b)throw SceneJS_error.fatalError(SceneJS.errors.ILLEGAL_NODE_CONFIG,'Null SceneJS.State node config: "'+b+'"');var c=SceneJS._webgl.enumMap[b];if(!c)throw SceneJS_error.fatalError(SceneJS.errors.ILLEGAL_NODE_CONFIG,'Unrecognised SceneJS.State node config value: "'+b+'"');var d=a[c];if(!d)throw SceneJS_error.fatalError(SceneJS.errors.ILLEGAL_NODE_CONFIG,"This browser's WebGL does not support renderer node config value: \""+b+'"');return d},k={enableBlend:function(a,b){return a?void(b?a.enable(a.BLEND):a.disable(a.BLEND)):(null!=b&&void 0!=b||(b=!1),b)},blendColor:function(a,b){return a?void a.blendColor(b.r,b.g,b.b,b.a):(b=b||{},{r:b.r||0,g:b.g||0,b:b.b||0,a:void 0==b.a||null==b.a?1:b.a})},blendEquation:function(a,b){return a?void a.blendEquation(a,j(a,b)):b||"funcAdd"},blendEquationSeparate:function(a,b){return a?void a.blendEquation(j(a,b.rgb),j(a,b.alpha)):(b=b||{},{rgb:b.rgb||"funcAdd",alpha:b.alpha||"funcAdd"})},blendFunc:function(a,b){return a?void a.blendFunc(j(a,b.sfactor||"srcAlpha"),j(a,b.dfactor||"oneMinusSrcAlpha")):(b=b||{},{sfactor:b.sfactor||"srcAlpha",dfactor:b.dfactor||"oneMinusSrcAlpha"})},blendFuncSeparate:function(a,b){return a?void a.blendFuncSeparate(j(a,b.srcRGB||"zero"),j(a,b.dstRGB||"zero"),j(a,b.srcAlpha||"zero"),j(a,b.dstAlpha||"zero")):(b=b||{},{srcRGB:b.srcRGB||"zero",dstRGB:b.dstRGB||"zero",srcAlpha:b.srcAlpha||"zero",dstAlpha:b.dstAlpha||"zero"})},clearColor:function(a,b){return a?void a.clearColor(b.r,b.g,b.b,b.a):(b=b||{},{r:b.r||0,g:b.g||0,b:b.b||0,a:void 0==b.a||null==b.a?1:b.a})},clearDepth:function(a,b){return a?void a.clearDepth(b):null==b||void 0==b?1:b},clearStencil:function(a,b){return a?void a.clearStencil(b):b||0},colorMask:function(a,b){return a?void a.colorMask(b.r,b.g,b.b,b.a):(b=b||{},{r:b.r||0,g:b.g||0,b:b.b||0,a:void 0==b.a||null==b.a?1:b.a})},enableCullFace:function(a,b){return a?void(b?a.enable(a.CULL_FACE):a.disable(a.CULL_FACE)):b},cullFace:function(a,b){return a?void a.cullFace(j(a,b)):b||"back"},enableDepthTest:function(a,b){return a?void(b?a.enable(a.DEPTH_TEST):a.disable(a.DEPTH_TEST)):(null!=b&&void 0!=b||(b=!0),b)},depthFunc:function(a,b){return a?void a.depthFunc(j(a,b)):b||"less"},enableDepthMask:function(a,b){return a?void a.depthMask(b):(null!=b&&void 0!=b||(b=!0),b)},depthRange:function(a,b){return a?void a.depthRange(b.zNear,b.zFar):(b=b||{},{zNear:void 0==b.zNear||null==b.zNear?0:b.zNear,zFar:void 0==b.zFar||null==b.zFar?1:b.zFar})},frontFace:function(a,b){return a?void a.frontFace(j(a,b)):b||"ccw"},lineWidth:function(a,b){return a?void a.lineWidth(b):b||1},enableScissorTest:function(a,b){return a?void(b?a.enable(a.SCISSOR_TEST):(b=!1,a.disable(a.SCISSOR_TEST))):b}},l={viewport:function(a,b){return a?void a.viewport(b.x,b.y,b.width,b.height):(b=b||{},{x:b.x||1,y:b.y||1,width:b.width||c.canvas.width,height:b.height||c.canvas.height})},scissor:function(a,b){return a?void a.scissor(b.x,b.y,b.width,b.height):(b=b||{},{x:b.x||0,y:b.y||0,width:b.width||1,height:b.height||1})},clear:function(a,b){if(!a)return b=b||{};var c;b.color&&(c=a.COLOR_BUFFER_BIT),b.depth&&(c|=a.DEPTH_BUFFER_BIT), +b.stencil&&(c|=a.STENCIL_BUFFER_BIT)}};SceneJS.Renderer=SceneJS_NodeFactory.createNodeType("renderer"),SceneJS.Renderer.prototype._init=function(a){if(1==this._core.useCount){for(var b in a)a.hasOwnProperty(b)&&(this._core[b]=a[b]);this._core.dirty=!0}},SceneJS.Renderer.prototype.setViewport=function(a){this._core.viewport=a?{x:a.x||1,y:a.y||1,width:a.width||1e3,height:a.height||1e3}:void 0,this._core.dirty=!0,this._engine.display.imageDirty=!0},SceneJS.Renderer.prototype.getViewport=function(){return this._core.viewport?{x:this._core.viewport.x,y:this._core.viewport.y,width:this._core.viewport.width,height:this._core.viewport.height}:void 0},SceneJS.Renderer.prototype.setScissor=function(a){this._core.scissor=a?{x:a.x||1,y:a.y||1,width:a.width||1e3,height:a.height||1e3}:void 0,this._core.dirty=!0,this._engine.display.imageDirty=!0},SceneJS.Renderer.prototype.getScissor=function(){return this._core.scissor?{x:this._core.scissor.x,y:this._core.scissor.y,width:this._core.scissor.width,height:this._core.scissor.height}:void 0},SceneJS.Renderer.prototype.setClear=function(a){this._core.clear=a?{r:a.r||0,g:a.g||0,b:a.b||0}:void 0,this._core.dirty=!0,this._engine.display.imageDirty=!0},SceneJS.Renderer.prototype.getClear=function(){return this._core.clear?{r:this._core.clear.r,g:this._core.clear.g,b:this._core.clear.b}:null},SceneJS.Renderer.prototype.setEnableBlend=function(a){this._core.enableBlend=a,this._core.dirty=!0,this._engine.display.imageDirty=!0},SceneJS.Renderer.prototype.getEnableBlend=function(){return this._core.enableBlend},SceneJS.Renderer.prototype.setBlendColor=function(a){this._core.blendColor=a?{r:a.r||0,g:a.g||0,b:a.b||0,a:void 0==a.a||null==a.a?1:a.a}:void 0,this._core.dirty=!0,this._engine.display.imageDirty=!0},SceneJS.Renderer.prototype.getBlendColor=function(){return this._core.blendColor?{r:this._core.blendColor.r,g:this._core.blendColor.g,b:this._core.blendColor.b,a:this._core.blendColor.a}:void 0},SceneJS.Renderer.prototype.setBlendEquation=function(a){this._core.blendEquation=a,this._core.dirty=!0,this._engine.display.imageDirty=!0},SceneJS.Renderer.prototype.getBlendEquation=function(){return this._core.blendEquation},SceneJS.Renderer.prototype.setBlendEquationSeparate=function(a){this._core.blendEquationSeparate=a?{rgb:a.rgb||"funcAdd",alpha:a.alpha||"funcAdd"}:void 0,this._core.dirty=!0,this._engine.display.imageDirty=!0},SceneJS.Renderer.prototype.getBlendEquationSeparate=function(){return this._core.blendEquationSeparate?{rgb:this._core.rgb,alpha:this._core.alpha}:void 0},SceneJS.Renderer.prototype.setBlendFunc=function(a){this._core.blendFunc=a?{sfactor:a.sfactor||"srcAlpha",dfactor:a.dfactor||"one"}:void 0,this._core.dirty=!0,this._engine.display.imageDirty=!0},SceneJS.Renderer.prototype.getBlendFunc=function(){return this._core.blendFunc?{sfactor:this._core.sfactor,dfactor:this._core.dfactor}:void 0},SceneJS.Renderer.prototype.setBlendFuncSeparate=function(a){this._core.blendFuncSeparate=a?{srcRGB:a.srcRGB||"zero",dstRGB:a.dstRGB||"zero",srcAlpha:a.srcAlpha||"zero",dstAlpha:a.dstAlpha||"zero"}:void 0,this._core.dirty=!0},SceneJS.Renderer.prototype.getBlendFuncSeparate=function(){return this._core.blendFuncSeparate?{srcRGB:this._core.blendFuncSeparate.srcRGB,dstRGB:this._core.blendFuncSeparate.dstRGB,srcAlpha:this._core.blendFuncSeparate.srcAlpha,dstAlpha:this._core.blendFuncSeparate.dstAlpha}:void 0},SceneJS.Renderer.prototype.setEnableCullFace=function(a){this._core.enableCullFace=a,this._core.dirty=!0},SceneJS.Renderer.prototype.getEnableCullFace=function(){return this._core.enableCullFace},SceneJS.Renderer.prototype.setCullFace=function(a){this._core.cullFace=a,this._core.dirty=!0},SceneJS.Renderer.prototype.getCullFace=function(){return this._core.cullFace},SceneJS.Renderer.prototype.setEnableDepthTest=function(a){this._core.enableDepthTest=a,this._core.dirty=!0},SceneJS.Renderer.prototype.getEnableDepthTest=function(){return this._core.enableDepthTest},SceneJS.Renderer.prototype.setDepthFunc=function(a){this._core.depthFunc=a,this._core.dirty=!0},SceneJS.Renderer.prototype.getDepthFunc=function(){return this._core.depthFunc},SceneJS.Renderer.prototype.setEnableDepthMask=function(a){this._core.enableDepthMask=a,this._core.dirty=!0},SceneJS.Renderer.prototype.getEnableDepthMask=function(){return this._core.enableDepthMask},SceneJS.Renderer.prototype.setClearDepth=function(a){this._core.clearDepth=a,this._core.dirty=!0},SceneJS.Renderer.prototype.getClearDepth=function(){return this._core.clearDepth},SceneJS.Renderer.prototype.setDepthRange=function(a){this._core.depthRange=a?{zNear:void 0==a.zNear||null==a.zNear?0:a.zNear,zFar:void 0==a.zFar||null==a.zFar?1:a.zFar}:void 0,this._core.dirty=!0},SceneJS.Renderer.prototype.getDepthRange=function(){return this._core.depthRange?{zNear:this._core.depthRange.zNear,zFar:this._core.depthRange.zFar}:void 0},SceneJS.Renderer.prototype.setFrontFace=function(a){this._core.frontFace=a,this._core.dirty=!0},SceneJS.Renderer.prototype.getFrontFace=function(){return this._core.frontFace},SceneJS.Renderer.prototype.setLineWidth=function(a){this._core.lineWidth=a,this._core.dirty=!0},SceneJS.Renderer.prototype.getLineWidth=function(){return this._core.lineWidth},SceneJS.Renderer.prototype.setEnableScissorTest=function(a){this._core.enableScissorTest=a,this._core.dirty=!0},SceneJS.Renderer.prototype.getEnableScissorTest=function(){return this._core.enableScissorTest},SceneJS.Renderer.prototype.setClearStencil=function(a){this._core.clearStencil=a,this._core.dirty=!0},SceneJS.Renderer.prototype.getClearStencil=function(){return this._core.clearStencil},SceneJS.Renderer.prototype.setColorMask=function(a){this._core.colorMask=a?{r:a.r||0,g:a.g||0,b:a.b||0,a:void 0==a.a||null==a.a?1:a.a}:void 0,this._core.dirty=!0},SceneJS.Renderer.prototype.getColorMask=function(){return this._core.colorMask?{r:this._core.colorMask.r,g:this._core.colorMask.g,b:this._core.colorMask.b,a:this._core.colorMask.a}:void 0},SceneJS.Renderer.prototype._compile=function(b){this._core.dirty&&(this._core.props=a(this._core),this._core.dirty=!1),this._engine.display.renderer=e[f++]=this._core,this._compileNodes(b),this._engine.display.renderer=--f>0?e[f-1]:d,e[f]=null}},function(){var a={less:"LESS",equal:"EQUAL",lequal:"LEQUAL",greater:"GREATER",notequal:"NOTEQUAL",gequal:"GEQUAL"},b={type:"depthBuffer",stateId:SceneJS._baseStateId++,enabled:!0,clearDepth:1,depthFunc:null,_depthFuncName:"less"},c=[],d=0;SceneJS_events.addListener(SceneJS_events.SCENE_COMPILING,function(a){null===b.depthFunc&&(b.depthFunc=a.engine.canvas.gl.LESS),a.engine.display.depthBuffer=b,d=0}),SceneJS.DepthBuf=SceneJS_NodeFactory.createNodeType("depthBuffer"),SceneJS.DepthBuf.prototype._init=function(a){void 0!=a.enabled?this.setEnabled(a.enabled):1==this._core.useCount&&this.setEnabled(!0),void 0!=a.clearDepth?this.setClearDepth(a.clearDepth):1==this._core.useCount&&this.setClearDepth(1),void 0!=a.depthFunc?this.setDepthFunc(a.depthFunc):1==this._core.useCount&&this.setDepthFunc("less"),void 0!=a.clear?this.setClear(a.clear):1==this._core.useCount&&this.setClear(!0)},SceneJS.DepthBuf.prototype.setEnabled=function(a){return this._core.enabled!=a&&(this._core.enabled=a,this._engine.display.imageDirty=!0),this},SceneJS.DepthBuf.prototype.getEnabled=function(){return this._core.enabled},SceneJS.DepthBuf.prototype.setClear=function(a){return this._core.clear!=a&&(this._core.clear=a,this._engine.display.imageDirty=!0),this},SceneJS.DepthBuf.prototype.getClear=function(){return this._core.clear},SceneJS.DepthBuf.prototype.setClearDepth=function(a){return this._core.clearDepth!=a&&(this._core.clearDepth=a,this._engine.display.imageDirty=!0),this},SceneJS.DepthBuf.prototype.getClearDepth=function(){return this._core.clearDepth},SceneJS.DepthBuf.prototype.setDepthFunc=function(b){if(this._core._depthFuncName!=b){var c=a[b];if(void 0==c)throw"unsupported value for 'clearFunc' attribute on depthBuffer node: '"+b+"' - supported values are 'less', 'equal', 'lequal', 'greater', 'notequal' and 'gequal'";this._core.depthFunc=this._engine.canvas.gl[c],this._core._depthFuncName=b,this._engine.display.imageDirty=!0}return this},SceneJS.DepthBuf.prototype.getDepthFunc=function(){return this._core._depthFuncName},SceneJS.DepthBuf.prototype._compile=function(a){this._engine.display.depthBuffer=c[d++]=this._core,this._compileNodes(a),this._engine.display.depthBuffer=--d>0?c[d-1]:b,c[d]=null}}(),function(){var a={never:"NEVER",less:"LESS",equal:"EQUAL",lequal:"LEQUAL",greater:"GREATER",notequal:"NOTEQUAL",gequal:"GEQUAL",always:"ALWAYS",keep:"KEEP",zero:"ZERO",replace:"REPLACE",incr:"INCR",incr_wrap:"INCR_WRAP",decr:"DECR",decr_wrap:"DECR_WRAP",invert:"INVERT",front:"FRONT",back:"BACK",front_and_back:"FRONT_AND_BACK"},b={type:"stencilBuffer",stateId:SceneJS._baseStateId++,enabled:!1,clearStencil:0,stencilFuncFuncFront:null,stencilFuncRefFront:0,stencilFuncMaskFront:255,stencilFuncFuncBack:null,stencilFuncRefBack:0,stencilFuncMaskBack:255,stencilOpSfailFront:null,stencilOpDpfailFront:null,stencilOpDppassFront:null,stencilOpSfailBack:null,stencilOpDpfailBack:null,stencilOpDppassBack:null,_stencilFuncFuncStateFront:"always",_stencilFuncRefStateFront:0,_stencilFuncMaskStateFront:255,_stencilFuncFuncStateBack:"always",_stencilFuncRefStateBack:0,_stencilFuncMaskStateBack:255,_stencilOpSfailStateFront:"keep",_stencilOpDpfailStateFront:"keep",_stencilOpDppassStateFront:"keep",_stencilOpSfailStateBack:"keep",_stencilOpDpfailStateBack:"keep",_stencilOpDppassStateBack:"keep"},c=[],d=0;SceneJS_events.addListener(SceneJS_events.SCENE_COMPILING,function(a){null===b.stencilFuncFuncFront&&(b.stencilFuncFuncFront=a.engine.canvas.gl.ALWAYS),null===b.stencilFuncFuncBack&&(b.stencilFuncFuncBack=a.engine.canvas.gl.ALWAYS),null===b.stencilOpSfailFront&&(b.stencilOpSfailFront=a.engine.canvas.gl.KEEP,b.stencilOpDpfailFront=a.engine.canvas.gl.KEEP,b.stencilOpDppassFront=a.engine.canvas.gl.KEEP),null===b.stencilOpSfailBack&&(b.stencilOpSfailBack=a.engine.canvas.gl.KEEP,b.stencilOpDpfailBack=a.engine.canvas.gl.KEEP,b.stencilOpDppassBack=a.engine.canvas.gl.KEEP),a.engine.display.stencilBuffer=b,d=0}),SceneJS.StencilBuf=SceneJS_NodeFactory.createNodeType("stencilBuffer"),SceneJS.StencilBuf.prototype._init=function(a){void 0!=a.enabled?this.setEnabled(a.enabled):1==this._core.useCount&&this.setEnabled(!0),void 0!=a.clearStencil?this.setClearStencil(a.clearStencil):1==this._core.useCount&&this.setClearStencil(0),void 0!=a.stencilFunc?this.setStencilFunc(a.stencilFunc):1==this._core.useCount&&this.setStencilFunc({face:"front_back",func:"always",ref:1,mask:255}),void 0!=a.stencilOp?this.setStencilOp(a.stencilOp):1==this._core.useCount&&this.setStencilOp({face:"front_back",sfail:"keep",dpfail:"keep",dppass:"keep"}),void 0!=a.clear&&this.setClear(a.clear)},SceneJS.StencilBuf.prototype.setEnabled=function(a){return this._core.enabled!=a&&(this._core.enabled=a,this._engine.display.imageDirty=!0),this},SceneJS.StencilBuf.prototype.getEnabled=function(){return this._core.enabled},SceneJS.StencilBuf.prototype.setClear=function(a){return this._core.clear!=a&&(this._core.clear=a,this._engine.display.imageDirty=!0),this},SceneJS.StencilBuf.prototype.getClear=function(){return this._core.clear},SceneJS.StencilBuf.prototype.setClearStencil=function(a){return this._core.clearStencil!=a&&(this._core.clearStencil=a,this._engine.display.imageDirty=!0),this},SceneJS.StencilBuf.prototype.getClearStencil=function(){return this._core.clearStencil},SceneJS.StencilBuf.prototype.setStencilFunc=function(b){var c=!1,d=!1,e=b.func||"always",f=void 0!==b.ref?b.ref:1,g=void 0!==b.mask?b.mask:255,h=e,i=f,j=g,k=b.face||"front_and_back";if(b.front||b.back?(b.front&&(c=!0,e=b.front.func||"always",f=void 0!==b.front.ref?b.front.ref:1,g=void 0!==b.front.mask?b.front.mask:255),b.back&&(d=!0,h=b.back.func||"always",i=void 0!==b.back.ref?b.back.ref:1,j=void 0!==b.back.mask?b.back.mask:255)):(c="front"===k||"front_and_back"===k,d="back"===k||"front_and_back"===k),f!==i||g!==j)throw"WebGL only allow same value for stencil ref and mask of front and back faces";if(c&&(this._core._stencilFuncFuncStateFront!=e||this._core._stencilFuncRefStateFront!=f||this._core._stencilFuncMaskStateFront!=g)){var l=a[e];if(void 0==l)throw"unsupported value for 'stencilFunc' attribute on stencilBuffer node: '"+stencilFunc.func+"' - supported values are 'keep', 'always', 'less', 'equal', 'lequal', 'greater', 'notequal' and 'gequal'";this._core.stencilFuncFuncFront=this._engine.canvas.gl[l],this._core.stencilFuncRefFront=f,this._core.stencilFuncMaskFront=g,this._core._stencilFuncFuncStateFront=e,this._core._stencilFuncRefStateFront=f,this._core._stencilFuncMaskStateFront=g,this._engine.display.imageDirty=!0}if(d&&(this._core._stencilFuncFuncStateBack!=h||this._core._stencilFuncRefStateBack!=i||this._core._stencilFuncMaskStateBack!=j)){var l=a[h];if(void 0==l)throw"unsupported value for 'stencilFunc' attribute on stencilBuffer node: '"+stencilFunc.func+"' - supported values are 'keep', 'always', 'less', 'equal', 'lequal', 'greater', 'notequal' and 'gequal'";this._core.stencilFuncFuncBack=this._engine.canvas.gl[l],this._core.stencilFuncRefBack=i,this._core.stencilFuncMaskBack=j,this._core._stencilFuncFuncStateBack=h,this._core._stencilFuncRefStateBack=i,this._core._stencilFuncMaskStateBack=j,this._engine.display.imageDirty=!0}return this},SceneJS.StencilBuf.prototype.setStencilOp=function(b){var c=!1,d=!1,e=b.sfail||"keep",f=b.dpfail||"keep",g=b.dppass||"keep",h=e,i=f,j=g,k=b.face||"front_and_back";if(b.front||b.back?(b.front&&(c=!0,e=b.front.sfail||"keep",f=b.front.dpfail||"keep",g=b.front.dppass||"keep"),b.back&&(d=!0,h=b.back.sfail||"keep",i=b.back.dpfail||"keep",j=b.back.dppass||"keep")):(c="front"===k||"front_and_back"===k,d="back"===k||"front_and_back"===k),c&&(this._core._stencilOpSfailStateFront!=e||this._core._stencilOpDpfailStateFront!=f||this._core._stencilOpDppassStateFront!=g)){var l=a[e],m=a[f],n=a[g];if(void 0==l||void 0==m||void 0==n)throw"unsupported value for 'StencilOp' attribute on stencilBuffer node - supported values are 'keep', 'zero', 'replace', 'incr', 'incr_wrap', 'decr', 'decr_wrap', 'invert'";this._core.stencilOpSfailFront=this._engine.canvas.gl[l],this._core.stencilOpDpfailFront=this._engine.canvas.gl[m],this._core.stencilOpDppassFront=this._engine.canvas.gl[n],this._core._stencilOpSfailStateFront=e,this._core._stencilOpSfailStateFront=f,this._core._stencilOpSfailStateFront=g,this._engine.display.imageDirty=!0}if(d&&(this._core._stencilOpSfailStateBack!=h||this._core._stencilOpDpfailStateBack!=i||this._core._stencilOpDppassStateBack!=j)){var l=a[h],m=a[i],n=a[j];if(void 0==l||void 0==m||void 0==n)throw"unsupported value for 'StencilOp' attribute on stencilBuffer node - supported values are 'keep', 'zero', 'replace', 'incr', 'incr_wrap', 'decr', 'decr_wrap', 'invert'";this._core.stencilOpSfailBack=this._engine.canvas.gl[l],this._core.stencilOpDpfailBack=this._engine.canvas.gl[m],this._core.stencilOpDppassBack=this._engine.canvas.gl[n],this._core._stencilOpSfailStateBack=h,this._core._stencilOpSfailStateBack=i,this._core._stencilOpSfailStateBack=j,this._engine.display.imageDirty=!0}return this},SceneJS.StencilBuf.prototype.getStencilFuncFront=function(){return{func:this._core._stencilFuncFuncStateFront,ref:this._core._stencilFuncRefStateFront,mask:this._core._stencilFuncMaskStateFront}},SceneJS.StencilBuf.prototype.getStencilFuncBack=function(){return{func:this._core._stencilFuncFuncStateBack,ref:this._core._stencilFuncRefStateBack,mask:this._core._stencilFuncMaskStateBack}},SceneJS.StencilBuf.prototype.getStencilOpFront=function(){return{sfail:this._core._stencilOpSfailStateFront,dpfail:this._core._stencilOpDpfailStateFront,dppass:this._core._stencilOpDppassStateFront}},SceneJS.StencilBuf.prototype.getStencilOpBack=function(){return{sfail:this._core._stencilOpSfailStateBack,dpfail:this._core._stencilOpDpfailStateBack,dppass:this._core._stencilOpDppassStateBack}},SceneJS.StencilBuf.prototype._compile=function(a){this._engine.display.stencilBuffer=c[d++]=this._core,this._compileNodes(a),this._engine.display.stencilBuffer=--d>0?c[d-1]:b,c[d]=null}}(),function(){var a={type:"colorBuffer",stateId:SceneJS._baseStateId++,blendEnabled:!1,colorMask:{r:!0,g:!0,b:!0,a:!0}},b=[],c=0;SceneJS_events.addListener(SceneJS_events.SCENE_COMPILING,function(b){b.engine.display.colorBuffer=a,c=0}),SceneJS.ColorBuffer=SceneJS_NodeFactory.createNodeType("colorBuffer"),SceneJS.ColorBuffer.prototype._init=function(a){void 0!=a.blendEnabled?this.setBlendEnabled(a.blendEnabled):1==this._core.useCount&&this.setBlendEnabled(!1),this.setColorMask(a)},SceneJS.ColorBuffer.prototype.setBlendEnabled=function(a){this._core.blendEnabled!=a&&(this._core.blendEnabled=a,this._engine.display.imageDirty=!0),this._engine.display.imageDirty=!0},SceneJS.ColorBuffer.prototype.getBlendEnabled=function(){return this._core.blendEnabled},SceneJS.ColorBuffer.prototype.setColorMask=function(a){this._core.colorMask={r:void 0==a.r||null==a.r||a.r,g:void 0==a.g||null==a.g||a.g,b:void 0==a.b||null==a.b||a.b,a:void 0==a.a||null==a.a||a.a},this._engine.display.imageDirty=!0},SceneJS.ColorBuffer.prototype.getColorMask=function(){return this._core.colorMask},SceneJS.ColorBuffer.prototype._compile=function(d){this._engine.display.colorBuffer=b[c++]=this._core,this._compileNodes(d),this._engine.display.colorBuffer=--c>0?b[c-1]:a,b[c]=null,this._engine.display.imageDirty=!0}}(),function(){var a={type:"view",stateId:SceneJS._baseStateId++,scissorTestEnabled:!1},b=[],c=0;SceneJS_events.addListener(SceneJS_events.SCENE_COMPILING,function(b){b.engine.display.view=a,c=0}),SceneJS.View=SceneJS_NodeFactory.createNodeType("view"),SceneJS.View.prototype._init=function(a){void 0!=a.scissorTestEnabled?this.setScissorTestEnabled(a.scissorTestEnabled):1==this._core.useCount&&this.setScissorTestEnabled(!1)},SceneJS.View.prototype.setScissorTestEnabled=function(a){return this._core.scissorTestEnabled!=a&&(this._core.scissorTestEnabled=a,this._engine.display.imageDirty=!0),this},SceneJS.View.prototype.getScissorTestEnabled=function(){return this._core.scissorTestEnabled},SceneJS.View.prototype._compile=function(d){this._engine.display.view=b[c++]=this._core,this._compileNodes(d),this._engine.display.view=--c>0?b[c-1]:a,b[c]=null}}(),SceneJS.Scene=SceneJS_NodeFactory.createNodeType("scene"),SceneJS.Scene.prototype._init=function(a){a.tagMask&&this.setTagMask(a.tagMask),this._tagSelector=null,this.transparent=a.transparent===!0,this.stats=this._engine.stats},SceneJS.Scene.prototype.loseWebGLContext=function(){this._engine.loseWebGLContext()},SceneJS.Scene.prototype.getCanvas=function(){return this._engine.canvas.canvas},SceneJS.Scene.prototype.getGL=function(){return this._engine.canvas.gl},SceneJS.Scene.prototype.getWebGL2Supported=function(){return this._engine.canvas.webgl2},SceneJS.Scene.prototype.getZBufferDepth=function(){var a=this._engine.canvas.gl;return a.getParameter(a.DEPTH_BITS)},SceneJS.Scene.prototype.setResolutionScaling=function(a){return this._engine.canvas.setResolutionScaling(a)},SceneJS.Scene.prototype.setTagMask=function(a){a=a||"XXXXXXXXXXXXXXXXXXXXXXXXXX",this._tagSelector||(this._tagSelector={}),this._tagSelector.mask=a,this._tagSelector.regex=a?new RegExp(a):null,this._engine.display.selectTags(this._tagSelector)},SceneJS.Scene.prototype.getTagMask=function(){return this._tagSelector?this._tagSelector.mask:null},SceneJS.Scene.prototype.setNumPasses=function(a){this._engine.setNumPasses(a)},SceneJS.Scene.prototype.setClearEachPass=function(a){this._engine.setClearEachPass(a)},SceneJS.Scene.prototype.setBindOutputFrameBuffer=function(a,b){this._engine.display.bindOutputFramebuffer=a,this._engine.display.unbindOutputFramebuffer=b},SceneJS.Scene.prototype.renderFrame=function(a){return this._engine.renderFrame(a)},SceneJS.Scene.prototype.pauseCompilation=function(){return this._engine.pauseCompilation()},SceneJS.Scene.prototype.resumeCompilation=function(){return this._engine.resumeCompilation()},SceneJS.Scene.prototype.compile=function(){return this._engine.compile()},SceneJS.Scene.prototype.needFrame=function(){this._engine.display.imageDirty=!0},SceneJS.Scene.prototype.start=function(a){this._engine.start(a)},SceneJS.Scene.prototype.setFPS=function(a){this._engine.fps=a},SceneJS.Scene.prototype.pause=function(a){this._engine.pause(a)},SceneJS.Scene.prototype.isRunning=function(){return this._engine.running},SceneJS.Scene.prototype.pick=function(a){var b=this._engine.pick(a);return this.renderFrame({force:!0}),b?(this.publish("pick",b),b):void this.publish("nopick")},SceneJS.Scene.prototype.readPixels=function(a,b,c){return this._engine.readPixels(a,b,c)},SceneJS.Scene.prototype._destroy=function(){this.destroyed||(delete SceneJS._engines[this.id],SceneJS._engineIds.removeItem(this.id),this.destroyed=!0)},SceneJS.Scene.prototype.isActive=function(){return!this._engine.destroyed},SceneJS.Scene.prototype.stop=function(){this._engine.stop()},SceneJS.Scene.prototype.containsNode=function(a){return!!this._engine.findNode(a)},SceneJS.Scene.prototype.findNodes=function(a){return this._engine.findNodes(a)},SceneJS.Scene.prototype.findNode=function(a,b){return this.getNode(a,b)},SceneJS.Scene.prototype.getNode=function(a,b){var c=this._engine.findNode(a);return c?(b&&b(c),c):b?void this.once("nodes/"+a,b):null},SceneJS.Scene.prototype.hasCore=function(a,b){return this._engine.hasCore(a,b)},SceneJS.Scene.prototype.setDepthSort=function(a){this._engine.setDepthSort(a)},SceneJS.Scene.prototype.getStatus=function(){var a=SceneJS_sceneStatusModule.sceneStatus[this.id];return a?SceneJS._shallowClone(a):{destroyed:!0}},new function(){function a(a){for(var b,c,d={},e=0;e0){var l={type:"shader",stateId:c[i-1],hash:c.slice(0,i).join("."),shaders:{fragment:{code:f.slice(0,i).join(""),hooks:a(g)},vertex:{code:d.slice(0,i).join(""),hooks:a(e)}},paramsStack:h.slice(0,i)};k.display.shader=l}else k.display.shader=b;j=!1}}),SceneJS.Shader=SceneJS_NodeFactory.createNodeType("shader"),SceneJS.Shader.prototype._init=function(a){1==this._core.useCount&&(this._setShaders(a.shaders),this.setParams(a.params))},SceneJS.Shader.prototype._setShaders=function(a){a=a||[],this._core.shaders={};for(var b,c=0,d=a.length;c0){var g={type:"shaderParams",stateId:c[e-1],paramsStack:d.slice(0,e)};f.display.shaderParams=g}else f.display.shaderParams=b;a=!1}}),SceneJS.ShaderParams=SceneJS_NodeFactory.createNodeType("shaderParams"),SceneJS.ShaderParams.prototype._init=function(a){1==this._core.useCount&&this.setParams(a.params)},SceneJS.ShaderParams.prototype.setParams=function(a){a=a||{};var b=this._core;b.params||(b.params={});for(var c in a)a.hasOwnProperty(c)&&(b.params[c]=a[c]);this._engine.display.imageDirty=!0},SceneJS.ShaderParams.prototype.getParams=function(){var a=this._core.params;if(!a)return{};var b={};for(var c in a)a.hasOwnProperty(c)&&(b[c]=a[c]);return b},SceneJS.ShaderParams.prototype._compile=function(b){c[e]=this._core.coreId,d[e]=this._core.params,e++,a=!0,this._compileNodes(b),e--,a=!0}},function(){var a={type:"style",stateId:SceneJS._baseStateId++,lineWidth:1},b=[],c=0;SceneJS_events.addListener(SceneJS_events.SCENE_COMPILING,function(b){b.engine.display.style=a,c=0}),SceneJS.Style=SceneJS_NodeFactory.createNodeType("style"),SceneJS.Style.prototype._init=function(a){void 0!=a.lineWidth&&this.setLineWidth(a.lineWidth)},SceneJS.Style.prototype.setLineWidth=function(a){return this._core.lineWidth!=a&&(this._core.lineWidth=a,this._engine.display.imageDirty=!0),this},SceneJS.Style.prototype.getLineWidth=function(){return this._core.lineWidth},SceneJS.Style.prototype._compile=function(d){this._engine.display.style=b[c++]=this._core,this._compileNodes(d),this._engine.display.style=--c>0?b[c-1]:a,b[c]=null}}(),function(){var a={type:"tag",stateId:SceneJS._baseStateId++,tag:null},b=[],c=0;SceneJS_events.addListener(SceneJS_events.SCENE_COMPILING,function(b){b.engine.display.tag=a,c=0}),SceneJS.Tag=SceneJS_NodeFactory.createNodeType("tag"),SceneJS.Tag.prototype._init=function(a){if(1==this._core.useCount){if(!a.tag)throw SceneJS_error.fatalError(SceneJS.errors.NODE_CONFIG_EXPECTED,"tag node attribute missing : 'tag'");this.setTag(a.tag)}},SceneJS.Tag.prototype.setTag=function(a){var b=this._core;b.tag=a,b.pattern=null,b.matched=!1,this._engine.display.drawListDirty=!0},SceneJS.Tag.prototype.getTag=function(){return this._core.tag},SceneJS.Tag.prototype._compile=function(d){this._engine.display.tag=b[c++]=this._core,this._compileNodes(d),this._engine.display.tag=--c>0?b[c-1]:a,b[c]=null}}(),new function(){var a={type:"texture",stateId:SceneJS._baseStateId++,empty:!0,hash:""},b=[],c=0;SceneJS_events.addListener(SceneJS_events.SCENE_COMPILING,function(b){b.engine.display.texture=a,c=0}),SceneJS.Texture=SceneJS_NodeFactory.createNodeType("_texture"),SceneJS.Texture.prototype._init=function(a){if(1==this._core.useCount){this._core.layers=[],this._core.params={};var b=void 0==a.waitForLoad||a.waitForLoad;if(!a.layers)throw SceneJS_error.fatalError(SceneJS.errors.NODE_CONFIG_EXPECTED,"texture layers missing");if(!SceneJS._isArray(a.layers))throw SceneJS_error.fatalError(SceneJS.errors.NODE_CONFIG_EXPECTED,"texture layers should be an array");for(var c,d=this._engine.canvas.gl,e=0;e>b;return a+1},SceneJS.Texture.prototype._setLayerTexture=function(a,b,c){b.texture=new SceneJS._webgl.Texture2D(a,{texture:c,minFilter:this._getGLOption("minFilter",a,b,a.LINEAR_MIPMAP_NEAREST),magFilter:this._getGLOption("magFilter",a,b,a.LINEAR),wrapS:this._getGLOption("wrapS",a,b,a.REPEAT),wrapT:this._getGLOption("wrapT",a,b,a.REPEAT),update:null}),this.destroyed&&b.texture.destroy(),this._engine.display.imageDirty=!0; +},SceneJS.Texture.prototype._getGLOption=function(a,b,c,d){var e=c[a];if(void 0==e)return d;var f=SceneJS._webgl.enumMap[e];if(void 0==f)throw SceneJS_error.fatalError(SceneJS.errors.ILLEGAL_NODE_CONFIG,"Unrecognised value for texture node property '"+a+"' value: '"+e+"'");var g=b[f];return g},SceneJS.Texture.prototype._getOption=function(a,b){return void 0==a?b:a},SceneJS.Texture.prototype.setLayer=function(a){if(void 0==a.index||null==a.index)throw SceneJS_error.fatalError(SceneJS.errors.ILLEGAL_NODE_CONFIG,"Invalid texture set layer argument: index null or undefined");if(a.index<0||a.index>=this._core.layers.length)throw SceneJS_error.fatalError(SceneJS.errors.ILLEGAL_NODE_CONFIG,"Invalid texture set layer argument: index out of range ("+this._core.layers.length+" layers defined)");this._setLayer(parseInt(a.index),a),this._engine.display.imageDirty=!0},SceneJS.Texture.prototype.setLayers=function(a){var b;for(var c in a)if(a.hasOwnProperty(c)&&(void 0!=c||null!=c)){if(b=parseInt(c),b<0||b>=this._core.layers.length)throw SceneJS_error.fatalError(SceneJS.errors.ILLEGAL_NODE_CONFIG,"Invalid texture set layer argument: index out of range ("+this._core.layers.length+" layers defined)");this._setLayer(b,a[c]||{})}this._engine.display.imageDirty=!0},SceneJS.Texture.prototype._setLayer=function(a,b){b=b||{};var c=this._core.layers[a];if(void 0!=b.blendFactor&&null!=b.blendFactor&&(c.blendFactor=b.blendFactor),b.source){var d=c._source;d&&d.configure&&d.configure(b.source)}(b.translate||b.rotate||b.scale)&&this._setLayerTransform(b,c)},SceneJS.Texture.prototype._setLayerTransform=function(a,b){var c,d;if(a.translate){var e=a.translate;void 0!=e.x&&(b.translate.x=e.x),void 0!=e.y&&(b.translate.y=e.y),c=SceneJS_math_translationMat4v([e.x||0,e.y||0,0])}if(a.scale){var f=a.scale;void 0!=f.x&&(b.scale.x=f.x),void 0!=f.y&&(b.scale.y=f.y),d=SceneJS_math_scalingMat4v([f.x||1,f.y||1,1]),c=c?SceneJS_math_mulMat4(c,d):d}if(a.rotate){var g=a.rotate;void 0!=g.z&&(b.rotate.z=g.z||0),d=SceneJS_math_rotationMat4v(.0174532925*g.z,[0,0,1]),c=c?SceneJS_math_mulMat4(c,d):d}c&&(b.matrix=c,b.matrixAsArray?b.matrixAsArray.set(b.matrix):b.matrixAsArray=new Float32Array(b.matrix),b.matrixAsArray=new Float32Array(b.matrix))},SceneJS.Texture.prototype._compile=function(d){this._core.hash||this._makeHash(),this._engine.display.texture=b[c++]=this._core,this._compileNodes(d),this._engine.display.texture=--c>0?b[c-1]:a,b[c]=null},SceneJS.Texture.prototype._makeHash=function(){var a,b=this._core;if(b.layers&&b.layers.length>0){for(var c,d=b.layers,e=[],f=0,g=d.length;f'");var e=0;if("uv"!==d&&(e=d.substring(2),isNaN(e)))throw SceneJS_error.fatalError(SceneJS.errors.NODE_CONFIG_EXPECTED,"texture applyFrom value invalid - should be 'uv'");if(b.applyTo){var f=b.applyTo;if("baseColor"!=f&&"color"!=f&&"specular"!=f&&"emit"!=f&&"alpha"!=f&&"normals"!=f&&"shine"!=f)throw SceneJS_error.fatalError(SceneJS.errors.NODE_CONFIG_EXPECTED,"texture applyTo value is unsupported - should be either 'color', 'baseColor', 'specular' or 'normals'")}if(b.blendMode&&"add"!=b.blendMode&&"multiply"!=b.blendMode)throw SceneJS_error.fatalError(SceneJS.errors.NODE_CONFIG_EXPECTED,"texture layer blendMode value is unsupported - should be either 'add' or 'multiply'");"color"==b.applyTo&&(b.applyTo="baseColor"),SceneJS._apply({waitForLoad:void 0==b.waitForLoad||b.waitForLoad,texture:null,minFilter:b.minFilter,magFilter:b.magFilter,wrapS:b.wrapS,wrapT:b.wrapT,uvLayerIdx:e,isNormalMap:"normals"===b.applyTo,applyFrom:d,applyTo:b.applyTo?b.applyTo:"baseColor",blendMode:b.blendMode?b.blendMode:"multiply",blendFactor:void 0!=b.blendFactor&&null!=b.blendFactor?b.blendFactor:1,translate:b.translate?SceneJS._apply(b.translate,{x:0,y:0}):{x:0,y:0},scale:b.scale?SceneJS._apply(b.scale,{x:1,y:1}):{x:1,y:1},rotate:b.rotate||0,matrix:null,_matrixDirty:!0,buildMatrix:a},this._core),a.call(this._core),b.src?(this._initTexture(b.preloadColor),this._core.src=b.src,this._loadTexture(b.src,b.preloadSrc)):b.image?(this._initTexture(b.preloadColor),this._core.image=b.image,this._setTextureImage(b.image)):b.target&&this.getScene().getNode(b.target,function(a){c.setTarget(a)}),this._core.webglRestored=function(){c._core.image?(c._initTexture(b.preloadColor),c._setTextureImage(c._core.image)):c._core.src?(c._initTexture(b.preloadColor),c._loadTexture(c._core.src)):c._core.target},this._engine.stats.memory.textures++}},SceneJS.TextureMap.prototype._initTexture=function(a){var b=this._engine.canvas.gl;a=a||{r:.57735,g:.57735,b:.57735},a.a=void 0===a.a?1:a.a,a=new Uint8Array([Math.floor(255*a.r),Math.floor(255*a.g),Math.floor(255*a.b),Math.floor(255*a.a)]);var c=b.createTexture();b.bindTexture(b.TEXTURE_2D,c),b.texImage2D(b.TEXTURE_2D,0,b.RGBA,1,1,0,b.RGBA,b.UNSIGNED_BYTE,a),this._setCoreTexture(c)},SceneJS.TextureMap.prototype._loadTexture=function(a,b){var c=this,d=SceneJS_sceneStatusModule.taskStarted(this,"Loading texture"),e=new Image,f=!1,g=!1;if(b){var h=new Image;h.onload=function(){f||(c._setTextureImage(h),SceneJS_sceneStatusModule.taskFinished(d),g=!0,c._engine.display.imageDirty=!0)},this._fetchImage(h,b)}e.onload=function(){c._setTextureImage(e),g||SceneJS_sceneStatusModule.taskFinished(d),f=!0,c._engine.display.imageDirty=!0},e.onerror=function(){SceneJS_sceneStatusModule.taskFailed(d)},this._fetchImage(e,a)},SceneJS.TextureMap.prototype._fetchImage=function(a,b){0==b.indexOf("data")?a.src=b:(a.crossOrigin="Anonymous",a.src=b)},SceneJS.TextureMap.prototype._setTextureImage=function(a){var b=this._engine.canvas.gl,c=this._core,d=c.texture&&c.texture.texture?c.texture.texture:b.createTexture();b.bindTexture(b.TEXTURE_2D,d);var e=SceneJS_configsModule.configs.maxTextureSize;e&&(a=SceneJS._webgl.clampImageSize(a,e)),b.texImage2D(b.TEXTURE_2D,0,b.RGBA,b.RGBA,b.UNSIGNED_BYTE,SceneJS._webgl.ensureImageSizePowerOfTwo(a)),c.image=a,this._setCoreTexture(d)},SceneJS.TextureMap.prototype._setCoreTexture=function(a){var b=this._engine.canvas.gl;this._core.texture=new SceneJS._webgl.Texture2D(b,{texture:a,minFilter:this._getGLOption("minFilter",b.LINEAR_MIPMAP_NEAREST),magFilter:this._getGLOption("magFilter",b.LINEAR),wrapS:this._getGLOption("wrapS",b.REPEAT),wrapT:this._getGLOption("wrapT",b.REPEAT),update:null}),this.destroyed&&this._core.texture.destroy(),this._engine.display.imageDirty=!0},SceneJS.TextureMap.prototype._getGLOption=function(a,b){var c=this._engine.canvas.gl,d=this._core[a];if(void 0==d)return b;var e=SceneJS._webgl.enumMap[d];if(void 0==e)throw SceneJS_error.fatalError(SceneJS.errors.ILLEGAL_NODE_CONFIG,"Unrecognised value for texture node property '"+a+"' value: '"+d+"'");return c[e]},SceneJS.TextureMap.prototype._getOption=function(a,b){return void 0==a?b:a},SceneJS.TextureMap.prototype.setSrc=function(a){this._core.image=null,this._core.src=a,this._core.target=null,this._loadTexture(a)},SceneJS.TextureMap.prototype.setImage=function(a){this._core.image=a,this._core.src=null,this._core.target=null,this._setTextureImage(a)},SceneJS.TextureMap.prototype.setTarget=function(a){return"colorTarget"!=a.type&&"depthTarget"!=a.type?void console.log("Target node type not compatible: "+a.type):(delete this._core.src,this._core.target=a,this._core.src=null,this._core.image=null,this._core.texture=a._core.renderBuf.getTexture(),this._core.texture.bufType=a._core.bufType,void(this._engine.display.imageDirty=!0))},SceneJS.TextureMap.prototype.setBlendFactor=function(a){this._core.blendFactor=a,this._engine.display.imageDirty=!0},SceneJS.TextureMap.prototype.getBlendFactor=function(){return this._core.blendFactor},SceneJS.TextureMap.prototype.setTranslate=function(a){this._core.translate||(this._core.translate={x:0,y:0}),this._core.translate.x=a.x,this._core.translate.y=a.y,this._core._matrixDirty=!0,this._engine.display.imageDirty=!0},SceneJS.TextureMap.prototype.getTranslate=function(){return this._core.translate},SceneJS.TextureMap.prototype.setScale=function(a){this._core.scale||(this._core.scale={x:0,y:0}),this._core.scale.x=a.x,this._core.scale.y=a.y,this._core._matrixDirty=!0,this._engine.display.imageDirty=!0},SceneJS.TextureMap.prototype.getScale=function(){return this._core.scale},SceneJS.TextureMap.prototype.setRotate=function(a){this._core.rotate=a,this._core._matrixDirty=!0,this._engine.display.imageDirty=!0},SceneJS.TextureMap.prototype.getRotate=function(){return this._core.rotate},SceneJS.TextureMap.prototype.getMatrix=function(){return this._core._matrixDirty&&this._core.buildMatrix.call(this.core)(),this.core.matrix},SceneJS.TextureMap.prototype._compile=function(a){this.__core||(this.__core=this._engine._coreFactory.getCore("texture"));var e=this._engine.display.texture;this._core.empty||(this.__core.layers=e&&e.layers?e.layers.concat([this._core]):[this._core]),this._makeHash(this.__core),c[d++]=this.__core,this._engine.display.texture=this.__core,this._compileNodes(a),this._engine.display.texture=--d>0?c[d-1]:b,c[d]=null},SceneJS.TextureMap.prototype._makeHash=function(a){var b;if(a.layers&&a.layers.length>0){for(var c,d=a.layers,e=[],f=0,g=d.length;f0?b[c-1]:a,b[c]=null},SceneJS.Fresnel.prototype._makeHash=function(a){var b=[];a.diffuse&&b.push("d;"),a.specular&&b.push("s;"),a.alpha&&b.push("a;"),a.reflect&&b.push("r;"),a.emit&&b.push("e;"),a.fragment&&b.push("f;"),b=b.join(""),a.hash!=b&&(a.hash=b)},SceneJS.Fresnel.prototype._destroy=function(){this._core&&this._engine._coreFactory.putCore(this._core)}},function(){var a={type:"cubemap",stateId:SceneJS._baseStateId++,empty:!0,texture:null,hash:""},b=[],c=0;SceneJS_events.addListener(SceneJS_events.SCENE_COMPILING,function(b){b.engine.display.cubemap=a,c=0}),SceneJS.Reflect=SceneJS_NodeFactory.createNodeType("reflect"),SceneJS.Reflect.prototype._init=function(a){if(1==this._core.useCount){if(this._core.hash="y",a.blendMode&&"add"!=a.blendMode&&"multiply"!=a.blendMode)throw SceneJS_error.fatalError(SceneJS.errors.NODE_CONFIG_EXPECTED,"reflection blendMode value is unsupported - should be either 'add' or 'multiply'");this._core.blendMode=a.blendMode||"multiply",this._core.intensity=void 0!=a.intensity&&null!=a.intensity?a.intensity:1,this._core.applyTo="reflect";for(var b=this,c=this._engine.canvas.gl,d=c.createTexture(),e=[c.TEXTURE_CUBE_MAP_POSITIVE_X,c.TEXTURE_CUBE_MAP_NEGATIVE_X,c.TEXTURE_CUBE_MAP_POSITIVE_Y,c.TEXTURE_CUBE_MAP_NEGATIVE_Y,c.TEXTURE_CUBE_MAP_POSITIVE_Z,c.TEXTURE_CUBE_MAP_NEGATIVE_Z],f=[],g=SceneJS_sceneStatusModule.taskStarted(this,"Loading reflection texture"),h=!1,i=0;i0?b[c-1]:a,b[c]=null},SceneJS.Reflect.prototype._makeHash=function(a){var b;if(a.layers&&a.layers.length>0){for(var c,d=a.layers,e=[],f=0,g=d.length;f'");var d=0;if("uv"!==c&&(d=c.substring(2),isNaN(d)))throw SceneJS_error.fatalError(SceneJS.errors.NODE_CONFIG_EXPECTED,"texture applyFrom value invalid - should be 'uv'");this._core.uvLayerIdx=d,a.src?(this._initTexture(),this._core.src=a.src,this._loadTexture(a.src)):a.image?(this._initTexture(a.preloadColor),this._core.image=a.image,this._setTextureImage(a.image)):a.target&&this.getScene().getNode(a.target,function(a){b.setTarget(a)}),this._core.webglRestored=function(){b._core.image?(b._initTexture(),b._setTextureImage(b._core.image)):b._core.src?(b._initTexture(),b._loadTexture(b._core.src)):b._core.target},this.setRegionColor(a.regionColor),this.setHighlightFactor(a.highlightFactor),this.setHideAlpha(a.hideAlpha),this.setRegionData(a.regionData),this.setMode(a.mode)}},SceneJS.RegionMap.prototype._initTexture=function(){var a=this._engine.canvas.gl,b={r:.57735,g:.57735,b:.57735};b.a=void 0===b.a?1:b.a,b=new Uint8Array([Math.floor(255*b.r),Math.floor(255*b.g),Math.floor(255*b.b),Math.floor(255*b.a)]);var c=a.createTexture();a.bindTexture(a.TEXTURE_2D,c),a.texImage2D(a.TEXTURE_2D,0,a.RGBA,1,1,0,a.RGBA,a.UNSIGNED_BYTE,b),this._setCoreTexture(c)},SceneJS.RegionMap.prototype._loadTexture=function(a){var b=this,c=SceneJS_sceneStatusModule.taskStarted(this,"Loading texture"),d=new Image,e=!1,f=!1;d.onload=function(){b._setTextureImage(d),f||SceneJS_sceneStatusModule.taskFinished(c),e=!0,b._engine.display.imageDirty=!0},d.onerror=function(){SceneJS_sceneStatusModule.taskFailed(c)},this._fetchImage(d,a)},SceneJS.RegionMap.prototype._fetchImage=function(a,b){0==b.indexOf("data")?a.src=b:(a.crossOrigin="Anonymous",a.src=b)},SceneJS.RegionMap.prototype._setTextureImage=function(a){var b=this._engine.canvas.gl,c=this._core.texture?this._core.texture.texture:b.createTexture();b.bindTexture(b.TEXTURE_2D,c),b.texImage2D(b.TEXTURE_2D,0,b.RGBA,b.RGBA,b.UNSIGNED_BYTE,SceneJS._webgl.ensureImageSizePowerOfTwo(a)),this._core.image=a,this._setCoreTexture(c)},SceneJS.RegionMap.prototype._setCoreTexture=function(a){var b=this._engine.canvas.gl;this._core.texture=new SceneJS._webgl.Texture2D(b,{texture:a,minFilter:this._getGLOption("minFilter",b.NEAREST_MIPMAP_NEAREST),magFilter:this._getGLOption("magFilter",b.NEAREST),wrapS:this._getGLOption("wrapS",b.REPEAT),wrapT:this._getGLOption("wrapT",b.REPEAT),isDepth:this._getOption(this._core.isDepth,!1),depthMode:this._getGLOption("depthMode",b.LUMINANCE),depthCompareMode:this._getGLOption("depthCompareMode",b.COMPARE_R_TO_TEXTURE),depthCompareFunc:this._getGLOption("depthCompareFunc",b.LEQUAL),flipY:this._getOption(this._core.flipY,!0),width:this._getOption(this._core.width,1),height:this._getOption(this._core.height,1),internalFormat:this._getGLOption("internalFormat",b.ALPHA),sourceFormat:this._getGLOption("sourceFormat",b.ALPHA),sourceType:this._getGLOption("sourceType",b.UNSIGNED_BYTE),update:null}),this.destroyed&&this._core.texture.destroy(),this._engine.display.imageDirty=!0},SceneJS.RegionMap.prototype._getGLOption=function(a,b){var c=this._engine.canvas.gl,d=this._core[a];if(void 0==d)return b;var e=SceneJS._webgl.enumMap[d];if(void 0==e)throw SceneJS_error.fatalError(SceneJS.errors.ILLEGAL_NODE_CONFIG,"Unrecognised value for texture node property '"+a+"' value: '"+d+"'");return c[e]},SceneJS.RegionMap.prototype._getOption=function(a,b){return void 0==a?b:a},SceneJS.RegionMap.prototype.setSrc=function(a){this._core.image=null,this._core.src=a,this._core.target=null,this._loadTexture(a)},SceneJS.RegionMap.prototype.setImage=function(a){this._core.image=a,this._core.src=null,this._core.target=null,this._setTextureImage(a)},SceneJS.RegionMap.prototype.setTarget=function(a){return"colorTarget"!=a.type&&"depthTarget"!=a.type?void console.log("Target node type not compatible: "+a.type):(delete this._core.src,this._core.target=a,this._core.src=null,this._core.image=null,this._core.texture=a._core.renderBuf.getTexture(),this._core.texture.bufType=a._core.bufType,void(this._engine.display.imageDirty=!0))},SceneJS.RegionMap.prototype.setRegionColor=function(b){var c=a.regionColor;return this._core.regionColor=b?[void 0!=b.r&&null!=b.r?b.r:c[0],void 0!=b.g&&null!=b.g?b.g:c[1],void 0!=b.b&&null!=b.b?b.b:c[2]]:a.regionColor,this._engine.display.imageDirty=!0,this},SceneJS.RegionMap.prototype.setHighlightFactor=function(b){var c=a.highlightFactor;return this._core.highlightFactor=b?[void 0!=b.r&&null!=b.r?b.r:c[0],void 0!=b.g&&null!=b.g?b.g:c[1],void 0!=b.b&&null!=b.b?b.b:c[2]]:a.highlightFactor,this._engine.display.imageDirty=!0,this},SceneJS.RegionMap.prototype.setHideAlpha=function(b){return this._core.hideAlpha=void 0!=b?b:a.hideAlpha,this._engine.display.imageDirty=!0,this},SceneJS.RegionMap.prototype.setMode=function(b){return this._core.mode=b&&c[b]?b:a.mode,this._engine.branchDirty(this),this._engine.display.imageDirty=!0,this._core.hash="reg-"+b,this},SceneJS.RegionMap.prototype.setRegionData=function(b){return this._core.regionData=b?b:a.regionData,this},SceneJS.RegionMap.prototype._compile=function(a){var b=this._engine.display.regionMap;this._engine.display.regionMap=this._core,this._compileNodes(a),this._engine.display.regionMap=b},SceneJS.RegionMap.prototype._destroy=function(){1==this._core.useCount&&this._core.texture&&!this._core.target&&(this._core.texture.destroy(),this._core.texture=null)}},SceneJS.XForm=SceneJS_NodeFactory.createNodeType("xform"),SceneJS.XForm.prototype._init=function(a){1==this._core.useCount&&(SceneJS_modelXFormStack.buildCore(this._core),this.setElements(a.elements),this.xformParent=null,this.xformChildren=[])},SceneJS.XForm.prototype.getModelMatrix=function(){return this._core.dirty&&this._core.build(),this._core.matrix},SceneJS.XForm.prototype.getWorldMatrix=function(){return this._core.dirty&&this._core.build(),Array.apply([],this._core.mat)},SceneJS.XForm.prototype.setElements=function(a){if(a=a||SceneJS_math_identityMat4(),16!=a.length)throw SceneJS_error.fatalError(SceneJS.errors.ILLEGAL_NODE_CONFIG,"SceneJS.XForm elements should number 16");var b=this._core;if(b.matrix)for(var c=0;c<16;c++)b.matrix[c]=a[c];else b.matrix=a;return b.setDirty(),this._engine.display.imageDirty=!0,this},SceneJS.XForm.prototype._compile=function(a){var b,c,d=this._core;for(d.numCores=0,b=0,c=this.xformChildren.length;b0?a.display.modelTransform=f[g-1]:a.display.modelTransform=e,h=!1)}),this.buildCore=function(a){function b(a){a.dirty=!0,a.matrixDirty=!0;for(var c=0,d=a.numCores;c0?f[g-1]:e,f[g]=null,h=!0}};SceneJS.Types=new function(){this.addType=function(a,b){SceneJS_NodeFactory.createNodeType(a,b,function(a){var c;for(var d in b)if(b.hasOwnProperty(d))switch(c=b[d],d){case"init":case"construct":!function(){var c=b[d];a.prototype._init=function(a){c.call(this,a)},a.prototype._fromPlugin=!0}();break;case"destroy":case"destruct":a.prototype._destroy=c;break;default:a.prototype[d]=c}})},this.hasType=function(a){return!!SceneJS_NodeFactory.nodeTypes[a]}};var SceneJS_Display=function(a,b){this.stats=a||{},this._canvas=b.canvas,this._programFactory=new SceneJS_ProgramFactory(this.stats,{canvas:b.canvas}),this._chunkFactory=new SceneJS_ChunkFactory,this.transparent=b.transparent===!0,this.depthSort=b.depthSort===!0,this.enable=null,this.flags=null,this.layer=null,this.stage=null,this.renderer=null,this.depthBuffer=null,this.stencilBuffer=null,this.colorBuffer=null,this.view=null,this.lights=null,this.material=null,this.texture=null,this.fresnel=null,this.cubemap=null,this.modelTransform=null,this.viewTransform=null,this.projTransform=null,this.billboard=null,this.regionMap=null,this.renderTarget=null,this.clips=null,this.morphGeometry=null,this.name=null,this.tag=null,this.renderListeners=null,this.shader=null,this.shaderParams=null,this.style=null,this.geometry=null,this._objectFactory=new SceneJS_ObjectFactory,this._objects={},this._ambientColor=[0,0,0,1],this._objectList=[],this._objectListLen=0,this._objectPickList=[null],this._objectPickListLen=1,this._drawList=[],this._drawListLen=0,this._pickDrawList=[],this._pickDrawListLen=0,this._targetList=[],this._targetListLen=0,this._objectDrawList=[],this._objectDrawListLen=0,this._drawListTransparentIndex=-1,this._frameCtx={pickNames:[],regionData:[],canvas:this._canvas,VAO:null},this._frameCtx.renderListenerCtx=new SceneJS.RenderContext(this._frameCtx),this.objectListDirty=!0,this.stateOrderDirty=!0,this.stateSortDirty=!0,this.drawListDirty=!0,this.imageDirty=!0,this.bindOutputFrameBuffer=null,this.unbindOutputFrameBuffer=null};SceneJS_Display.prototype.webglRestored=function(){this._programFactory.webglRestored(),this._chunkFactory.webglRestored();var a=this._canvas.gl;this.pickBuf&&this.pickBuf.webglRestored(a),this.imageDirty=!0},SceneJS_Display.prototype.buildObject=function(a){var b=this._objects[a];b||(b=this._objects[a]=this._objectFactory.getObject(a),this.objectListDirty=!0),b.modelTransform=this.modelTransform,b.viewTransform=this.viewTransform,b.projTransform=this.projTransform,b.stage=this.stage,b.layer=this.layer,b.renderTarget=this.renderTarget,b.texture=this.texture,b.cubemap=this.cubemap,b.geometry=this.geometry,b.morphGeometry=this.morphGeometry,b.enable=this.enable,b.flags=this.flags,b.tag=this.tag,b.name=this.name;var c=[this.geometry.hash,this.shader.hash,this.clips.hash,this.morphGeometry.hash,this.texture.hash,this.fresnel.hash,this.cubemap.hash,this.lights.hash,this.flags.hash,this.regionMap.hash,this.billboard.hash].join(";");b.program&&c==b.hash||(b.program&&this._programFactory.putProgram(b.program),b.program=this._programFactory.getProgram(c,this),b.hash=c),this._setChunk(b,0,"program"),this._setChunk(b,1,"xform",this.modelTransform),this._setChunk(b,2,"lookAt",this.viewTransform),this._setChunk(b,3,"camera",this.projTransform),this._setChunk(b,4,"flags",this.flags),this._setChunk(b,5,"shader",this.shader),this._setChunk(b,6,"shaderParams",this.shaderParams),this._setChunk(b,7,"style",this.style),this._setChunk(b,8,"depthBuffer",this.depthBuffer),this._setChunk(b,9,"stencilBuffer",this.stencilBuffer),this._setChunk(b,10,"colorBuffer",this.colorBuffer),this._setChunk(b,11,"view",this.view),this._setChunk(b,12,"lights",this.lights),this._setChunk(b,13,"material",this.material),this._setChunk(b,14,"texture",this.texture),this._setChunk(b,15,"regionMap",this.regionMap),this._setChunk(b,16,"fresnel",this.fresnel),this._setChunk(b,17,"cubemap",this.cubemap),this._setChunk(b,18,"clips",this.clips),this._setChunk(b,19,"renderer",this.renderer),this._setChunk(b,20,"geometry",this.morphGeometry,this.geometry),this._setChunk(b,21,"listeners",this.renderListeners),this._setChunk(b,22,"draw",this.geometry),this.stateOrderDirty=!0},SceneJS_Display.prototype._setChunk=function(a,b,c,d,e){var f,g=this._chunkFactory.chunkTypes[c];if(d){if(d.empty){var h=a.chunks[b];return h&&this._chunkFactory.putChunk(h),void(a.chunks[b]=null)}f=g.prototype.programGlobal?"_"+d.stateId:"p"+a.program.id+"_"+d.stateId,e&&(f+="__"+e.stateId)}else f="p"+a.program.id;f=b+"__"+f;var h=a.chunks[b];if(h){if(h.id==f)return;this._chunkFactory.putChunk(h)}a.chunks[b]=this._chunkFactory.getChunk(f,c,a.program,d,e),"lights"==c&&this._setAmbient(d)},SceneJS_Display.prototype._setAmbient=function(a){for(var b,c=a.lights,d=0,e=c.length;dthis._objectListLen)for(i=this._objectListLen;ithis._drawListLen)for(a=this._drawListLen;athis._pickDrawListLen)for(a=this._pickDrawListLen;athis._objectDrawListLen)for(a=this._objectDrawListLen;athis._objectPickListLen)for(a=this._objectPickListLen;a0&&ia[0].positions)this._lerpTargets(ha.keys,ha.targets,"positions",aa,ba,ca,ha.factor,e,f,g);else{var ja=$.arrays.positions;e[0]=ja[da],e[1]=ja[da+1],e[2]=ja[da+2],f[0]=ja[ea],f[1]=ja[ea+1],f[2]=ja[ea+2],g[0]=ja[fa],g[1]=ja[fa+1],g[2]=ja[fa+2]}var ka=H.position=SceneJS_math_rayPlaneIntersect(a,b,e,f,g,SceneJS_math_vec3());n.set(ka),n[3]=1,SceneJS_math_transformVector4(D.modelTransform.mat,n,o),H.worldPos=SceneJS._sliceArray(o,0,3);var la=H.barycentric=SceneJS_math_cartesianToBarycentric2(ka,e,f,g,SceneJS_math_vec3()),ma=!1;if(ia&&ia.length>0&&ia[0].normals&&(this._lerpTargets(ha.keys,ha.targets,"normals",aa,ba,ca,ha.factor,h,i,j),ma=!0),!ma){var na=$.arrays.normals;na&&(h[0]=na[da],h[1]=na[da+1],h[2]=na[da+2],i[0]=na[ea],i[1]=na[ea+1],i[2]=na[ea+2],j[0]=na[fa],j[1]=na[fa+1],j[2]=na[fa+2],ma=!0)}ma&&(H.normal=SceneJS_math_addVec3(SceneJS_math_addVec3(SceneJS_math_mulVec3Scalar(h,la[0],p),SceneJS_math_mulVec3Scalar(i,la[1],q),r),SceneJS_math_mulVec3Scalar(j,la[2],s),SceneJS_math_vec3()));var oa=$.arrays.uvs;if(oa&&oa.length>0){H.uvs=[];var pa,qa,ra=2*aa,sa=2*ba,ta=2*ca;for(E=0,F=oa.length;E0&&(H.uv=H.uvs[0])}}}return G.unbind(),H},SceneJS_Display.prototype._lerpTargets=function(a,b,c,d,e,f,g,h,i,j){for(var k=0;k=0?this._drawListTransparentIndex:this._drawListLen,f=0;f 0.0) { discard; }"),m("}")}return m(" if (SCENEJS_uPickMode == 0.0) {"),m(" gl_FragColor = SCENEJS_uPickColor; "),m(" } else if (SCENEJS_uPickMode == 1.0) {"),m(" gl_FragColor = SCENEJS_vColor; "),m(" } else {"),m(G?" gl_FragColor = texture2D(SCENEJS_uRegionMapSampler, vec2(SCENEJS_vRegionMapUV.s, 1.0 - SCENEJS_vRegionMapUV.t));":" gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);"),m(" }"),m("}"),n()}function c(){return!p.regionMap.empty&&e()}function d(){return!!(p.texture.layers&&p.texture.layers.length>0)&&e()}function e(){return!!p.geometry.uvBufs||!(!p.morphGeometry.targets||!p.morphGeometry.targets[0].uvBuf&&!p.morphGeometry.targets[0].uvBuf2)}function f(a){return a.flags.reflective&&a.cubemap.layers&&a.cubemap.layers.length>0&&a.geometry.normalBuf}function g(a){return!!a.geometry.normalBuf||!(!a.morphGeometry.targets||!a.morphGeometry.targets[0].normalBuf)}function h(a){if(a.texture){var b=a.texture.layers;if(!b)return!1;for(var c=0,d=b.length;c 0.0) { discard; }"),m("}")}z&&(m("vec3 worldEyeVec = normalize(SCENEJS_uWorldEye - SCENEJS_vWorldVertex.xyz);"),w&&m("vec3 worldNormal = normalize(SCENEJS_vWorldNormal); "),A&&(m(" if (gl_FrontFacing == false) {"),m(" gl_FragColor = vec4(SCENEJS_uSolidColor.xyz, 1.0);"),m(" return;"),m(" }"))),m(" vec3 ambient= SCENEJS_uAmbientColor;"),c.viewPos&&m(c.viewPos+"(SCENEJS_vViewVertex);"),z&&c.viewNormal&&m(c.viewNormal+"(SCENEJS_vViewNormal);"),p.geometry.colorBuf?(m(" vec3 color = SCENEJS_vColor.rgb;"),m(" float colorA = SCENEJS_vColor.a;")):m(" vec3 color = SCENEJS_uMaterialColor;"),m(" float alpha = SCENEJS_uMaterialAlpha;"),m(" float emit = SCENEJS_uMaterialEmit;"),m(" float specular = SCENEJS_uMaterialSpecular;"),m(" vec3 specularColor = SCENEJS_uMaterialSpecularColor;"),m(" vec3 emitColor = SCENEJS_uMaterialEmitColor;"),m(" float shine = SCENEJS_uMaterialShine;"),c.materialBaseColor&&m("color="+c.materialBaseColor+"(color);"),c.materialAlpha&&m("alpha="+c.materialAlpha+"(alpha);"),c.materialEmit&&m("emit="+c.materialEmit+"(emit);"),c.materialSpecular&&m("specular="+c.materialSpecular+"(specular);"),c.materialSpecularColor&&m("specularColor="+c.materialSpecularColor+"(specularColor);"),c.materialShine&&m("shine="+c.materialShine+"(shine);"),z&&(m(" float attenuation = 1.0;"),m(D?" vec3 viewNormalVec = vec3(0.0, 1.0, 0.0);":" vec3 viewNormalVec = normalize(SCENEJS_vViewNormal);"),m("vec3 viewEyeVec = normalize(SCENEJS_vViewEyeVec);"));var r;if(x&&(m(" vec4 texturePos;"),m(" vec2 textureCoord=vec2(0.0,0.0);"),x))for(var j=0,q=p.texture.layers.length;j tolerance) {"),m(" fragColor.a = SCENEJS_uRegionMapHideAlpha;"),m("}"))),c.pixelColor&&m("fragColor="+c.pixelColor+"(fragColor);"),I&&(m(" if (SCENEJS_uDepthMode) {"),m(" float depth = length(SCENEJS_vViewVertex) / (SCENEJS_uZFar - SCENEJS_uZNear);"),m(" const vec4 bias = vec4(1.0 / 255.0,"),m(" 1.0 / 255.0,"),m(" 1.0 / 255.0,"),m(" 0.0);"),m(" float r = depth;"),m(" float g = fract(r * 255.0);"),m(" float b = fract(g * 255.0);"),m(" float a = fract(b * 255.0);"),m(" vec4 colour = vec4(r, g, b, a);"),m(" fragColor = colour - (colour.yzww * bias);"),m(" }")),i&&(m("float fragmentFresnel = fresnel(worldEyeVec, worldNormal, SCENEJS_uFragmentFresnelEdgeBias, SCENEJS_uFragmentFresnelCenterBias, SCENEJS_uFragmentFresnelPower);"),m("fragColor.rgb *= mix(SCENEJS_uFragmentFresnelEdgeColor.rgb, SCENEJS_uFragmentFresnelCenterColor.rgb, fragmentFresnel);")),I||m("fragColor.rgb *= fragColor.a;"),m("gl_FragColor = fragColor;"),m("}"),n()}function l(){L=[]}function m(a){L.push(a||"")}function n(){return L}function o(a){return a.getShaderPrecisionFormat?a.getShaderPrecisionFormat(a.FRAGMENT_SHADER,a.HIGH_FLOAT).precision>0?"highp":a.getShaderPrecisionFormat(a.FRAGMENT_SHADER,a.MEDIUM_FLOAT).precision>0?"mediump":"lowp":"mediump"}var p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I,J,K={},L="";this.getSource=function(e,l){var m=K[e];return m?(m.useCount++,m):(p=l,q=p.fresnel.diffuse,r=p.fresnel.specular,s=p.fresnel.alpha,t=p.fresnel.reflect,u=p.fresnel.emit,v=p.fresnel.fragment,w=q||r||s||t||u||v,x=d(p),y=f(p),z=g(p),A=p.flags.solid,B=p.flags.skybox,C=!p.billboard.empty,D=h(p),E=p.clips.clips.length>0,F=!!p.morphGeometry.targets,G=c(),H=G&&"info"!==p.regionMap.mode,I=i(),J="points"===p.geometry.primitiveName,m=new SceneJS_ProgramSource(e,a(p),b(p),j(p),k(p)),K[e]=m,m)},this.putSource=function(a){var b=K[a];b&&0==--b.useCount&&(K[b.hash]=null)}},SceneJS_ProgramSource=function(a,b,c,d,e){this.hash=a,this.pickVertexSrc=b,this.pickFragmentSrc=c,this.drawVertexSrc=d,this.drawFragmentSrc=e,this.useCount=0},SceneJS_ProgramFactory=function(a,b){this.stats=a,this._canvas=b.canvas,this._programs={},this._nextProgramId=0};SceneJS_ProgramFactory.prototype.getProgram=function(a,b){var c=this._programs[a];if(!c){var d=SceneJS_ProgramSourceFactory.getSource(a,b);c=new SceneJS_Program(this.stats,this._nextProgramId++,a,d,this._canvas.gl),this._programs[a]=c,this.stats.memory.programs++}return c.useCount++,c},SceneJS_ProgramFactory.prototype.putProgram=function(a){--a.useCount<=0&&(a.draw.destroy(),a.pick.destroy(),SceneJS_ProgramSourceFactory.putSource(a.hash),delete this._programs[a.hash],this.stats.memory.programs--)},SceneJS_ProgramFactory.prototype.webglRestored=function(){var a,b=this._canvas.gl;for(var c in this._programs)this._programs.hasOwnProperty(c)&&(a=this._programs[c],a&&a.build&&a.build(b))},SceneJS_ProgramFactory.prototype.destroy=function(){};var SceneJS_Program=function(a,b,c,d,e){this.stats=a,this.id=b,this.hash=d.hash,this.source=d,this.gl=e,this.draw=null,this.pick=null,this.useCount=0,this.build(e)};SceneJS_Program.prototype.build=function(a){this.gl=a,this.draw=new SceneJS._webgl.Program(this.stats,a,[this.source.drawVertexSrc.join("\n")],[this.source.drawFragmentSrc.join("\n")]),this.pick=new SceneJS._webgl.Program(this.stats,a,[this.source.pickVertexSrc.join("\n")],[this.source.pickFragmentSrc.join("\n")])};var SceneJS_ObjectFactory=function(){};SceneJS_ObjectFactory.prototype._freeObjects=[],SceneJS_ObjectFactory.prototype._numFreeObjects=0,SceneJS_ObjectFactory.prototype.getObject=function(a){var b;return this._numFreeObjects>0?(b=this._freeObjects[--this._numFreeObjects],b.id=a,b):new SceneJS_Object(a)},SceneJS_ObjectFactory.prototype.putObject=function(a){};var SceneJS_Object=function(a){this.id=a,this.hash=null,this.sortKey1=null,this.sortKey2=null,this.chunks=[],this.chunksLen=0,this.program=null,this.layer=null,this.texture=null,this.flags=null,this.tag=null,this.centroid=null};!function(){var a=new SceneJS_math_vec4;SceneJS_Object.prototype.getDepth=function(){this.centroid||(this.centroid=this._calculateCentroid(this));var b=this.modelTransform.mat,c=this.viewTransform.mat,d=SceneJS_math_transformVector4(b,this.centroid,a);return SceneJS_math_transformVector4(c,d,d),-d[2]},SceneJS_Object.prototype._calculateCentroid=function(){for(var a=SceneJS_math_vec4(),b=this.geometry.arrays.positions,c=this.geometry.arrays.indices,d=1/0,e=1/0,f=1/0,g=-(1/0),h=-(1/0),i=-(1/0),j=Math.min,k=Math.max,l=0,m=c.length;l>24&255,e=a.pickIndex>>16&255,f=a.pickIndex>>8&255,g=255&a.pickIndex;a.pickIndex++,this._uPickColor.setValue([g/255,f/255,e/255,d/255])}b.indexBuf?c.drawElements(b.primitive,b.indexBuf.numItems,b.indexBuf.itemType,0):c.drawArrays(b.primitive,0,b.vertexBuf.numItems/3)}else if(a.pickTriangle){var h=b.getPickPositions();h&&c.drawArrays(b.primitive,0,h.numItems/3)}}}),SceneJS_ChunkFactory.createChunkType({type:"flags",build:function(){var a=this.program.draw;this._uClippingDraw=a.getUniform("SCENEJS_uClipping"),this._uSolidDraw=a.getUniform("SCENEJS_uSolid"),this._uSolidColorDraw=a.getUniform("SCENEJS_uSolidColor");var b=this.program.pick;this._uClippingPick=b.getUniform("SCENEJS_uClipping")},drawAndPick:function(a){var b=this.program.gl,c=this.core.backfaces;a.backfaces!=c&&(c?b.disable(b.CULL_FACE):b.enable(b.CULL_FACE),a.backfaces=c);var d=this.core.frontface;a.frontface!=d&&("ccw"==d?b.frontFace(b.CCW):b.frontFace(b.CW),a.frontface=d);var e=a.picking;if(e)this._uClippingPick&&this._uClippingPick.setValue(this.core.clipping);else{var f=this.core.transparent;a.transparent!=f&&(f?(b.enable(b.BLEND),b.blendFunc(b.ONE,b.ONE_MINUS_SRC_ALPHA),a.blendEnabled=!0):(b.disable(b.BLEND),a.blendEnabled=!1),a.transparent=f),this._uClippingDraw&&this._uClippingDraw.setValue(this.core.clipping),this._uSolidDraw&&this._uSolidDraw.setValue(this.core.solid),this._uSolidColorDraw&&this._uSolidColorDraw.setValue(this.core.solidColor),this.core.clearColorBuffer&&b.clear(b.COLOR_BUFFER_BIT)}}}),SceneJS_ChunkFactory.createChunkType({type:"renderTarget",programGlobal:!0,draw:function(a){var b=this.program.gl;a.renderBuf&&(b.flush(),a.renderBuf.unbind(),a.renderBuf=null);var c=this.core.renderBuf;return c?(c.bind(),a.depthMode="depth"===this.core.bufType,a.depthMode||a.blendEnabled&&(b.enable(b.BLEND),b.blendFunc(b.ONE,b.ONE_MINUS_SRC_ALPHA)),b.viewport(0,0,b.drawingBufferWidth,b.drawingBufferHeight),b.clearColor(a.ambientColor[0],a.ambientColor[1],a.ambientColor[2],1),b.clear(b.COLOR_BUFFER_BIT|b.DEPTH_BUFFER_BIT),void(a.renderBuf=c)):void(a.depthMode=!1)}}),SceneJS_ChunkFactory.createChunkType({type:"geometry",build:function(){var a=this.program.draw;this._aRegionMapUVDraw=a.getAttribute("SCENEJS_aRegionMapUV"),this._aVertexDraw=a.getAttribute("SCENEJS_aVertex"),this._aNormalDraw=a.getAttribute("SCENEJS_aNormal"),this._aUVDraw=[];for(var b,c=0;c<1e3&&(b=a.getAttribute("SCENEJS_aUVCoord"+c),b);c++)this._aUVDraw.push(b);this._aTangentDraw=a.getAttribute("SCENEJS_aTangent"),this._aColorDraw=a.getAttribute("SCENEJS_aVertexColor"),this._aMorphVertexDraw=a.getAttribute("SCENEJS_aMorphVertex"),this._aMorphNormalDraw=a.getAttribute("SCENEJS_aMorphNormal"),this._aMorphTangentDraw=a.getAttribute("SCENEJS_aMorphTangent"),this._uMorphFactorDraw=a.getUniform("SCENEJS_uMorphFactor"),this._uPointSizeDraw=a.getUniform("SCENEJS_uPointSize");var d=this.program.pick;this._aRegionMapUVPick=d.getAttribute("SCENEJS_aRegionMapUV"),this._aVertexPick=d.getAttribute("SCENEJS_aVertex"),this._aColorPick=d.getAttribute("SCENEJS_aColor"),this._aMorphVertexPick=d.getAttribute("SCENEJS_aMorphVertex"),this._uMorphFactorPick=d.getUniform("SCENEJS_uMorphFactor"),this._uPointSizePick=a.getUniform("SCENEJS_uPointSize"),this.VAO=null,this.VAOMorphKey1=0,this.VAOMorphKey2=0,this.VAOHasInterleavedBuf=!1},recycle:function(){if(this.VAO){var a=this.program.gl.getExtension("OES_vertex_array_object");a.deleteVertexArrayOES(this.VAO),this.VAO=null}},morphDraw:function(a){this.VAOMorphKey1=this.core.key1,this.VAOMorphKey2=this.core.key2;var b=this.core.key1,c=this.core.key2,d=this.core.targets[b],e=this.core.targets[c];if(this._aMorphVertexDraw?(this._aVertexDraw.bindFloatArrayBuffer(d.vertexBuf),this._aMorphVertexDraw.bindFloatArrayBuffer(e.vertexBuf),a.bindArray+=2):this._aVertexDraw&&(this._aVertexDraw.bindFloatArrayBuffer(this.core2.vertexBuf),a.bindArray++),this._aMorphNormalDraw?(this._aNormalDraw.bindFloatArrayBuffer(d.normalBuf),this._aMorphNormalDraw.bindFloatArrayBuffer(e.normalBuf),a.bindArray+=2):this._aNormalDraw&&(this._aNormalDraw.bindFloatArrayBuffer(this.core2.normalBuf),a.bindArray++),this._aMorphTangentDraw||this._aTangentDraw){var f=a.normalMapUVLayerIdx;f>=0&&(this._aMorphTangentDraw?(this._aTangentDraw.bindFloatArrayBuffer(this.core.getTangents(b,this.core2.arrays.indices,this.core2.arrays.uvs[f])),this._aMorphTangentDraw.bindFloatArrayBuffer(this.core.getTangents(c,this.core2.arrays.indices,this.core2.arrays.uvs[f])),a.bindArray+=2):this._aTangentDraw)}for(var g,h=0,i=this._aUVDraw.length;h=0&&(this._aTangentDraw.bindFloatArrayBuffer(this.core2.getTangents(g)),a.bindArray++)}}if(this._aRegionMapUVDraw){var h=a.regionMapUVLayerIdx;if(h>=0){var i=this.core2.uvBufs;h=0;d--)if(b[d](c)===!0)return!0}}),SceneJS_ChunkFactory.createChunkType({type:"lookAt",build:function(){this._uvMatrixDraw=this.program.draw.getUniform("SCENEJS_uVMatrix"),this._uVNMatrixDraw=this.program.draw.getUniform("SCENEJS_uVNMatrix"),this._uWorldEyeDraw=this.program.draw.getUniform("SCENEJS_uWorldEye"),this._uWorldLookDraw=this.program.draw.getUniform("SCENEJS_uWorldLook"),this._uvMatrixPick=this.program.pick.getUniform("SCENEJS_uVMatrix")},draw:function(a){this.core.dirty&&this.core.rebuild();this.program.gl;this._uvMatrixDraw&&this._uvMatrixDraw.setValue(this.core.mat),this._uVNMatrixDraw&&this._uVNMatrixDraw.setValue(this.core.normalMat),this._uWorldEyeDraw&&this._uWorldEyeDraw.setValue(this.core.lookAt.eye),this._uWorldLookDraw&&this._uWorldLookDraw.setValue(this.core.lookAt.look),a.viewMat=this.core.mat},pick:function(a){this._uvMatrixPick&&this._uvMatrixPick.setValue(a.pickViewMatrix||this.core.mat),a.viewMat=this.core.mat}}),SceneJS_ChunkFactory.createChunkType({type:"material",build:function(){var a=this.program.draw;this._uMaterialBaseColor=a.getUniform("SCENEJS_uMaterialColor"),this._uMaterialSpecularColor=a.getUniform("SCENEJS_uMaterialSpecularColor"),this._uMaterialEmitColor=a.getUniform("SCENEJS_uMaterialEmitColor"),this._uMaterialSpecular=a.getUniform("SCENEJS_uMaterialSpecular"),this._uMaterialShine=a.getUniform("SCENEJS_uMaterialShine"),this._uMaterialEmit=a.getUniform("SCENEJS_uMaterialEmit"),this._uMaterialAlpha=a.getUniform("SCENEJS_uMaterialAlpha")},draw:function(){this.program.gl;this._uMaterialBaseColor&&this._uMaterialBaseColor.setValue(this.core.baseColor),this._uMaterialSpecularColor&&this._uMaterialSpecularColor.setValue(this.core.specularColor),this._uMaterialEmitColor&&this._uMaterialEmitColor.setValue(this.core.emitColor),this._uMaterialSpecular&&this._uMaterialSpecular.setValue(this.core.specular),this._uMaterialShine&&this._uMaterialShine.setValue(this.core.shine),this._uMaterialEmit&&this._uMaterialEmit.setValue(this.core.emit),this._uMaterialAlpha&&this._uMaterialAlpha.setValue(this.core.alpha)}}),SceneJS_ChunkFactory.createChunkType({type:"program",build:function(){this._depthModeDraw=this.program.draw.getUniform("SCENEJS_uDepthMode"),this._pickMode=this.program.pick.getUniform("SCENEJS_uPickMode")},draw:function(a){var b=this.program.draw;b.bind(),a.textureUnit=0;var c=this.program.gl;if(this._depthModeDraw&&this._depthModeDraw.setValue(a.depthMode),!a.VAO)for(var d=0;d<10;d++)c.disableVertexAttribArray(d);a.drawProgram=this.program.draw,a.useProgram++},pick:function(a){var b=this.program.pick;b.bind();var c=this.program.gl;a.pickObject?this._pickMode.setValue(0):a.pickTriangle?this._pickMode.setValue(1):this._pickMode.setValue(2),a.textureUnit=0;for(var d=0;d<10;d++)c.disableVertexAttribArray(d)}}),SceneJS_ChunkFactory.createChunkType({type:"renderer",build:function(){},drawAndPick:function(a){if(this.core.props){var b=this.program.gl;a.renderer&&(a.renderer.props.restoreProps(b),a.renderer=this.core),this.core.props.setProps(b)}}}),SceneJS_ChunkFactory.createChunkType({type:"regionMap",build:function(){this._uRegionMapRegionColor=this.program.draw.getUniform("SCENEJS_uRegionMapRegionColor"),this._uRegionMapHighlightFactor=this.program.draw.getUniform("SCENEJS_uRegionMapHighlightFactor"),this._uRegionMapHideAlpha=this.program.draw.getUniform("SCENEJS_uRegionMapHideAlpha"),this._uRegionMapSampler="SCENEJS_uRegionMapSampler"},draw:function(a){var b=this.core.texture;b&&(this.program.draw.bindTexture(this._uRegionMapSampler,b,a.textureUnit),a.textureUnit=(a.textureUnit+1)%SceneJS.WEBGL_INFO.MAX_TEXTURE_UNITS);var c=this.program.gl,d="hide"===this.core.mode||"isolate"===this.core.mode;a.transparent!=d&&(d?(c.enable(c.BLEND),c.blendFunc(c.ONE,c.ONE_MINUS_SRC_ALPHA),a.blendEnabled=!0):(c.disable(c.BLEND),a.blendEnabled=!1),a.transparent=d),b?(this._uRegionMapRegionColor&&this._uRegionMapRegionColor.setValue(this.core.regionColor),this._uRegionMapHighlightFactor&&this._uRegionMapHighlightFactor.setValue(this.core.highlightFactor),this._uRegionMapHideAlpha&&this._uRegionMapHideAlpha.setValue(this.core.hideAlpha),a.regionMapUVLayerIdx=this.core.uvLayerIdx):a.regionMapUVLayerIdx=-1},pick:function(a){var b=this.core.texture;b?(a.regionData=this.core.regionData,a.textureUnit=0,this.program.pick.bindTexture(this._uRegionMapSampler,b,a.textureUnit),a.textureUnit=(a.textureUnit+1)%SceneJS.WEBGL_INFO.MAX_TEXTURE_UNITS,a.regionMapUVLayerIdx=this.core.uvLayerIdx):a.regionMapUVLayerIdx=-1}}),SceneJS_ChunkFactory.createChunkType({type:"depthBuffer",programGlobal:!0,drawAndPick:function(a){var b=this.program.gl,c=this.core.enabled;a.depthbufEnabled!=c&&(c?b.enable(b.DEPTH_TEST):b.disable(b.DEPTH_TEST),a.depthbufEnabled=c);var d=this.core.clearDepth;a.clearDepth!=d&&(b.clearDepth(d),a.clearDepth=d);var e=this.core.depthFunc;a.depthFunc!=e&&(b.depthFunc(e),a.depthFunc=e),this.core.clear&&b.clear(b.DEPTH_BUFFER_BIT)}}),SceneJS_ChunkFactory.createChunkType({type:"stencilBuffer",programGlobal:!0,drawAndPick:function(a){var b=this.program.gl,c=this.core.enabled;a.stencilbufEnabled!=c&&(c?b.enable(b.STENCIL_TEST):b.disable(b.STENCIL_TEST),a.stencilbufEnabled=c);var d=this.core.clearStencil;void 0!==d&&a.clearStencil!=d&&(b.clearStencil(d),a.clearStencil=d);var e=this.core.stencilFuncFuncFront,f=this.core.stencilFuncRefFront,g=this.core.stencilFuncMaskFront;e&&(a.stencilFuncFuncFront==e&&a.stencilFuncRefFront==f&&a.stencilFuncMaskFront==g||(b.stencilFuncSeparate(b.FRONT,e,f,g),a.stencilFuncFuncFront=e,a.stencilFuncRefFront=f,a.stencilFuncMaskFront=g));var h=this.core.stencilFuncFuncBack,i=this.core.stencilFuncRefBack,j=this.core.stencilFuncMaskBack;h&&(a.stencilFuncFuncBack==h&&a.stencilFuncRefBack==i&&a.stencilFuncMaskBack==j||(b.stencilFuncSeparate(b.BACK,h,i,j),a.stencilFuncFuncBack=h,a.stencilFuncRefBack=i,a.stencilFuncMaskBack=j));var k=this.core.stencilOpSfailFront,l=this.core.stencilOpDpfailFront,m=this.core.stencilOpDppassFront;k&&(a.stencilOpSfailFront==k&&a.stencilOpDpfailFront==l&&a.stencilOpDppassFront==m||(b.stencilOpSeparate(b.FRONT,k,l,m),a.stencilOpSfailFront=k,a.stencilOpDpfailFront=l,a.stencilOpDppassFront=m));var n=this.core.stencilOpSfailBack,o=this.core.stencilOpDpfailBack,p=this.core.stencilOpDppassBack;n&&(a.stencilOpSfailBack==n&&a.stencilOpDpfailBack==o&&a.stencilOpDppassBack==p||(b.stencilOpSeparate(b.BACK,n,o,p),a.stencilOpSfailBack=n,a.stencilOpDpfailBack=o,a.stencilOpDppassBack=p)),this.core.clear&&b.clear(b.STENCIL_BUFFER_BIT)}}),SceneJS_ChunkFactory.createChunkType({type:"colorBuffer",programGlobal:!0,build:function(){},drawAndPick:function(a){if(!a.transparent){var b=this.core.blendEnabled,c=this.program.gl;a.blendEnabled!=b&&(b?c.enable(c.BLEND):c.disable(c.BLEND),a.blendEnabled=b);var d=this.core.colorMask;c.colorMask(d.r,d.g,d.b,d.a)}}}),SceneJS_ChunkFactory.createChunkType({type:"view",programGlobal:!0,build:function(){},drawAndPick:function(a){var b=this.core.scissorTestEnabled;if(a.scissorTestEnabled!=b){var c=this.program.gl;b?c.enable(c.SCISSOR_TEST):c.disable(c.SCISSOR_TEST),a.scissorTestEnabled=b}}}),SceneJS_ChunkFactory.createChunkType({type:"shader",build:function(){},drawAndPick:function(a){var b=this.core.paramsStack;if(b)for(var c,d,e=a.picking?this.program.pick:this.program.draw,f=0,g=b.length;f