diff --git a/api/latest/scenejs.js b/api/latest/scenejs.js index 1120de80..2b211a91 100644 --- a/api/latest/scenejs.js +++ b/api/latest/scenejs.js @@ -18769,6 +18769,10 @@ var SceneJS_ProgramSourceFactory = new (function () { add("fragColor.rgb *= mix(SCENEJS_uFragmentFresnelEdgeColor.rgb, SCENEJS_uFragmentFresnelCenterColor.rgb, fragmentFresnel);"); } + if (!depthTargeting) { + add("fragColor.rgb *= fragColor.a;"); + } + add("gl_FragColor = fragColor;"); add("}"); @@ -19645,7 +19649,7 @@ SceneJS_ChunkFactory.createChunkType({ // Entering a transparency bin gl.enable(gl.BLEND); - gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA); + gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA); frameCtx.blendEnabled = true; } else { @@ -19711,7 +19715,7 @@ SceneJS_ChunkFactory.createChunkType({ // Enable blending for non-depth targets if (frameCtx.blendEnabled) { gl.enable(gl.BLEND); - gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA); + gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA); } } @@ -20359,7 +20363,7 @@ SceneJS_ChunkFactory.createChunkType({ // Entering a transparency bin gl.enable(gl.BLEND); - gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA); + gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA); frameCtx.blendEnabled = true; } else { diff --git a/api/latest/scenejs.min.js b/api/latest/scenejs.min.js index 8e360362..8451fecc 100644 --- a/api/latest/scenejs.min.js +++ b/api/latest/scenejs.min.js @@ -19,5 +19,5 @@ var c=this._listeners[a];if(!c)return null;for(var d=0;d0?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;f>e;e++)b=c[e],d.push(b.mode),b.specular&&d.push("s"),b.diffuse&&d.push("d"),d.push("world"==b.space?"w":"v");a.hash=d.join("")}else a.hash=""}var b={type:"lights",stateId:SceneJS._baseStateId++,hash:null,empty:!1,lights:[{mode:"ambient",color:[.7,.7,.8],diffuse:!0,specular:!1},{mode:"dir",color:[1,1,1],diffuse:!0,specular:!0,dir:[-.5,-.5,-1],space:"view"},{mode:"dir",color:[1,1,1],diffuse:!1,specular:!0,dir:[1,-.9,-.7],space:"view"}]};a(b);var c=[],d=0;SceneJS_events.addListener(SceneJS_events.SCENE_COMPILING,function(a){a.engine.display.lights=b,d=0}),SceneJS.Lights=SceneJS_NodeFactory.createNodeType("lights"),SceneJS.Lights.prototype._init=function(a){if(1==this._core.useCount){var b=a.lights;if(!b)throw SceneJS_error.fatalError(SceneJS.errors.NODE_CONFIG_EXPECTED,"lights node attribute missing : 'lights'");this._core.lights=this._core.lights||[];for(var c=0,d=b.length;d>c;c++)this._initLight(c,b[c])}},SceneJS.Lights.prototype._initLight=function(a,b){var c={};this._core.lights[a]=c;var d=b.mode||"dir";if("dir"!=d&&"point"!=d&&"ambient"!=d)throw SceneJS_error.fatalError(SceneJS.errors.ILLEGAL_NODE_CONFIG,"Light mode not supported - should be 'dir' or 'point' or 'ambient'");var e=b.pos,f=b.dir,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],c.mode=d,c.diffuse="ambient"==d?!0:void 0!=b.diffuse?b.diffuse:!0,c.specular="ambient"==d?!1:void 0!=b.specular?b.specular:!0,c.pos=b.pos?[e.x||0,e.y||0,e.z||0]:[0,0,0],c.dir=b.dir?[f.x||0,f.y||0,f.z||0]:[0,0,1],c.attenuation=[void 0!=b.constantAttenuation?b.constantAttenuation:0,b.linearAttenuation||0,b.quadraticAttenuation||0];var h=b.space;if(h){if("view"!=h&&"world"!=h)throw SceneJS_error.fatalError(SceneJS.errors.ILLEGAL_NODE_CONFIG,"lights node invalid value for property 'space': '"+h+"' - should be 'view' or 'world'")}else h="world";c.space=h,this._core.hash=null},SceneJS.Lights.prototype.setLights=function(a){var b;for(var c in a)if(a.hasOwnProperty(c)&&(void 0!=c||null!=c)){if(b=parseInt(c),0>b||b>=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?!0:void 0!=b.diffuse?b.diffuse:!0,c.specular="ambient"==f?!1:void 0!=b.specular?b.specular:!0,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.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.getMatrix=function(){return this._core.dirty&&this._core.rebuild(),this._core.matrix.slice(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(){var a={type:"morphGeometry",stateId:SceneJS._baseStateId++,hash:"",morph:null},b=[],c=0;SceneJS_events.addListener(SceneJS_events.SCENE_COMPILING,function(b){b.engine.display.morphGeometry=a,c=0}),SceneJS.MorphGeometry=SceneJS_NodeFactory.createNodeType("morphGeometry"),SceneJS.MorphGeometry.prototype._init=function(a){if(1==this._core.useCount){this._pickPositionsDirty=!0,this._buildNodeCore(a),this._core.webglRestored=function(){};var b=this;this._core.getPickPositions=function(a,c){return b._pickPositionsDirty&&b._buildPickPositions(c),b._core.targets[a].pickPositionsBuf},this._core.getTangents=function(a,c,d){var e=b._core,f=e.targets[a];if(f.tangentBuf)return f.tangentBuf;var g=f.positions;if(d=f.uv||d,g&&c&&d){var h=b._engine.canvas.gl,i=new Float32Array(SceneJS_math_buildTangents(g,c,d));f.tangents=i;var j=h.STATIC_DRAW;return f.tangentBuf=new SceneJS._webgl.ArrayBuffer(h,h.ARRAY_BUFFER,i,i.length,3,j),f.tangentBuf}},this.setFactor(a.factor)}this._core.factor=a.factor||0,this._core.clamp=!!a.clamp},SceneJS.MorphGeometry.prototype._buildNodeCore=function(a){var b=a.targets||[];if(b.length<2)throw SceneJS_error.fatalError(SceneJS.errors.ILLEGAL_NODE_CONFIG,"morphGeometry node should have at least two targets");var c=a.keys||[];if(c.length!=b.length)throw SceneJS_error.fatalError(SceneJS.errors.ILLEGAL_NODE_CONFIG,"morphGeometry node mismatch in number of keys and targets");var d=this._core,e=this._engine.canvas.gl,f=e.STATIC_DRAW;d.keys=c,d.targets=[],d.key1=0,d.key2=1;for(var g,h,i,j,k,l=0,m=b.length;m>l;l++)k=b[l],!g&&k.positions&&(g=k.positions),!h&&k.normals&&(h=k.normals),!i&&k.uv&&(i=k.uv),!j&&k.uv2&&(j=k.uv2);try{for(var n,o,l=0,m=b.length;m>l;l++)k=b[l],n={},o=k.positions||g,o&&(n.positions=o.constructor==Float32Array?o:new Float32Array(o),n.vertexBuf=new SceneJS._webgl.ArrayBuffer(e,e.ARRAY_BUFFER,n.positions,o.length,3,f),g=o),o=k.normals||h,o&&(n.normals=o.constructor==Float32Array?o:new Float32Array(o),n.normalBuf=new SceneJS._webgl.ArrayBuffer(e,e.ARRAY_BUFFER,n.normals,o.length,3,f),h=o),o=k.uv||i,o&&(n.uv=o.constructor==Float32Array?o:new Float32Array(o),n.uvBuf=new SceneJS._webgl.ArrayBuffer(e,e.ARRAY_BUFFER,n.uv,o.length,2,f),i=o),o=k.uv2||j,o&&(n.uv2=o.constructor==Float32Array?o:new Float32Array(o),n.uvBuf2=new SceneJS._webgl.ArrayBuffer(e,e.ARRAY_BUFFER,n.uv2,o.length,2,f),j=o),d.targets.push(n)}catch(p){for(var l=0,m=d.targets.length;m>l;l++)n=d.targets[l],n.vertexBuf&&n.vertexBuf.destroy(),n.normalBuf&&n.normalBuf.destroy(),n.uvBuf&&n.uvBuf.destroy(),n.uvBuf2&&n.uvBuf2.destroy();throw SceneJS_error.fatalError(SceneJS.errors.ERROR,"Failed to allocate VBO(s) for morphGeometry: "+p)}this._pickPositionsDirty=!0},SceneJS.MorphGeometry.prototype._buildPickPositions=function(a){for(var b,c=this._core,d=null,e=this._engine.canvas.gl,f=e.STATIC_DRAW,g=0,h=c.targets.length;h>g;g++)d=c.targets[g],d.positions&&(d.pickPositionsBuf&&(d.pickPositionsBuf.destroy(),d.pickPositionsBuf=null),b=SceneJS_math_getPickPositions(d.positions,a),d.pickPositionsBuf=new SceneJS._webgl.ArrayBuffer(e,e.ARRAY_BUFFER,new Float32Array(b),b.length,3,f));this._pickPositionsDirty=!1},SceneJS.MorphGeometry.prototype.setFactor=function(a){a=a||0;var b=this._core,c=b.keys,d=b.key1,e=b.key2,f=b.factor;if(ac[c.length-1])d=c.length-2,e=d+1;else{for(;c[d]>a;)d--,e--;for(;c[e]0?b[c-1]:a,b[c]=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;d>c;c++)a=b.targets[c],a.vertexBuf&&a.vertexBuf.destroy(),a.pickPositionsBuf&&a.pickPositionsBuf.destroy(),a.normalBuf&&a.normalBuf.destroy(),a.uvBuf&&a.uvBuf.destroy(),a.uvBuf2&&a.uvBuf2.destroy()}},function(){var a={type:"name",stateId:SceneJS._baseStateId++,name:null},b=[],c=0;SceneJS_events.addListener(SceneJS_events.SCENE_COMPILING,function(b){b.engine.display.name=a,c=0}),SceneJS.Name=SceneJS_NodeFactory.createNodeType("name"),SceneJS.Name.prototype._init=function(a){this.setName(a.name),this._core.nodeId=this.id},SceneJS.Name.prototype.setName=function(a){this._core.name=a||"unnamed",this._engine.branchDirty(this)},SceneJS.Name.prototype.getName=function(){return this._core.name},SceneJS.Name.prototype._compile=function(d){this._engine.display.name=b[c++]=this._core;for(var e,f=[],g=0;c>g;g++)e=b[g].name,e&&f.push(e);this._core.path=f.join("."),this._compileNodes(d),this._engine.display.name=--c>0?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={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:!0,g:void 0!=a.g&&null!=a.g?a.g:!0,b:void 0!=a.b&&null!=a.b?a.b:!0,a:void 0!=a.a&&null!=a.a?a.a:!0},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},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.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.renderFrame=function(a){return this._engine.renderFrame(a)},SceneJS.Scene.prototype.compile=function(a){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,b,c){var d=this._engine.pick(a,b,c);return this.renderFrame({force:!0}),d?(this.publish("pick",d),d):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.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;i>e;e++){b=a[e];for(c in b)b.hasOwnProperty(c)&&(d[c]=b[c])}return d}var b={type:"shader",stateId:SceneJS._baseStateId++,hash:"",empty:!0,shader:{}},c=[],d=[],e=[],f=[],g=[],h=[],i=0,j=!0;SceneJS_events.addListener(SceneJS_events.SCENE_COMPILING,function(a){a.engine.display.shader=b,i=0,j=!0}),SceneJS_events.addListener(SceneJS_events.OBJECT_COMPILING,function(k){if(j){if(i>0){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;d>c;c++){if(b=a[c],!b.stage)throw SceneJS_error.fatalError(SceneJS.errors.ILLEGAL_NODE_CONFIG,"shader 'stage' attribute expected");var e;b.code&&(e=SceneJS._isArray(b.code)?b.code.join(""):b.code),this._core.shaders[b.stage]={code:e,hooks:b.hooks}}},SceneJS.Shader.prototype.setParams=function(a){a=a||{};var b=this._core.params;b||(b=this._core.params={});for(var c in a)a.hasOwnProperty(c)&&(b[c]=a[c]);this._engine.display.imageDirty=!0},SceneJS.Shader.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.Shader.prototype._compile=function(a){c[i]=this._core.coreId;var b=this._core.shaders,k=b.fragment||{},l=b.vertex||{};f[i]=k.code||"",g[i]=k.hooks||{},d[i]=l.code||"",e[i]=l.hooks||{},h[i]=this._core.params||{},i++,j=!0,this._compileNodes(a),i--,j=!0}},new function(){var a,b={type:"shaderParams",stateId:SceneJS._baseStateId++,empty:!0},c=[],d=[],e=0;SceneJS_events.addListener(SceneJS_events.SCENE_COMPILING,function(c){c.engine.display.shaderParams=b,e=0,a=!0}),SceneJS_events.addListener(SceneJS_events.OBJECT_COMPILING,function(f){if(a){if(e>0){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?!0: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;ec;c++)h._loadLayerTexture(b,a[c])}}},SceneJS.Texture.prototype._loadLayerTexture=function(a,b){var c=this,d=b.source;if(d){if(!d.type)throw SceneJS_error.fatalError(SceneJS.errors.ILLEGAL_NODE_CONFIG,"texture layer config expected: source.type");SceneJS.Plugins.getPlugin("texture",d.type,function(e){if(!e.getSource)throw SceneJS_error.fatalError(SceneJS.errors.PLUGIN_INVALID,"texture: 'getSource' method missing on plugin for texture source type '"+d.type+"'.");var f=e.getSource({gl:a});if(!f.subscribe)throw SceneJS_error.fatalError(SceneJS.errors.PLUGIN_INVALID,"texture: 'subscribe' method missing on plugin for texture source type '"+d.type+"'");var g=SceneJS_sceneStatusModule.taskStarted(c,"Loading texture");f.subscribe(function(){var d=!1;return function(e){d?c._engine.display.imageDirty=!0:(d=!0,c._setLayerTexture(a,b,e),SceneJS_sceneStatusModule.taskFinished(g))}}()),f.configure&&f.configure(d),b._source=f})}else{var e=b.uri||b.src,f=b.preloadURI||b.preloadSrc,g=b.preloadColor||{r:.57735,g:.57735,b:.57735};g.a=void 0===g.a?1:g.a,g=new Uint8Array([Math.floor(255*g.r),Math.floor(255*g.g),Math.floor(255*g.b),Math.floor(255*g.a)]);var h=SceneJS_sceneStatusModule.taskStarted(this,"Loading texture"),i=a.createTexture(),j=!1,k=!1;if(a.bindTexture(a.TEXTURE_2D,i),b.image)return c._setTextureImage(a,i,b.image),c._setLayerTexture(a,b,i),void SceneJS_sceneStatusModule.taskFinished(h);if(a.texImage2D(a.TEXTURE_2D,0,a.RGBA,1,1,0,a.RGBA,a.UNSIGNED_BYTE,g),c._setLayerTexture(a,b,i),f){var l=new Image;l.onload=function(){j||(c._setTextureImage(a,i,l),c._setLayerTexture(a,b,i),SceneJS_sceneStatusModule.taskFinished(h),k=!0)},c._fetchImage(l,f)}var m=new Image;m.onload=function(){c._setTextureImage(a,i,m),c._setLayerTexture(a,b,i),k||SceneJS_sceneStatusModule.taskFinished(h),b.image=m,j=!0,c.publish("image",m)},m.onerror=function(){SceneJS_sceneStatusModule.taskFailed(h)},c._fetchImage(m,e)}},SceneJS.Texture.prototype._fetchImage=function(a,b){0==b.indexOf("data")?a.src=b:(a.crossOrigin="Anonymous",a.src=b)},SceneJS.Texture.prototype._setTextureImage=function(a,b,c){a.bindTexture(a.TEXTURE_2D,b);var d=SceneJS_configsModule.configs.maxTextureSize;return d&&(c=SceneJS._webgl.clampImageSize(c,d)),a.texImage2D(a.TEXTURE_2D,0,a.RGBA,a.RGBA,a.UNSIGNED_BYTE,this._ensureImageSizePowerOfTwo(c)),this._engine.display.imageDirty=!0,c},SceneJS.Texture.prototype._ensureImageSizePowerOfTwo=function(a){if(!this._isPowerOfTwo(a.width)||!this._isPowerOfTwo(a.height)){var b=document.createElement("canvas");b.width=this._nextHighestPowerOfTwo(a.width),b.height=this._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,a.crossOrigin=""}return a},SceneJS.Texture.prototype._isPowerOfTwo=function(a){return 0==(a&a-1)},SceneJS.Texture.prototype._nextHighestPowerOfTwo=function(a){--a;for(var b=1;32>b;b<<=1)a|=a>>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),isDepth:this._getOption(b.isDepth,!1),depthMode:this._getGLOption("depthMode",a,b,a.LUMINANCE),depthCompareMode:this._getGLOption("depthCompareMode",a,b,a.COMPARE_R_TO_TEXTURE),depthCompareFunc:this._getGLOption("depthCompareFunc",a,b,a.LEQUAL),flipY:this._getOption(b.flipY,!0),width:this._getOption(b.width,1),height:this._getOption(b.height,1),internalFormat:this._getGLOption("internalFormat",a,b,a.LEQUAL),sourceFormat:this._getGLOption("sourceType",a,b,a.ALPHA),sourceType:this._getGLOption("sourceType",a,b,a.UNSIGNED_BYTE),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),0>b||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;g>f;f++)c=d[f],e.push("/"),e.push(c.applyFrom),e.push("/"),e.push(c.applyTo),e.push("/"),e.push(c.blendMode),c.matrix&&e.push("/anim");a=e.join("")}else a="";b.hash!=a&&(b.hash=a)},SceneJS.Texture.prototype._destroy=function(){if(1==this._core.useCount)for(var a,b,c=this._core.layers,d=0,e=c.length;e>d;d++)a=c[d],a.texture&&a.texture.destroy(),b=a._source,b&&b.destroy&&b.destroy()}},new function(){function a(){var a,b;(0!=this.translate.x||0!=this.translate.y)&&(a=SceneJS_math_translationMat4v([this.translate.x||0,this.translate.y||0,0])),(1!=this.scale.x||1!=this.scale.y)&&(b=SceneJS_math_scalingMat4v([this.scale.x||1,this.scale.y||1,1]),a=a?SceneJS_math_mulMat4(a,b):b),0!=this.rotate&&(b=SceneJS_math_rotationMat4v(.0174532925*this.rotate,[0,0,1]),a=a?SceneJS_math_mulMat4(a,b):b),a&&(this.matrix=a,this.matrixAsArray?this.matrixAsArray.set(this.matrix):this.matrixAsArray=new Float32Array(this.matrix)),this._matrixDirty=!1}var b={type:"texture",stateId:SceneJS._baseStateId++,empty:!0,hash:""};SceneJS_events.addListener(SceneJS_events.SCENE_COMPILING,function(a){a.engine.display.texture=b,d=0});var c=[],d=0;SceneJS.TextureMap=SceneJS_NodeFactory.createNodeType("texture"),SceneJS.TextureMap.prototype._init=function(b){var c=this;if(1==this._core.useCount){var d=b.applyFrom||"uv";if("uv"!==d.substring(0,2))throw SceneJS_error.fatalError(SceneJS.errors.NODE_CONFIG_EXPECTED,"texture applyFrom value is unsupported - should be 'uv'");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?!0:b.waitForLoad,texture:null,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}}},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),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.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;g>f;f++)c=d[f],e.push("/"),e.push(c.applyFrom),e.push("/"),e.push(c.applyTo),e.push("/"),e.push(c.blendMode),c.matrix&&e.push("/anim");b=e.join("")}else b="";a.hash!=b&&(a.hash=b)},SceneJS.TextureMap.prototype._destroy=function(){1==this._core.useCount&&this._core.texture&&!this._core.target&&(this._core.texture.destroy(),this._core.texture=null),this._core&&this._engine._coreFactory.putCore(this._core)}},new function(){var a={type:"fresnel",stateId:SceneJS._baseStateId++,centerBias:1,edgeBias:0,power:1,centerColor:[1,1,1],edgeColor:[0,0,0],empty:!0,hash:""};SceneJS_events.addListener(SceneJS_events.SCENE_COMPILING,function(b){b.engine.display.fresnel=a,c=0});var b=[],c=0;SceneJS.Fresnel=SceneJS_NodeFactory.createNodeType("fresnel"),SceneJS.Fresnel.prototype._init=function(a){if(1==this._core.useCount){if(a.applyTo&&"color"!=a.applyTo&&"specular"!=a.applyTo&&"alpha"!=a.applyTo&&"reflect"!=a.applyTo&&"emit"!=a.applyTo&&"fragment"!=a.applyTo)throw SceneJS_error.fatalError(SceneJS.errors.NODE_CONFIG_EXPECTED,"fresnel applyTo value is unsupported - should be either 'color', 'specular', 'alpha', 'reflect', 'emit' or 'fragment'");this._core.applyTo=a.applyTo,this.setCenterBias(a.centerBias),this.setEdgeBias(a.edgeBias),this.setPower(a.power),this.setCenterColor(a.centerColor),this.setEdgeColor(a.edgeColor)}},SceneJS.Fresnel.prototype.getApplyTo=function(){return this._core.applyTo},SceneJS.Fresnel.prototype.setCenterBias=function(b){this._core.centerBias=void 0!==b&&null!==b?b:a.centerBias,this._engine.display.imageDirty=!0},SceneJS.Fresnel.prototype.getCenterBias=function(){return this._core.centerBias},SceneJS.Fresnel.prototype.setEdgeBias=function(b){this._core.edgeBias=void 0!==b&&null!==b?b:a.edgeBias,this._engine.display.imageDirty=!0},SceneJS.Fresnel.prototype.getEdgeBias=function(){return this._core.edgeBias},SceneJS.Fresnel.prototype.setPower=function(b){this._core.power=void 0!==b&&null!==b?b:a.power,this._engine.display.imageDirty=!0},SceneJS.Fresnel.prototype.getPower=function(){return this._core.power},SceneJS.Fresnel.prototype.setCenterColor=function(b){var c=a.centerColor;return this._core.centerColor=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.centerColor,this._engine.display.imageDirty=!0,this},SceneJS.Fresnel.prototype.getCenterColor=function(){return{r:this._core.centerColor[0],g:this._core.centerColor[1],b:this._core.centerColor[2]}},SceneJS.Fresnel.prototype.setEdgeColor=function(b){var c=a.edgeColor;return this._core.edgeColor=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.edgeColor,this._engine.display.imageDirty=!0,this},SceneJS.Fresnel.prototype.getEdgeColor=function(){ return{r:this._core.edgeColor[0],g:this._core.edgeColor[1],b:this._core.edgeColor[2]}},SceneJS.Fresnel.prototype._compile=function(d){this.__core||(this.__core=this._engine._coreFactory.getCore("fresnel"));var e=this._engine.display.fresnel;this._core.empty||(this.__core.diffuse="color"==this._core.applyTo?this._core:e.diffuse,this.__core.specular="specular"==this._core.applyTo?this._core:e.specular,this.__core.alpha="alpha"==this._core.applyTo?this._core:e.alpha,this.__core.reflect="reflect"==this._core.applyTo?this._core:e.reflect,this.__core.emit="emit"==this._core.applyTo?this._core:e.emit,this.__core.fragment="fragment"==this._core.applyTo?this._core:e.fragment),this._makeHash(this.__core),b[c++]=this.__core,this._engine.display.fresnel=this.__core,this._compileNodes(d),this._engine.display.fresnel=--c>0?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;ii;i++)c.texImage2D(e[i],0,c.RGBA,c.RGBA,c.UNSIGNED_BYTE,SceneJS._webgl.ensureImageSizePowerOfTwo(f[i]));b._core.texture=new SceneJS._webgl.Texture2D(c,{texture:d,target:c.TEXTURE_CUBE_MAP,minFilter:c.LINEAR,magFilter:c.LINEAR,wrapS:c.CLAMP_TO_EDGE,wrapT:c.CLAMP_TO_EDGE}),SceneJS_sceneStatusModule.taskFinished(g),b._engine.display.imageDirty=!0}}}(),j.onerror=function(){h=!0,SceneJS_sceneStatusModule.taskFailed(g)},j.src=a.src[i]}}},SceneJS.Reflect.prototype._compile=function(d){this.__core||(this.__core=this._engine._coreFactory.getCore("cubemap"));var e=this._engine.display.cubemap;this._core.empty||(this.__core.layers=e&&e.layers?e.layers.concat([this._core]):[this._core]),this._makeHash(this.__core),b[c++]=this.__core,this._engine.display.cubemap=this.__core,this._compileNodes(d),this._engine.display.cubemap=--c>0?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;g>f;f++)c=d[f],e.push("/"),e.push(c.applyTo),e.push("/"),e.push(c.blendMode);b=e.join("")}else b="";a.hash!=b&&(a.hash=b)},SceneJS.Reflect.prototype._destroy=function(){1==this._core.useCount&&this._core.texture&&(this._core.texture.destroy(),this._core.texture=null),this._core&&this._engine._coreFactory.putCore(this._core)}}(),new function(){var a={type:"regionMap",stateId:SceneJS._baseStateId++,empty:!0,texture:null,regionColor:[-1,-1,-1],highlightFactor:[1.5,1.5,0],hideAlpha:0,regionData:[],mode:"info",hash:""};SceneJS_events.addListener(SceneJS_events.SCENE_COMPILING,function(c){c.engine.display.regionMap=a,b=0});var b=0,c={info:!0,highlight:!0,hide:!0,isolate:!0};SceneJS.RegionMap=SceneJS_NodeFactory.createNodeType("regionMap"),SceneJS.RegionMap.prototype._init=function(a){var b=this;if(1==this._core.useCount){SceneJS._apply({regionMap:null},this._core);var c=a.applyFrom||"uv";if("uv"!==c.substring(0,2))throw SceneJS_error.fatalError(SceneJS.errors.NODE_CONFIG_EXPECTED,"texture applyFrom value is unsupported - should be 'uv'");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))},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;16>c;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){SceneJS_modelXFormStack.push(this._core),this._compileNodes(a),SceneJS_modelXFormStack.pop()},SceneJS.Matrix=SceneJS_NodeFactory.createNodeType("matrix"),SceneJS.Matrix.prototype._init=function(a){1==this._core.useCount&&(SceneJS_modelXFormStack.buildCore(this._core),this.setElements(a.elements))},SceneJS.Matrix.prototype.getModelMatrix=function(){return this._core.dirty&&this._core.build(),this._core.matrix},SceneJS.Matrix.prototype.getWorldMatrix=function(){return this._core.dirty&&this._core.build(),Array.apply([],this._core.mat)},SceneJS.Matrix.prototype.setMatrix=function(a){if(a=a||SceneJS_math_identityMat4(),16!=a.length)throw SceneJS_error.fatalError(SceneJS.errors.ILLEGAL_NODE_CONFIG,"SceneJS.Matrix elements should number 16");var b=this._core;if(b.matrix)for(var c=0;16>c;c++)b.matrix[c]=a[c];else b.matrix=a;return b.setDirty(),this._engine.display.imageDirty=!0,this},SceneJS.Matrix.prototype.setElements=SceneJS.Matrix.prototype.setMatrix,SceneJS.Matrix.prototype._compile=function(a){SceneJS_modelXFormStack.push(this._core),this._compileNodes(a),SceneJS_modelXFormStack.pop()},SceneJS.Rotate=SceneJS_NodeFactory.createNodeType("rotate"),SceneJS.Rotate.prototype._init=function(a){if(1==this._core.useCount){SceneJS_modelXFormStack.buildCore(this._core),this.setMultOrder(a.multOrder),this.setAngle(a.angle),this.setXYZ({x:a.x,y:a.y,z:a.z});var b=this._core;this._core.buildMatrix=function(){b.matrix=SceneJS_math_rotationMat4v(b.angle*Math.PI/180,[b.x,b.y,b.z])}}},SceneJS.Rotate.prototype.getModelMatrix=function(){return this._core.dirty&&this._core.build(),this._core.matrix},SceneJS.Rotate.prototype.getWorldMatrix=function(){return this._core.dirty&&this._core.build(),Array.apply([],this._core.mat)},SceneJS.Rotate.prototype.setMultOrder=function(a){if(a=a||"post","post"!=a&&"pre"!=a)throw SceneJS_error.fatalError(SceneJS.errors.NODE_CONFIG_EXPECTED,"Illegal multOrder for rotate node - '"+a+"' should be 'pre' or 'post'");this._core.multOrder=a,this._core.setDirty(),this._engine.display.imageDirty=!0},SceneJS.Rotate.prototype.setAngle=function(a){this._core.angle=a||0,this._core.setDirty(),this._engine.display.imageDirty=!0},SceneJS.Rotate.prototype.getAngle=function(){return this._core.angle},SceneJS.Rotate.prototype.setXYZ=function(a){a=a||{},this._core.x=a.x||0,this._core.y=a.y||0,this._core.z=a.z||0,this._core.setDirty(),this._engine.display.imageDirty=!0},SceneJS.Rotate.prototype.getXYZ=function(){return{x:this._core.x,y:this._core.y,z:this._core.z}},SceneJS.Rotate.prototype.setX=function(a){this._core.x=a,this._core.setDirty(),this._engine.display.imageDirty=!0},SceneJS.Rotate.prototype.getX=function(){return this._core.x},SceneJS.Rotate.prototype.setY=function(a){this._core.y=a,this._core.setDirty(),this._engine.display.imageDirty=!0},SceneJS.Rotate.prototype.getY=function(){return this._core.y},SceneJS.Rotate.prototype.setZ=function(a){this._core.z=a,this._core.setDirty(),this._engine.display.imageDirty=!0},SceneJS.Rotate.prototype.getZ=function(){return this._core.z},SceneJS.Rotate.prototype.incAngle=function(a){this._core.angle+=a,this._core.setDirty(),this._engine.display.imageDirty=!0},SceneJS.Rotate.prototype._compile=function(a){SceneJS_modelXFormStack.push(this._core),this._compileNodes(a),SceneJS_modelXFormStack.pop()},SceneJS.Translate=SceneJS_NodeFactory.createNodeType("translate"),SceneJS.Translate.prototype._init=function(a){if(1==this._core.useCount){SceneJS_modelXFormStack.buildCore(this._core),this.setMultOrder(a.multOrder),this.setXYZ({x:a.x,y:a.y,z:a.z});var b=this._core;this._core.buildMatrix=function(){b.matrix=SceneJS_math_translationMat4v([b.x,b.y,b.z],b.matrix)}}},SceneJS.Translate.prototype.getModelMatrix=function(){return this._core.dirty&&this._core.build(),this._core.matrix},SceneJS.Translate.prototype.getWorldMatrix=function(){return this._core.dirty&&this._core.build(),Array.apply([],this._core.mat)},SceneJS.Translate.prototype.setMultOrder=function(a){if(a=a||"post","post"!=a&&"pre"!=a)throw SceneJS_error.fatalError(SceneJS.errors.NODE_CONFIG_EXPECTED,"Illegal multOrder for translate node - '"+a+"' should be 'pre' or 'post'");this._core.multOrder=a,this._core.setDirty(),this._engine.display.imageDirty=!0},SceneJS.Translate.prototype.setXYZ=function(a){return a=a||{},this._core.x=a.x||0,this._core.y=a.y||0,this._core.z=a.z||0,this._core.setDirty(),this._engine.display.imageDirty=!0,this},SceneJS.Translate.prototype.getXYZ=function(){return{x:this._core.x,y:this._core.y,z:this._core.z}},SceneJS.Translate.prototype.setX=function(a){return this._core.x=a,this._core.setDirty(),this._engine.display.imageDirty=!0,this},SceneJS.Translate.prototype.setY=function(a){return this._core.y=a,this._core.setDirty(),this._engine.display.imageDirty=!0,this},SceneJS.Translate.prototype.setZ=function(a){return this._core.z=a,this._core.setDirty(),this._engine.display.imageDirty=!0,this},SceneJS.Translate.prototype.incX=function(a){return this._core.x+=a,this._core.setDirty(),this._engine.display.imageDirty=!0,this},SceneJS.Translate.prototype.incY=function(a){return this._core.y+=a,this._core.setDirty(),this._engine.display.imageDirty=!0,this},SceneJS.Translate.prototype.incZ=function(a){return this._core.z+=a,this._core.setDirty(),this._engine.display.imageDirty=!0,this},SceneJS.Translate.prototype.getX=function(){return this._core.x},SceneJS.Translate.prototype.getY=function(){return this._core.y},SceneJS.Translate.prototype.getZ=function(){return this._core.z},SceneJS.Translate.prototype._compile=function(a){SceneJS_modelXFormStack.push(this._core),this._compileNodes(a),SceneJS_modelXFormStack.pop()},SceneJS.Scale=SceneJS_NodeFactory.createNodeType("scale"),SceneJS.Scale.prototype._init=function(a){if(1==this._core.useCount){SceneJS_modelXFormStack.buildCore(this._core),this.setMultOrder(a.multOrder),this.setXYZ({x:a.x,y:a.y,z:a.z});var b=this._core;this._core.buildMatrix=function(){b.matrix=SceneJS_math_scalingMat4v([b.x,b.y,b.z])}}},SceneJS.Scale.prototype.getModelMatrix=function(){return this._core.dirty&&this._core.build(),this._core.matrix},SceneJS.Scale.prototype.getWorldMatrix=function(){return this._core.dirty&&this._core.build(),Array.apply([],this._core.mat)},SceneJS.Scale.prototype.setMultOrder=function(a){if(a=a||"post","post"!=a&&"pre"!=a)throw SceneJS_error.fatalError(SceneJS.errors.NODE_CONFIG_EXPECTED,"Illegal multOrder for scale node - '"+a+"' should be 'pre' or 'post'");this._core.multOrder=a,this._core.setDirty(),this._engine.display.imageDirty=!0},SceneJS.Scale.prototype.setXYZ=function(a){a=a||{},this._core.x=void 0==a.x?1:a.x,this._core.y=void 0==a.y?1:a.y,this._core.z=void 0==a.z?1:a.z,this._core.setDirty(),this._engine.display.imageDirty=!0},SceneJS.Scale.prototype.getXYZ=function(){return{x:this._core.x,y:this._core.y,z:this._core.z}},SceneJS.Scale.prototype.setX=function(a){this._core.x=a,this._core.setDirty(),this._engine.display.imageDirty=!0},SceneJS.Scale.prototype.setY=function(a){this._core.y=a,this._core.setDirty(),this._engine.display.imageDirty=!0},SceneJS.Scale.prototype.setZ=function(a){this._core.z=a,this._core.setDirty(),this._engine.display.imageDirty=!0},SceneJS.Scale.prototype.getX=function(){return this._core.x},SceneJS.Scale.prototype.getY=function(){return this._core.y},SceneJS.Scale.prototype.getZ=function(){return this._core.z},SceneJS.Scale.prototype.incX=function(a){this._core.x+=a,this._core.setDirty(),this._engine.display.imageDirty=!0},SceneJS.Scale.prototype.incY=function(a){this._core.y+=a,this._core.matrixDirty=!0},SceneJS.Scale.prototype.incZ=function(a){this._core.z+=a,this._core.setDirty(),this._engine.display.imageDirty=!0},SceneJS.Scale.prototype._compile=function(a){SceneJS_modelXFormStack.push(this._core),this._compileNodes(a),SceneJS_modelXFormStack.pop()};var SceneJS_modelXFormStack=new function(){var a=SceneJS_math_identityMat4(),b=new Float32Array(a),c=SceneJS_math_transposeMat4(SceneJS_math_inverseMat4(SceneJS_math_identityMat4(),SceneJS_math_mat4())),d=new Float32Array(c),e={type:"xform",stateId:SceneJS._baseStateId++,matrix:a,mat:b,normalMatrix:c,normalMat:d,parent:null,cores:[],numCores:0,dirty:!1,matrixDirty:!1},f=[],g=0;this.top=e;var h,i=this;SceneJS_events.addListener(SceneJS_events.SCENE_COMPILING,function(){g=0,i.top=e,h=!0}),SceneJS_events.addListener(SceneJS_events.OBJECT_COMPILING,function(a){h&&(g>0?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;d>c;c++)b(a.cores[c])}a.parent=null,a.cores=[],a.numCores=0,a.matrixDirty=!1,a.matrix=SceneJS_math_identityMat4(),a.mat=new Float32Array(a.matrix),a.normalMat=new Float32Array(SceneJS_math_transposeMat4(SceneJS_math_inverseMat4(a.matrix,SceneJS_math_mat4()))),a.dirty=!1,a.setDirty=function(){a.matrixDirty=!0,a.dirty,b(a)},a.build=function(){a.matrixDirty&&(a.buildMatrix&&a.buildMatrix(),a.matrixDirty=!1);var b,c=a.parent;if(c)for(b=a.matrix.slice(0);c;)c.matrixDirty&&(c.buildMatrix&&c.buildMatrix(),c.mat.set(c.matrix),c.normalMat.set(SceneJS_math_transposeMat4(SceneJS_math_inverseMat4(c.matrix,SceneJS_math_mat4()))),c.matrixDirty=!1),SceneJS_math_mulMat4(c.matrix,b,b),!c.dirty,c=c.parent;else b=a.matrix;a.mat.set(b),a.normalMat.set(SceneJS_math_transposeMat4(SceneJS_math_inverseMat4(b,SceneJS_math_mat4()))),a.dirty=!1}},this.push=function(a){f[g++]=a,a.parent=this.top,a.dirty=!0,this.top&&(this.top.cores[this.top.numCores++]=a),a.numCores=0,this.top=a,h=!0},this.pop=function(){this.top=--g>0?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){this._canvas=a.canvas,this._programFactory=new SceneJS_ProgramFactory({canvas:a.canvas}),this._chunkFactory=new SceneJS_ChunkFactory,this.transparent=a.transparent===!0,this.enable=null,this.flags=null,this.layer=null,this.stage=null,this.renderer=null,this.depthBuffer=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};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,"colorBuffer",this.colorBuffer),this._setChunk(b,10,"view",this.view),this._setChunk(b,11,"lights",this.lights),this._setChunk(b,12,"material",this.material),this._setChunk(b,13,"texture",this.texture),this._setChunk(b,14,"regionMap",this.regionMap),this._setChunk(b,15,"fresnel",this.fresnel),this._setChunk(b,16,"cubemap",this.cubemap),this._setChunk(b,17,"clips",this.clips),this._setChunk(b,18,"renderer",this.renderer),this._setChunk(b,19,"geometry",this.morphGeometry,this.geometry),this._setChunk(b,20,"listeners",this.renderListeners),this._setChunk(b,21,"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;e>d;d++)b=c[d],"ambient"==b.mode&&(this._ambientColor[0]=b.color[0],this._ambientColor[1]=b.color[1],this._ambientColor[2]=b.color[2])},SceneJS_Display.prototype.removeObject=function(a){var b=this._objects[a];if(b){this._programFactory.putProgram(b.program),b.program=null,b.hash=null;for(var c,d=0,e=b.chunks.length;e>d;d++)c=b.chunks[d],c&&this._chunkFactory.putChunk(c);this._objectFactory.putObject(b),delete this._objects[a],this.objectListDirty=!0}},SceneJS_Display.prototype.selectTags=function(a){this._tagSelector=a,this.drawListDirty=!0},SceneJS_Display.prototype.render=function(a){a=a||{},this.objectListDirty&&(this._buildObjectList(),this.objectListDirty=!1,this.stateOrderDirty=!0),this.stateOrderDirty&&(this._makeStateSortKeys(),this.stateOrderDirty=!1,this.stateSortDirty=!0),this.stateSortDirty&&(this._stateSort(),this.stateSortDirty=!1,this.drawListDirty=!0),this.drawListDirty&&(this._buildDrawList(),this.imageDirty=!0),(this.imageDirty||a.force)&&(SceneJS_events.fireEvent(SceneJS_events.RENDER,{forced:!!a.force}),this._doDrawList({clear:a.clear!==!1,opaqueOnly:a.opaqueOnly}),this.imageDirty=!1,this.pickBufDirty=!0)},SceneJS_Display.prototype._buildObjectList=function(){var a=this._objectListLen;this._objectListLen=0;for(var b in this._objects)this._objects.hasOwnProperty(b)&&(this._objectList[this._objectListLen++]=this._objects[b]);if(a>this._objectListLen)for(i=this._objectListLen;ib;b++)a=this._objectList[b],a.program?a.sortKey=1e12*(a.stage.priority+1)+1e9*(a.flags.transparent?2:1)+1e6*(a.layer.priority+1)+1e3*(a.program.id+1)+a.texture.stateId:a.sortKey=-1},SceneJS_Display.prototype._stateSort=function(){this._objectList.length=this._objectListLen,this._objectList.sort(this._stateSortObjects)},SceneJS_Display.prototype._stateSortObjects=function(a,b){return a.sortKey-b.sortKey},SceneJS_Display.prototype._logObjectList=function(){console.log("--------------------------------------------------------------------------------------------------"),console.log(this._objectListLen+" objects");for(var a=0,b=this._objectListLen;b>a;a++){var c=this._objectList[a];console.log("SceneJS_Display : object["+a+"] sortKey = "+c.sortKey)}console.log("--------------------------------------------------------------------------------------------------")},SceneJS_Display.prototype._buildDrawList=function(){this._lastStateId=this._lastStateId||[],this._lastPickStateId=this._lastPickStateId||[];var a;for(a=0;25>a;a++)this._lastStateId[a]=null,this._lastPickStateId[a]=null;var b=this._drawListLen,c=this._pickDrawListLen,d=this._objectDrawListLen,e=this._objectPickListLen;this._drawListLen=0,this._pickDrawListLen=0,this._objectDrawListLen=0,this._objectPickListLen=1,this._drawListTransparentIndex=-1;var f,g,h,i,j,k={},l=[],m=[];for(this._tagSelector&&(g=this._tagSelector.mask,h=this._tagSelector.regex),a=0,len=this._objectListLen;ar;r++)n=q[r],o=n.coreId,p=k[o],p||(p=[],k[o]=p,l.push(p),m.push(this._chunkFactory.getChunk(n.stateId,"renderTarget",f.program,n))),p.push(f);else this._objectDrawList[this._objectDrawListLen++]=f;var p,n,f,t;for(a=0,len=l.length;ar;r++)f=p[r],t=f.stage&&f.stage.pickable&&f.flags&&f.flags.picking,this._appendObjectToDrawLists(f,t)}for(f&&this._appendRenderTargetChunk(this._chunkFactory.getChunk(-1,"renderTarget",f.program,{})),a=0,len=this._objectDrawListLen;athis._drawListLen)for(a=this._drawListLen;b>a;a++)this._drawList[a]=null;if(c>this._pickDrawListLen)for(a=this._pickDrawListLen;c>a;a++)this._pickDrawList[a]=null;if(d>this._objectDrawListLen)for(a=this._objectDrawListLen;d>a;a++)this._objectDrawList[a]=null;if(e>this._objectPickListLen)for(a=this._objectPickListLen;e>a;a++)this._objectPickList[a]=null;this.drawListDirty=!1},SceneJS_Display.prototype._appendRenderTargetChunk=function(a){this._drawList[this._drawListLen++]=a},SceneJS_Display.prototype._appendObjectToDrawLists=function(a,b){for(var c,d=a.chunks,e=0,f=d.length;f>e;e++)c=d[e],c&&(c.draw&&(c.unique||this._lastStateId[e]!=c.id)&&(this._drawList[this._drawListLen]=c,this._lastStateId[e]=c.id,c.core&&c.core&&c.core.transparent&&this._drawListTransparentIndex<0&&(this._drawListTransparentIndex=this._drawListLen),this._drawListLen++),c.pick&&b!==!1&&(c.unique||this._lastPickStateId[e]!=c.id)&&(this._pickDrawList[this._pickDrawListLen++]=c,this._lastPickStateId[e]=c.id));b&&(this._objectPickList[this._objectPickListLen++]=a)},SceneJS_Display.prototype._logDrawList=function(){console.log("--------------------------------------------------------------------------------------------------"),console.log(this._drawListLen+" draw list chunks");for(var a=0,b=this._drawListLen;b>a;a++){var c=this._drawList[a];switch(console.log("[chunk "+a+"] type = "+c.type),c.type){case"draw":console.log("\n");break;case"renderTarget":console.log(" bufType = "+c.core.bufType)}}console.log("--------------------------------------------------------------------------------------------------")},SceneJS_Display.prototype._logPickList=function(){console.log("--------------------------------------------------------------------------------------------------"),console.log(this._pickDrawListLen+" pick list chunks");for(var a=0,b=this._pickDrawListLen;b>a;a++){var c=this._pickDrawList[a];switch(console.log("[chunk "+a+"] type = "+c.type),c.type){case"draw":console.log("\n");break;case"renderTarget":console.log(" bufType = "+c.core.bufType)}}console.log("--------------------------------------------------------------------------------------------------")},function(){function a(a,b,c,d,e){var f=b.modelTransform.matrix,g=b.viewTransform.matrix,h=b.projTransform.matrix,i=SceneJS_math_mulMat4(g,f,m),j=SceneJS_math_mulMat4(h,i,n),k=SceneJS_math_inverseMat4(j,n),l=a.width,q=a.height,r=(c[0]-l/2)/(l/2),s=-(c[1]-q/2)/(q/2),t=SceneJS_math_transformVector4(k,[r,s,-1,1],o);t=SceneJS_math_mulVec4Scalar(t,1/t[3]);var u=SceneJS_math_transformVector4(k,[r,s,1,1],p);u=SceneJS_math_mulVec4Scalar(u,1/u[3]),d[0]=t[0],d[1]=t[1],d[2]=t[2],SceneJS_math_subVec3(u,t,e),SceneJS_math_normalizeVec3(e)}var b=SceneJS_math_vec3(),c=SceneJS_math_vec3(),d=SceneJS_math_vec3(),e=SceneJS_math_vec3(),f=SceneJS_math_vec3(),g=SceneJS_math_vec3(),h=SceneJS_math_vec3(),i=SceneJS_math_vec3(),j=SceneJS_math_vec3(),k=SceneJS_math_vec3(),l=SceneJS_math_vec3(),m=SceneJS_math_mat4(),n=SceneJS_math_mat4(),o=SceneJS_math_vec4(),p=SceneJS_math_vec4(),q=(SceneJS_math_vec4(),SceneJS_math_vec3()),r=SceneJS_math_vec3(),s=SceneJS_math_vec3(),t=SceneJS_math_vec3(),u=(SceneJS_math_vec3(),SceneJS_math_vec3()),v=SceneJS_math_vec3(),w=SceneJS_math_vec3(),x=SceneJS_math_vec3();SceneJS_math_vec3();SceneJS_Display.prototype.pick=function(m){var n,y,z,A=this._canvas.canvas,B=this._canvas.resolutionScaling,C=m.canvasX*B,D=m.canvasY*B,E=[C,D],F=this.pickBuf,G=null; -F||(F=this.pickBuf=new SceneJS._webgl.RenderBuffer({canvas:this._canvas})),this.render(),F.bind(),F.clear(),this._doDrawList({pickObject:!0,clear:!0}),this._canvas.gl.finish();var H=F.read(C,D),I=H[0]+256*H[1]+256*H[2]*256+256*H[3]*256*256;if(n=this._objectPickList[I]){G={canvasPos:E};var J=n.name;J&&(G.name=J.name,G.path=J.path,G.nodeId=J.nodeId)}if(m.pickRegion&&(F.clear(),this._doDrawList({pickRegion:!0,object:n,clear:!0}),H=F.read(C,D),0!==H[0]||0!==H[1]||0!==H[2]||0!==H[3])){G=G||{canvasPos:E};var K,L,M={r:H[0]/255,g:H[1]/255,b:H[2]/255,a:H[3]/255},N=this._frameCtx.regionData,O=.01,P={};for(y=0,z=N.length;z>y;y++)if(K=N[y].color,M&&N[y].data&&(L=Math.max(Math.abs(M.r-K.r),Math.abs(M.g-K.g),Math.abs(M.b-K.b),Math.abs(M.a-(void 0===K.a?M.a:K.a))),O>L)){P=N[y].data;break}G.color=M,G.regionData=P}if(m.pickTriangle&&n){F.clear(),this._doDrawList({pickTriangle:!0,object:n,clear:!0}),H=F.read(C,D);var Q=H[0]+256*H[1]+256*H[2]*256+256*H[3]*256*256;Q*=3,G.primitiveIndex=Q;var R=n.geometry;if("triangles"===R.primitiveName){G.primitive="triangle",a(A,n,E,b,c);var S=R.arrays.indices,T=S[Q],U=S[Q+1],V=S[Q+2],W=3*T,X=3*U,Y=3*V,Z=SceneJS_math_vec3();Z[0]=T,Z[1]=U,Z[2]=V,G.indices=Z;var $=n.morphGeometry,_=$.targets;if(_&&_.length>0&&_[0].positions)this._lerpTargets($.keys,$.targets,"positions",T,U,V,$.factor,d,e,f);else{var aa=R.arrays.positions;d[0]=aa[W],d[1]=aa[W+1],d[2]=aa[W+2],e[0]=aa[X],e[1]=aa[X+1],e[2]=aa[X+2],f[0]=aa[Y],f[1]=aa[Y+1],f[2]=aa[Y+2]}var ba=G.position=SceneJS_math_rayPlaneIntersect(b,c,d,e,f,SceneJS_math_vec3());o.set(ba),o[3]=1,SceneJS_math_transformVector4(n.modelTransform.matrix,o,p),G.worldPos=p.slice(0,3);var ca=G.barycentric=SceneJS_math_cartesianToBarycentric2(ba,d,e,f,SceneJS_math_vec3()),da=!1;if(_&&_.length>0&&_[0].normals&&(this._lerpTargets($.keys,$.targets,"normals",T,U,V,$.factor,g,h,i),da=!0),!da){var ea=R.arrays.normals;ea&&(g[0]=ea[W],g[1]=ea[W+1],g[2]=ea[W+2],h[0]=ea[X],h[1]=ea[X+1],h[2]=ea[X+2],i[0]=ea[Y],i[1]=ea[Y+1],i[2]=ea[Y+2],da=!0)}da&&(G.normal=SceneJS_math_addVec3(SceneJS_math_addVec3(SceneJS_math_mulVec3Scalar(g,ca[0],q),SceneJS_math_mulVec3Scalar(h,ca[1],r),s),SceneJS_math_mulVec3Scalar(i,ca[2],t),SceneJS_math_vec3()));var fa=R.arrays.uvs;if(fa&&fa.length>0){G.uvs=[];var ga,ha,ia=2*T,ja=2*U,ka=2*V;for(y=0,z=fa.length;z>y;y++)ga=fa[y],ga?(j[0]=ga[ia],j[1]=ga[ia+1],k[0]=ga[ja],k[1]=ga[ja+1],l[0]=ga[ka],l[1]=ga[ka+1],ha=SceneJS_math_addVec3(SceneJS_math_addVec3(SceneJS_math_mulVec2Scalar(j,ca[0],u),SceneJS_math_mulVec2Scalar(k,ca[1],v),w),SceneJS_math_mulVec2Scalar(l,ca[2],x),SceneJS_math_vec3()),G.uvs.push(ha)):ga.push(null);fa.length>0&&(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;ke;e++)this._pickDrawList[e].pick(c);else if(a.pickRegion||a.pickTriangle){if(a.object)for(var g,h=a.object.chunks,e=0,f=h.length;f>e;e++)g=h[e],g&&g.pick&&g.pick(c);else if(a.pickRegion)for(var e=0,f=this._pickDrawListLen;f>e;e++)this._pickDrawList[e].pick(c)}else for(var f=a.opaqueOnly&&this._drawListTransparentIndex>=0?this._drawListTransparentIndex:this._drawListLen,e=0;f>e;e++)this._drawList[e].draw(c);if(b.flush(),c.renderBuf&&c.renderBuf.unbind(),c.VAO){c.VAO.bindVertexArrayOES(null);for(var e=0;10>e;e++)b.disableVertexAttribArray(e)}},SceneJS_Display.prototype.readPixels=function(a,b,c){this._readPixelBuf||(this._readPixelBuf=new SceneJS._webgl.RenderBuffer({canvas:this._canvas})),this._readPixelBuf.bind(),this._readPixelBuf.clear(),this.render({force:!0,opaqueOnly:c});for(var d,e,f=0;b>f;f++)d=a[f]||(a[f]={}),e=this._readPixelBuf.read(d.x,d.y),d.r=e[0],d.g=e[1],d.b=e[2],d.a=e[3];this._readPixelBuf.unbind()},SceneJS_Display.prototype._unpackDepth=function(a){var b=[a[0]/256,a[1]/256,a[2]/256,a[3]/256],c=[1/16777216,1/65536,1/256,1];return SceneJS_math_dotVector4(b,c)},SceneJS_Display.prototype.destroy=function(){this._programFactory.destroy()};var SceneJS_ProgramSourceFactory=new function(){function a(){return l(),m("attribute vec3 SCENEJS_aVertex;"),m("attribute vec4 SCENEJS_aColor;"),m("uniform mat4 SCENEJS_uMMatrix;"),m("uniform mat4 SCENEJS_uVMatrix;"),m("uniform mat4 SCENEJS_uVNMatrix;"),m("uniform mat4 SCENEJS_uPMatrix;"),m("varying vec4 SCENEJS_vWorldVertex;"),G&&(m("attribute vec2 SCENEJS_aRegionMapUV;"),m("varying vec2 SCENEJS_vRegionMapUV;")),F&&(m("uniform float SCENEJS_uMorphFactor;"),p.morphGeometry.targets[0].vertexBuf&&m("attribute vec3 SCENEJS_aMorphVertex;")),m("varying vec4 SCENEJS_vColor;"),m("void main(void) {"),m(" vec4 tmpVertex=vec4(SCENEJS_aVertex, 1.0); "),F&&p.morphGeometry.targets[0].vertexBuf&&m(" tmpVertex = vec4(mix(tmpVertex.xyz, SCENEJS_aMorphVertex, SCENEJS_uMorphFactor), 1.0); "),m(" SCENEJS_vWorldVertex = SCENEJS_uMMatrix * tmpVertex; "),m("mat4 vPosMatrix = SCENEJS_uVMatrix;"),B&&m("vPosMatrix[3].xyz = vec3(0.0);"),m(" gl_Position = SCENEJS_uPMatrix * (vPosMatrix * SCENEJS_vWorldVertex);"),G&&m("SCENEJS_vRegionMapUV = SCENEJS_aRegionMapUV;"),m("SCENEJS_vColor = SCENEJS_aColor;"),m("}"),n()}function b(){if(l(),m("precision "+o(p._canvas.gl)+" float;"),m("varying vec4 SCENEJS_vWorldVertex;"),m("varying vec4 SCENEJS_vColor;"),m("uniform float SCENEJS_uPickMode;"),m("uniform vec4 SCENEJS_uPickColor;"),m("uniform bool SCENEJS_uClipping;"),E)for(var a=0;a 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?!1:e()}function d(){return p.texture.layers&&p.texture.layers.length>0?e():!1}function e(){return p.geometry.uvBufs?!0:p.morphGeometry.targets&&(p.morphGeometry.targets[0].uvBuf||p.morphGeometry.targets[0].uvBuf2)?!0:!1}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?!0:a.morphGeometry.targets&&a.morphGeometry.targets[0].normalBuf?!0:!1}function h(a){if(a.texture){var b=a.texture.layers;if(!b)return!1;for(var c=0,d=b.length;d>c;c++)if("normals"==b[c].applyTo)return!0}return!1}function i(){if(p.renderTarget&&p.renderTarget.targets)for(var a=p.renderTarget.targets,b=0,c=a.length;c>b;b++)if("depth"===a[b].bufType)return!0;return!1}function j(){var a=p.shader.shaders||{};if(a.vertex&&a.vertex.code&&""!=a.vertex.code&&SceneJS._isEmpty(a.vertex.hooks))return[a.vertex.code];var b,c,d=a.vertex||{},e=d.hooks||{},f=a.fragment||{},g=f.hooks||{};if(l(),m("uniform mat4 SCENEJS_uMMatrix;"),m("uniform mat4 SCENEJS_uVMatrix;"),m("uniform mat4 SCENEJS_uPMatrix;"),m("attribute vec3 SCENEJS_aVertex;"),m("uniform vec3 SCENEJS_uWorldEye;"),m("varying vec3 SCENEJS_vViewEyeVec;"),z&&(m("attribute vec3 SCENEJS_aNormal;"),m("uniform mat4 SCENEJS_uMNMatrix;"),m("uniform mat4 SCENEJS_uVNMatrix;"),m("varying vec3 SCENEJS_vViewNormal;"),w&&m("varying vec3 SCENEJS_vWorldNormal;"),D&&(m("attribute vec4 SCENEJS_aTangent;"),m("varying vec3 SCENEJS_vTangent;"))),x&&(c=p.geometry.uvBufs))for(var b=0,h=c.length;h>b;b++)c[b]&&m("attribute vec2 SCENEJS_aUVCoord"+b+";");if(p.geometry.colorBuf&&(m("attribute vec4 SCENEJS_aVertexColor;"),m("varying vec4 SCENEJS_vColor;")),(E||z)&&m("varying vec4 SCENEJS_vWorldVertex;"),m("varying vec4 SCENEJS_vViewVertex;"),x&&(c=p.geometry.uvBufs))for(b=0,h=c.length;h>b;b++)c[b]&&m("varying vec2 SCENEJS_vUVCoord"+b+";");if(H&&(m("attribute vec2 SCENEJS_aRegionMapUV;"),m("varying vec2 SCENEJS_vRegionMapUV;")),F&&(m("uniform float SCENEJS_uMorphFactor;"),p.morphGeometry.targets[0].vertexBuf&&m("attribute vec3 SCENEJS_aMorphVertex;"),z&&p.morphGeometry.targets[0].normalBuf&&m("attribute vec3 SCENEJS_aMorphNormal;"),D&&m("attribute vec3 SCENEJS_aMorphTangent;")),d.code&&m("\n"+d.code+"\n"),C&&(m("void billboard(inout mat4 mat) {"),m(" mat[0][0] = -1.0;"),m(" mat[0][1] = 0.0;"),m(" mat[0][2] = 0.0;"),p.billboard.spherical&&(m(" mat[1][0] = 0.0;"),m(" mat[1][1] = 1.0;"),m(" mat[1][2] = 0.0;")),m(" mat[2][0] = 0.0;"),m(" mat[2][1] = 0.0;"),m(" mat[2][2] =1.0;"),m("}")),m("void main(void) {"),D&&m("vec3 modelTangent = SCENEJS_aTangent.xyz;"),m(" vec4 tmpVertex=vec4(SCENEJS_aVertex, 1.0); "),m(" vec4 modelVertex = tmpVertex; "),z&&m(" vec4 modelNormal = vec4(SCENEJS_aNormal, 0.0); "),F&&(p.morphGeometry.targets[0].vertexBuf&&(m(" vec4 vMorphVertex = vec4(SCENEJS_aMorphVertex, 1.0); "),m(" modelVertex = vec4(mix(modelVertex.xyz, vMorphVertex.xyz, SCENEJS_uMorphFactor), 1.0); ")),z&&p.morphGeometry.targets[0].normalBuf&&(m(" vec4 vMorphNormal = vec4(SCENEJS_aMorphNormal, 1.0); "),m(" modelNormal = vec4( mix(modelNormal.xyz, vMorphNormal.xyz, SCENEJS_uMorphFactor), 1.0); ")),D&&m(" modelTangent = mix(modelTangent, SCENEJS_aMorphTangent, SCENEJS_uMorphFactor); ")),m("mat4 modelMatrix = SCENEJS_uMMatrix;"),m("mat4 viewMatrix = SCENEJS_uVMatrix;"),z&&(m("mat4 modelNormalMatrix = SCENEJS_uMNMatrix;"),m("mat4 viewNormalMatrix = SCENEJS_uVNMatrix;")),m("vec4 worldVertex;"),m("vec4 viewVertex;"),B&&m("viewMatrix[3].xyz = vec3(0.0);"),C?(m(" mat4 modelViewMatrix = viewMatrix * modelMatrix;"),m(" billboard(modelMatrix);"),m(" billboard(viewMatrix);"),m(" billboard(modelViewMatrix);"),z&&(m(" mat4 modelViewNormalMatrix = viewNormalMatrix * modelNormalMatrix;"),m(" billboard(modelNormalMatrix);"),m(" billboard(viewNormalMatrix);"),m(" billboard(modelViewNormalMatrix);")),e.viewMatrix&&m("viewMatrix = "+e.viewMatrix+"(viewMatrix);"),m(" worldVertex = modelMatrix * modelVertex;"),m(" viewVertex = modelViewMatrix * modelVertex;")):(e.viewMatrix&&m("viewMatrix = "+e.viewMatrix+"(viewMatrix);"),m(" worldVertex = modelMatrix * modelVertex;"),m(" viewVertex = viewMatrix * worldVertex; ")),e.viewPos&&m("viewVertex="+e.viewPos+"(viewVertex);"),z&&(m(" vec3 worldNormal = (modelNormalMatrix * modelNormal).xyz; "),m(" SCENEJS_vViewNormal = (viewNormalMatrix * vec4(worldNormal, 1.0)).xyz;"),w&&m(" SCENEJS_vWorldNormal = worldNormal;")),(E||z||g.worldPos)&&m(" SCENEJS_vWorldVertex = worldVertex;"),m(" SCENEJS_vViewVertex = viewVertex;"),m(e.projMatrix?"gl_Position = "+e.projMatrix+"(SCENEJS_uPMatrix) * viewVertex;":" gl_Position = SCENEJS_uPMatrix * viewVertex;"),D&&(m("modelTangent = normalize((viewNormalMatrix * modelNormalMatrix * vec4(modelTangent, 1.0)).xyz);"),m("vec3 bitangent = cross(SCENEJS_vViewNormal, modelTangent);"),m("mat3 TBM = mat3(modelTangent, bitangent, SCENEJS_vViewNormal);"),m("SCENEJS_vTangent = modelTangent;")),m("SCENEJS_vViewEyeVec = ((viewMatrix * vec4(SCENEJS_uWorldEye, 0.0)).xyz - viewVertex.xyz);"),D&&m("SCENEJS_vViewEyeVec *= TBM;"),x&&(c=p.geometry.uvBufs))for(b=0,h=c.length;h>b;b++)c[b]&&m("SCENEJS_vUVCoord"+b+" = SCENEJS_aUVCoord"+b+";");return p.geometry.colorBuf&&m("SCENEJS_vColor = SCENEJS_aVertexColor;"),H&&m("SCENEJS_vRegionMapUV = SCENEJS_aRegionMapUV;"),m("gl_PointSize = 3.0;"),m("}"),n()}function k(){var a=p.shader.shaders||{};if(a.fragment&&a.fragment.code&&""!=a.fragment.code&&SceneJS._isEmpty(a.fragment.hooks))return[a.fragment.code];var b=a.fragment||{},c=b.hooks||{},d=p.fresnel.diffuse,e=p.fresnel.specular,f=p.fresnel.alpha,g=p.fresnel.reflect,h=p.fresnel.emit,i=p.fresnel.fragment;if(l(),m("precision "+o(p._canvas.gl)+" float;"),m("uniform mat4 SCENEJS_uVMatrix;"),(E||z)&&m("varying vec4 SCENEJS_vWorldVertex;"),m("varying vec4 SCENEJS_vViewVertex;"),m("uniform float SCENEJS_uZNear;"),m("uniform float SCENEJS_uZFar;"),m("uniform vec3 SCENEJS_uWorldEye;"),E)for(var j=0;jj;j++)k[j]&&m("varying vec2 SCENEJS_vUVCoord"+j+";");if(x)for(var r,j=0,q=p.texture.layers.length;q>j;j++)r=p.texture.layers[j],m("uniform sampler2D SCENEJS_uSampler"+j+";"),r.matrix&&m("uniform mat4 SCENEJS_uLayer"+j+"Matrix;"),m("uniform float SCENEJS_uLayer"+j+"BlendFactor;")}if(z&&y)for(var r,j=0,q=p.cubemap.layers.length;q>j;j++)r=p.cubemap.layers[j],m("uniform samplerCube SCENEJS_uCubeMapSampler"+j+";"),m("uniform float SCENEJS_uCubeMapIntensity"+j+";");if(H&&(m("varying vec2 SCENEJS_vRegionMapUV;"),m("uniform sampler2D SCENEJS_uRegionMapSampler;"),m("uniform vec3 SCENEJS_uRegionMapRegionColor;"),m("uniform vec3 SCENEJS_uRegionMapHighlightFactor;"),m("uniform float SCENEJS_uRegionMapHideAlpha;")),m("uniform bool SCENEJS_uClipping;"),A&&m("uniform vec3 SCENEJS_uSolidColor;"),m("uniform bool SCENEJS_uDepthMode;"),m("uniform bool SCENEJS_uTransparent;"),p.geometry.colorBuf&&m("varying vec4 SCENEJS_vColor;"),m("uniform vec3 SCENEJS_uAmbientColor;"),m("uniform vec3 SCENEJS_uMaterialColor;"),m("uniform vec3 SCENEJS_uMaterialSpecularColor;"),m("uniform vec3 SCENEJS_uMaterialEmitColor;"),m("uniform float SCENEJS_uMaterialSpecular;"),m("uniform float SCENEJS_uMaterialShine;"),m("uniform float SCENEJS_uMaterialAlpha;"),m("uniform float SCENEJS_uMaterialEmit;"),d&&(m("uniform float SCENEJS_uDiffuseFresnelCenterBias;"),m("uniform float SCENEJS_uDiffuseFresnelEdgeBias;"),m("uniform float SCENEJS_uDiffuseFresnelPower;"),m("uniform vec3 SCENEJS_uDiffuseFresnelCenterColor;"),m("uniform vec3 SCENEJS_uDiffuseFresnelEdgeColor;")),e&&(m("uniform float SCENEJS_uSpecularFresnelCenterBias;"),m("uniform float SCENEJS_uSpecularFresnelEdgeBias;"),m("uniform float SCENEJS_uSpecularFresnelPower;"),m("uniform vec3 SCENEJS_uSpecularFresnelCenterColor;"),m("uniform vec3 SCENEJS_uSpecularFresnelEdgeColor;")),f&&(m("uniform float SCENEJS_uAlphaFresnelCenterBias;"),m("uniform float SCENEJS_uAlphaFresnelEdgeBias;"),m("uniform float SCENEJS_uAlphaFresnelPower;"),m("uniform vec3 SCENEJS_uAlphaFresnelCenterColor;"),m("uniform vec3 SCENEJS_uAlphaFresnelEdgeColor;")),g&&(m("uniform float SCENEJS_uReflectFresnelCenterBias;"),m("uniform float SCENEJS_uReflectFresnelEdgeBias;"),m("uniform float SCENEJS_uReflectFresnelPower;"),m("uniform vec3 SCENEJS_uReflectFresnelCenterColor;"),m("uniform vec3 SCENEJS_uReflectFresnelEdgeColor;")),h&&(m("uniform float SCENEJS_uEmitFresnelCenterBias;"),m("uniform float SCENEJS_uEmitFresnelEdgeBias;"),m("uniform float SCENEJS_uEmitFresnelPower;"),m("uniform vec3 SCENEJS_uEmitFresnelCenterColor;"),m("uniform vec3 SCENEJS_uEmitFresnelEdgeColor;")),i&&(m("uniform float SCENEJS_uFragmentFresnelCenterBias;"),m("uniform float SCENEJS_uFragmentFresnelEdgeBias;"),m("uniform float SCENEJS_uFragmentFresnelPower;"),m("uniform vec3 SCENEJS_uFragmentFresnelCenterColor;"),m("uniform vec3 SCENEJS_uFragmentFresnelEdgeColor;")),m("varying vec3 SCENEJS_vViewEyeVec;"),z){m("uniform mat4 SCENEJS_uVNMatrix;"),m("varying vec3 SCENEJS_vViewNormal;"),w&&m("varying vec3 SCENEJS_vWorldNormal;"),D&&m("varying vec3 SCENEJS_vTangent;");for(var s,j=0;j 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;q>j;j++){r=p.texture.layers[j];var t=r.applyFrom;if("normal"==t&&z){if(!p.geometry.normalBuf){SceneJS.log.warn("Texture layer applyFrom='normal' but geo has no normal vectors");continue}m("texturePos=vec4(viewNormalVec.xyz, 1.0);")}else{var u=t.match(/\d+$/),v=u?parseInt(u[0]):0,k=p.geometry.uvBufs;if(!k[v]){SceneJS.log.warn("Texture layer applyTo='uv' but geometry has no UV coordinates for layer "+v);continue}m("texturePos = vec4(SCENEJS_vUVCoord"+v+".s, SCENEJS_vUVCoord"+v+".t, 1.0, 1.0);")}m(r.matrix?"textureCoord=(SCENEJS_uLayer"+j+"Matrix * texturePos).xy;":"textureCoord=texturePos.xy;"),"alpha"==r.applyTo&&("multiply"==r.blendMode?m("alpha = alpha * (SCENEJS_uLayer"+j+"BlendFactor * texture2D(SCENEJS_uSampler"+j+", vec2(textureCoord.x, 1.0 - textureCoord.y)).b);"):"add"==r.blendMode&&m("alpha = ((1.0 - SCENEJS_uLayer"+j+"BlendFactor) * alpha) + (SCENEJS_uLayer"+j+"BlendFactor * texture2D(SCENEJS_uSampler"+j+", vec2(textureCoord.x, 1.0 - textureCoord.y)).b);")),"baseColor"==r.applyTo&&m("multiply"==r.blendMode?"color = color * (SCENEJS_uLayer"+j+"BlendFactor * texture2D(SCENEJS_uSampler"+j+", vec2(textureCoord.x, 1.0 - textureCoord.y)).rgb);":"color = ((1.0 - SCENEJS_uLayer"+j+"BlendFactor) * color) + (SCENEJS_uLayer"+j+"BlendFactor * texture2D(SCENEJS_uSampler"+j+", vec2(textureCoord.x, 1.0 - textureCoord.y)).rgb);"),"emit"==r.applyTo&&m("multiply"==r.blendMode?"emit = emit * (SCENEJS_uLayer"+j+"BlendFactor * texture2D(SCENEJS_uSampler"+j+", vec2(textureCoord.x, 1.0 - textureCoord.y)).r);":"emit = ((1.0 - SCENEJS_uLayer"+j+"BlendFactor) * emit) + (SCENEJS_uLayer"+j+"BlendFactor * texture2D(SCENEJS_uSampler"+j+", vec2(textureCoord.x, 1.0 - textureCoord.y)).r);"),"specular"==r.applyTo&&z&&m("multiply"==r.blendMode?"specular = specular * (SCENEJS_uLayer"+j+"BlendFactor * texture2D(SCENEJS_uSampler"+j+", vec2(textureCoord.x, 1.0 - textureCoord.y)).r);":"specular = ((1.0 - SCENEJS_uLayer"+j+"BlendFactor) * specular) + (SCENEJS_uLayer"+j+"BlendFactor * texture2D(SCENEJS_uSampler"+j+", vec2(textureCoord.x, 1.0 - textureCoord.y)).r);"),"shine"==r.applyTo&&m("multiply"==r.blendMode?"shine = shine * (SCENEJS_uLayer"+j+"BlendFactor * texture2D(SCENEJS_uSampler"+j+", vec2(textureCoord.x, 1.0 - textureCoord.y)).r);":"shine = ((1.0 - SCENEJS_uLayer"+j+"BlendFactor) * shine) + (SCENEJS_uLayer"+j+"BlendFactor * texture2D(SCENEJS_uSampler"+j+", vec2(textureCoord.x, 1.0 - textureCoord.y)).r);"),"normals"==r.applyTo&&z&&m("viewNormalVec = normalize(texture2D(SCENEJS_uSampler"+j+", vec2(textureCoord.x, -textureCoord.y)).xyz * 2.0 - 1.0);")}if(z&&y){m("float reflectFactor = 1.0;"),g&&(m("float reflectFresnel = fresnel(worldEyeVec, worldNormal, SCENEJS_uReflectFresnelEdgeBias, SCENEJS_uReflectFresnelCenterBias, SCENEJS_uReflectFresnelPower);"),m("reflectFactor *= mix(SCENEJS_uReflectFresnelEdgeColor.b, SCENEJS_uReflectFresnelCenterColor.b, reflectFresnel);")),m("vec4 v = SCENEJS_uVNMatrix * vec4(SCENEJS_vViewEyeVec, 1.0);"),m("vec3 v1 = v.xyz;"),m("v = SCENEJS_uVNMatrix * vec4(viewNormalVec, 1.0);"),m("vec3 v2 = v.xyz;"),m("vec3 envLookup = reflect(v1, v2);"),m("envLookup.y = envLookup.y * -1.0;"),m("vec4 envColor;");for(var j=0,q=p.cubemap.layers.length;q>j;j++)r=p.cubemap.layers[j],m("envColor = textureCube(SCENEJS_uCubeMapSampler"+j+", envLookup);"),m("color = mix(color, envColor.rgb, reflectFactor * specular * SCENEJS_uCubeMapIntensity"+j+");")}if(m(" vec4 fragColor;"),z){m(" vec3 lightValue = vec3(0.0, 0.0, 0.0);"),m(" vec3 specularValue = vec3(0.0, 0.0, 0.0);"),m(" vec3 viewLightVec;"),m(" float dotN;"),m(" float lightDist;"),D&&(m("vec3 tangent = normalize(SCENEJS_vTangent);"),m("vec3 bitangent = cross(SCENEJS_vViewNormal, tangent);"),m("mat3 TBM = mat3(tangent, bitangent, SCENEJS_vViewNormal);"));for(var s,j=0,q=p.lights.lights.length;q>j;j++)s=p.lights.lights[j],"ambient"!=s.mode&&("point"==s.mode&&("world"==s.space?(m("viewLightVec = SCENEJS_uLightPos"+j+" - SCENEJS_vWorldVertex.xyz;"),m("viewLightVec = vec3(SCENEJS_uVMatrix * vec4(viewLightVec, 0.0)).xyz;"),D&&m("viewLightVec *= TBM;")):(m("viewLightVec = SCENEJS_uLightPos"+j+".xyz - SCENEJS_vViewVertex.xyz;"),D&&m("viewLightVec *= TBM;")),m("dotN = max(dot(viewNormalVec, normalize(viewLightVec)), 0.0);"),m("lightDist = length( SCENEJS_uLightPos"+j+" - SCENEJS_vWorldVertex.xyz);"),m("attenuation = 1.0 - ( SCENEJS_uLightAttenuation"+j+"[0] + SCENEJS_uLightAttenuation"+j+"[1] * lightDist + SCENEJS_uLightAttenuation"+j+"[2] * lightDist * lightDist);"),s.diffuse&&m(" lightValue += dotN * SCENEJS_uLightColor"+j+" * attenuation;"),s.specular&&m(" specularValue += specularColor * SCENEJS_uLightColor"+j+" * specular * pow(max(dot(reflect(normalize(-viewLightVec), normalize(-viewNormalVec)), normalize(-SCENEJS_vViewVertex.xyz)), 0.0), shine) * attenuation;")),"dir"==s.mode&&("world"==s.space?(m("viewLightVec = normalize(SCENEJS_uLightDir"+j+");"),m("viewLightVec = vec3(SCENEJS_uVMatrix * vec4(viewLightVec, 0.0)).xyz;"),D&&m("viewLightVec *= TBM;")):(m("viewLightVec = normalize(SCENEJS_uLightDir"+j+");"),D&&m("viewLightVec *= TBM;")),m("viewLightVec = -viewLightVec;"),m("dotN = max(dot(viewNormalVec, normalize(viewLightVec)), 0.0);"),s.diffuse&&m("lightValue += dotN * SCENEJS_uLightColor"+j+";"),s.specular&&m("specularValue += specularColor * SCENEJS_uLightColor"+j+" * specular * pow(max(dot(reflect(normalize(-viewLightVec), normalize(-viewNormalVec)), normalize(-SCENEJS_vViewVertex.xyz)), 0.0), shine);")));p.geometry.colorBuf&&m("alpha *= colorA;"),(d||e||f||h)&&(d&&(m("float diffuseFresnel = fresnel(worldEyeVec, worldNormal, SCENEJS_uDiffuseFresnelEdgeBias, SCENEJS_uDiffuseFresnelCenterBias, SCENEJS_uDiffuseFresnelPower);"),m("color.rgb *= mix(SCENEJS_uDiffuseFresnelEdgeColor.rgb, SCENEJS_uDiffuseFresnelCenterColor.rgb, diffuseFresnel);")),e&&(m("float specFresnel = fresnel(worldEyeVec, worldNormal, SCENEJS_uSpecularFresnelEdgeBias, SCENEJS_uSpecularFresnelCenterBias, SCENEJS_uSpecularFresnelPower);"),m("specularValue *= mix(SCENEJS_uSpecularFresnelEdgeColor.rgb, SCENEJS_uSpecularFresnelCenterColor.rgb, specFresnel);")),f&&(m("float alphaFresnel = fresnel(worldEyeVec, worldNormal, SCENEJS_uAlphaFresnelEdgeBias, SCENEJS_uAlphaFresnelCenterBias, SCENEJS_uAlphaFresnelPower);"),m("alpha *= mix(SCENEJS_uAlphaFresnelEdgeColor.r, SCENEJS_uAlphaFresnelCenterColor.r, alphaFresnel);")),h&&(m("float emitFresnel = fresnel(worldEyeVec, worldNormal, SCENEJS_uEmitFresnelEdgeBias, SCENEJS_uEmitFresnelCenterBias, SCENEJS_uEmitFresnelPower);"),m("emitColor.rgb *= mix(SCENEJS_uEmitFresnelEdgeColor.rgb, SCENEJS_uEmitFresnelCenterColor.rgb, emitFresnel);"))),m("fragColor = vec4((specularValue.rgb + color.rgb * (lightValue.rgb + ambient.rgb)) + (emit * emitColor.rgb), alpha);")}else m("fragColor = vec4((color.rgb + (emit * color.rgb)) * (vec3(1.0, 1.0, 1.0) + ambient.rgb), alpha);");return H&&(m("vec3 regionColor = texture2D(SCENEJS_uRegionMapSampler, vec2(SCENEJS_vRegionMapUV.s, 1.0 - SCENEJS_vRegionMapUV.t)).rgb;"),m("float tolerance = 0.01;"),m("vec3 colorDelta = abs(SCENEJS_uRegionMapRegionColor - regionColor);"),"highlight"===p.regionMap.mode||"hide"===p.regionMap.mode?(m("if (max(colorDelta.x, max(colorDelta.y, colorDelta.z)) < tolerance) {"),m("highlight"===p.regionMap.mode?" fragColor.rgb *= SCENEJS_uRegionMapHighlightFactor;":" fragColor.a = SCENEJS_uRegionMapHideAlpha;"),m("}")):(m("if (max(colorDelta.x, max(colorDelta.y, colorDelta.z)) > 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);")),m("gl_FragColor = fragColor;"),m("}"),n()}function l(){K=[]}function m(a){K.push(a||"")}function n(){return K}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="";this.getSource=function(e,l){var m=J[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(),m=new SceneJS_ProgramSource(e,a(p),b(p),j(p),k(p)),J[e]=m,m)},this.putSource=function(a){var b=J[a];b&&0==--b.useCount&&(J[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){this._canvas=a.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._nextProgramId++,a,d,this._canvas.gl),this._programs[a]=c}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])},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){this.id=a,this.hash=c.hash,this.source=c,this.gl=d,this.draw=null,this.pick=null,this.useCount=0,this.build(d)};SceneJS_Program.prototype.build=function(a){this.gl=a,this.draw=new SceneJS._webgl.Program(a,[this.source.drawVertexSrc.join("\n")],[this.source.drawFragmentSrc.join("\n")]),this.pick=new SceneJS._webgl.Program(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.sortKey=null,this.chunks=[],this.chunksLen=0,this.program=null,this.layer=null,this.texture=null,this.flags=null,this.tag=null};SceneJS.RenderContext=function(a){this._frameCtx=a},SceneJS.RenderContext.prototype.getCameraMatrix=function(){return this._frameCtx.cameraMat},SceneJS.RenderContext.prototype.getViewMatrix=function(){return this._frameCtx.viewMat},SceneJS.RenderContext.prototype.getModelMatrix=function(){return this._frameCtx.modelMat},SceneJS.RenderContext.prototype.getCanvasPos=function(a){this.getProjPos(a);var b=this._frameCtx.canvas.canvas,c=this._frameCtx.canvas.resolutionScaling,d=b.width/c,e=b.height/c,f=this._pc,g=f[0]/f[3]*d*.5,h=f[1]/f[3]*e*.5; -return{x:g+.5*d,y:e-h-.5*e}},SceneJS.RenderContext.prototype.getCameraPos=function(a){return this.getProjPos(a),this._camPos=SceneJS_math_normalizeVec3(this._pc,[0,0,0]),{x:this._camPos[0],y:this._camPos[1],z:this._camPos[2]}},SceneJS.RenderContext.prototype.getProjPos=function(a){return this.getViewPos(a),this._pc=SceneJS_math_transformPoint3(this._frameCtx.cameraMat,this._vc),{x:this._pc[0],y:this._pc[1],z:this._pc[2],w:this._pc[3]}},SceneJS.RenderContext.prototype.getViewPos=function(a){return this.getWorldPos(a),this._vc=SceneJS_math_transformPoint3(this._frameCtx.viewMat,this._wc),{x:this._vc[0],y:this._vc[1],z:this._vc[2],w:this._vc[3]}},SceneJS.RenderContext.prototype.getWorldPos=function(a){return this._wc=SceneJS_math_transformPoint3(this._frameCtx.modelMat,a||[0,0,0]),{x:this._wc[0],y:this._wc[1],z:this._wc[2],w:this._wc[3]}};var SceneJS_Chunk=function(){};SceneJS_Chunk.prototype.init=function(a,b,c,d){this.id=a,this.program=b,this.core=c,this.core2=d,this.build&&this.build()};var SceneJS_ChunkFactory=function(){this._chunks={},this.chunkTypes=SceneJS_ChunkFactory.chunkTypes};SceneJS_ChunkFactory.chunkTypes={},SceneJS_ChunkFactory._freeChunks={},SceneJS_ChunkFactory.createChunkType=function(a){if(!a.type)throw"'type' expected in params";var b=SceneJS_Chunk,c=function(){this.useCount=0,this.init.apply(this,arguments)};return c.prototype=new b,c.prototype.constructor=c,a.drawAndPick&&(a.draw=a.pick=a.drawAndPick),SceneJS_ChunkFactory.chunkTypes[a.type]=c,SceneJS._apply(a,c.prototype),SceneJS_ChunkFactory._freeChunks[a.type]={chunks:[],chunksLen:0},c},SceneJS_ChunkFactory.prototype.getChunk=function(a,b,c,d,e){var f=SceneJS_ChunkFactory.chunkTypes[b];if(!f)throw"chunk type not supported: '"+b+"'";var g=this._chunks[a];return g?(g.useCount++,g):(g=new f(a,c,d,e),g.type=b,g.useCount=1,this._chunks[a]=g,g)},SceneJS_ChunkFactory.prototype.putChunk=function(a){0!=a.useCount&&--a.useCount<=0&&(a.recycle&&a.recycle(),delete this._chunks[a.id])},SceneJS_ChunkFactory.prototype.webglRestored=function(){var a;for(var b in this._chunks)this._chunks.hasOwnProperty(b)&&(a=this._chunks[b],a&&a.build&&a.build())},SceneJS_ChunkFactory.createChunkType({type:"camera",build:function(){this._uPMatrixDraw=this.program.draw.getUniform("SCENEJS_uPMatrix"),this._uZNearDraw=this.program.draw.getUniform("SCENEJS_uZNear"),this._uZFarDraw=this.program.draw.getUniform("SCENEJS_uZFar"),this._uPMatrixPick=this.program.pick.getUniform("SCENEJS_uPMatrix"),this._uZNearPick=this.program.pick.getUniform("SCENEJS_uZNear"),this._uZFarPick=this.program.pick.getUniform("SCENEJS_uZFar")},draw:function(a){this.core.checkAspect&&this.core.checkAspect(this.core,a.aspect);this.program.gl;this._uPMatrixDraw&&this._uPMatrixDraw.setValue(this.core.mat),this._uZNearDraw&&this._uZNearDraw.setValue(this.core.optics.near),this._uZFarDraw&&this._uZFarDraw.setValue(this.core.optics.far),a.cameraMat=this.core.mat},pick:function(a){this.core.checkAspect&&this.core.checkAspect(this.core,a.aspect);this.program.gl;this._uPMatrixPick&&this._uPMatrixPick.setValue(this.core.mat),a.rayPick&&(this._uZNearPick&&this._uZNearPick.setValue(this.core.optics.near),this._uZFarPick&&this._uZFarPick.setValue(this.core.optics.far)),a.cameraMat=this.core.mat}}),SceneJS_ChunkFactory.createChunkType({type:"clips",build:function(){this._draw=this._draw||[];for(var a=this.program.draw,b=0,c=this.core.clips.length;c>b;b++)this._draw[b]={uClipMode:a.getUniform("SCENEJS_uClipMode"+b),uClipNormalAndDist:a.getUniform("SCENEJS_uClipNormalAndDist"+b)};this._pick=this._pick||[];for(var d=this.program.pick,b=0,c=this.core.clips.length;c>b;b++)this._pick[b]={uClipMode:d.getUniform("SCENEJS_uClipMode"+b),uClipNormalAndDist:d.getUniform("SCENEJS_uClipNormalAndDist"+b)}},drawAndPick:function(a){for(var b,c,d,e=a.picking,f=e?this._pick:this._draw,g=this.core.clips,h=(this.program.gl,0),i=g.length;i>h;h++)e?(b=f[h].uClipMode,c=f[h].uClipNormalAndDist):(b=f[h].uClipMode,c=f[h].uClipNormalAndDist),b&&c&&(d=g[h],"inside"==d.mode?(b.setValue(2),c.setValue(d.normalAndDist)):"outside"==d.mode?(b.setValue(1),c.setValue(d.normalAndDist)):b.setValue(0))}}),SceneJS_ChunkFactory.createChunkType({type:"draw",unique:!0,build:function(){this._depthModeDraw=this.program.draw.getUniform("SCENEJS_uDepthMode"),this._uPickColor=this.program.pick.getUniform("SCENEJS_uPickColor")},draw:function(a){var b=this.core,c=this.program.gl;this._depthModeDraw&&this._depthModeDraw.setValue(a.depthMode),c.drawElements(b.primitive,b.indexBuf.numItems,b.indexBuf.itemType,0)},pick:function(a){var b=this.core,c=this.program.gl;if(a.pickObject||a.pickRegion){if(a.pickObject&&this._uPickColor){var d=a.pickIndex>>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])}c.drawElements(b.primitive,b.indexBuf.numItems,b.indexBuf.itemType,0)}else if(a.pickTriangle){var h=b.getPickIndices();h&&c.drawElements(b.primitive,h.numItems,h.itemType,0)}}}),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.SRC_ALPHA,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)}}}),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.SRC_ALPHA,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|b.STENCIL_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;1e3>c&&(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");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.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)):this._aVertexDraw&&this._aVertexDraw.bindFloatArrayBuffer(this.core2.vertexBuf),this._aMorphNormalDraw?(this._aNormalDraw.bindFloatArrayBuffer(d.normalBuf),this._aMorphNormalDraw.bindFloatArrayBuffer(e.normalBuf)):this._aNormalDraw&&this._aNormalDraw.bindFloatArrayBuffer(this.core2.normalBuf),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]))):this._aTangentDraw)}for(var g,h=0,i=this._aUVDraw.length;i>h;h++)g=this.core2.uvBufs[h],g&&this._aUVDraw[h].bindFloatArrayBuffer(g);this._aColorDraw&&this._aColorDraw.bindFloatArrayBuffer(this.core2.colorBuf),this.setDrawMorphFactor()},setDrawMorphFactor:function(){this._uMorphFactorDraw&&this._uMorphFactorDraw.setValue(this.core.factor)},draw:function(a){var b=this.core.targets&&this.core.targets.length,c=this.core2.interleavedBuf&&!this.core2.interleavedBuf.dirty;if(this.VAO&&a.VAO){if(a.VAO.bindVertexArrayOES(this.VAO),b){if(this.VAOMorphKey1==this.core.key1&&this.VAOMorphKey2==this.core.key2)return void this.setDrawMorphFactor()}else if(c||!this.VAOHasInterleavedBuf)return}else a.VAO&&(a.VAO.bindVertexArrayOES(null),this.VAO=a.VAO.createVertexArrayOES(),a.VAO.bindVertexArrayOES(this.VAO));if(b)this.morphDraw(a);else{if(c){this.VAOHasInterleavedBuf=!0,this.core2.interleavedBuf.bind(),this._aVertexDraw&&this._aVertexDraw.bindInterleavedFloatArrayBuffer(3,this.core2.interleavedStride,this.core2.interleavedPositionOffset),this._aNormalDraw&&this._aNormalDraw.bindInterleavedFloatArrayBuffer(3,this.core2.interleavedStride,this.core2.interleavedNormalOffset);for(var d=0,e=this._aUVDraw.length;e>d;d++)this._aUVDraw[d].bindInterleavedFloatArrayBuffer(2,this.core2.interleavedStride,this.core2.interleavedUVOffsets[d]);this._aColorDraw&&this._aColorDraw.bindInterleavedFloatArrayBuffer(4,this.core2.interleavedStride,this.core2.interleavedColorOffset)}else{this.VAOHasInterleavedBuf=!1,this._aVertexDraw&&this._aVertexDraw.bindFloatArrayBuffer(this.core2.vertexBuf),this._aNormalDraw&&this._aNormalDraw.bindFloatArrayBuffer(this.core2.normalBuf);for(var f,d=0,e=this._aUVDraw.length;e>d;d++)f=this.core2.uvBufs[d],f&&this._aUVDraw[d].bindFloatArrayBuffer(f);this._aColorDraw&&this._aColorDraw.bindFloatArrayBuffer(this.core2.colorBuf)}if(this._aTangentDraw){var g=a.normalMapUVLayerIdx;g>=0&&this._aTangentDraw.bindFloatArrayBuffer(this.core2.getTangents(g))}}if(this._aRegionMapUVDraw){var h=a.regionMapUVLayerIdx;if(h>=0){var i=this.core2.uvBufs;hc;c++)switch(a[c].mode){case"ambient":this._uAmbientColor[c]=b.draw.getUniform("SCENEJS_uAmbientColor");break;case"dir":this._uLightColor[c]=b.draw.getUniform("SCENEJS_uLightColor"+c),this._uLightPos[c]=null,this._uLightDir[c]=b.draw.getUniform("SCENEJS_uLightDir"+c);break;case"point":this._uLightColor[c]=b.draw.getUniform("SCENEJS_uLightColor"+c),this._uLightPos[c]=b.draw.getUniform("SCENEJS_uLightPos"+c),this._uLightDir[c]=null,this._uLightAttenuation[c]=b.draw.getUniform("SCENEJS_uLightAttenuation"+c)}},draw:function(a){a.dirty&&this.build();for(var b,c=this.core.lights,d=(this.program.gl,0),e=c.length;e>d;d++)b=c[d],this._uAmbientColor[d]?this._uAmbientColor[d].setValue(b.color):(this._uLightColor[d]&&this._uLightColor[d].setValue(b.color),this._uLightPos[d]&&(this._uLightPos[d].setValue(b.pos),this._uLightAttenuation[d]&&this._uLightAttenuation[d].setValue(b.attenuation)),this._uLightDir[d]&&this._uLightDir[d].setValue(b.dir))}}),SceneJS_ChunkFactory.createChunkType({type:"listeners",programGlobal:!0,build:function(){},draw:function(a){for(var b=this.core.listeners,c=a.renderListenerCtx,d=b.length-1;d>=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._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),a.viewMat=this.core.mat},pick:function(a){this.program.gl;this._uvMatrixPick&&this._uvMatrixPick.setValue(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;10>d;d++)c.disableVertexAttribArray(d);a.drawProgram=this.program.draw},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;10>d;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.SRC_ALPHA,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:"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;g>f;f++){c=b[f];for(d in c)c.hasOwnProperty(d)&&e.setUniform(d,c[d])}}}),SceneJS_ChunkFactory.createChunkType({type:"shaderParams",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;g>f;f++){c=b[f];for(d in c)c.hasOwnProperty(d)&&e.setUniform(d,c[d])}}}),SceneJS_ChunkFactory.createChunkType({type:"style",programGlobal:!0,drawAndPick:function(a){var b=this.core.lineWidth;if(a.lineWidth!=b){var c=this.program.gl;c.lineWidth(b),a.lineWidth=b}}}),SceneJS_ChunkFactory.createChunkType({type:"texture",build:function(){this._uTexSampler=this._uTexSampler||[],this._uTexMatrix=this._uTexMatrix||[],this._uTexBlendFactor=this._uTexBlendFactor||[];var a=this.core.layers;if(a)for(var b,c=this.program.draw,d=0,e=a.length;e>d;d++)b=a[d],this._uTexSampler[d]="SCENEJS_uSampler"+d,this._uTexMatrix[d]=c.getUniform("SCENEJS_uLayer"+d+"Matrix"),this._uTexBlendFactor[d]=c.getUniform("SCENEJS_uLayer"+d+"BlendFactor")},draw:function(a){a.textureUnit=0,a.normalMapUVLayerIdx=-1;var b=this.core.layers;if(b)for(var c,d=this.program.draw,e=0,f=b.length;f>e;e++)c=b[e],this._uTexSampler[e]&&c.texture&&(d.bindTexture(this._uTexSampler[e],c.texture,a.textureUnit),a.textureUnit=(a.textureUnit+1)%SceneJS.WEBGL_INFO.MAX_TEXTURE_UNITS,c._matrixDirty&&c.buildMatrix&&c.buildMatrix.call(c),this._uTexMatrix[e]&&this._uTexMatrix[e].setValue(c.matrixAsArray),this._uTexBlendFactor[e]&&this._uTexBlendFactor[e].setValue(c.blendFactor),c.isNormalMap&&(a.normalMapUVLayerIdx=c.uvLayerIdx));a.texture=this.core}}),SceneJS_ChunkFactory.createChunkType({type:"fresnel",build:function(){var a=this.program.draw,b=this.core;b.diffuse&&(this._uDiffuseFresnelCenterBias=a.getUniform("SCENEJS_uDiffuseFresnelCenterBias"),this._uDiffuseFresnelEdgeBias=a.getUniform("SCENEJS_uDiffuseFresnelEdgeBias"),this._uDiffuseFresnelPower=a.getUniform("SCENEJS_uDiffuseFresnelPower"),this._uDiffuseFresnelCenterColor=a.getUniform("SCENEJS_uDiffuseFresnelCenterColor"),this._uDiffuseFresnelEdgeColor=a.getUniform("SCENEJS_uDiffuseFresnelEdgeColor")),b.specular&&(this._uSpecularFresnelCenterBias=a.getUniform("SCENEJS_uSpecularFresnelCenterBias"),this._uSpecularFresnelEdgeBias=a.getUniform("SCENEJS_uSpecularFresnelEdgeBias"),this._uSpecularFresnelPower=a.getUniform("SCENEJS_uSpecularFresnelPower"),this._uSpecularFresnelCenterColor=a.getUniform("SCENEJS_uSpecularFresnelCenterColor"),this._uSpecularFresnelEdgeColor=a.getUniform("SCENEJS_uSpecularFresnelEdgeColor")),b.alpha&&(this._uAlphaFresnelCenterBias=a.getUniform("SCENEJS_uAlphaFresnelCenterBias"),this._uAlphaFresnelEdgeBias=a.getUniform("SCENEJS_uAlphaFresnelEdgeBias"),this._uAlphaFresnelPower=a.getUniform("SCENEJS_uAlphaFresnelPower"),this._uAlphaFresnelCenterColor=a.getUniform("SCENEJS_uAlphaFresnelCenterColor"),this._uAlphaFresnelEdgeColor=a.getUniform("SCENEJS_uAlphaFresnelEdgeColor")),b.reflect&&(this._uReflectFresnelCenterBias=a.getUniform("SCENEJS_uReflectFresnelCenterBias"),this._uReflectFresnelEdgeBias=a.getUniform("SCENEJS_uReflectFresnelEdgeBias"),this._uReflectFresnelPower=a.getUniform("SCENEJS_uReflectFresnelPower"),this._uReflectFresnelCenterColor=a.getUniform("SCENEJS_uReflectFresnelCenterColor"),this._uReflectFresnelEdgeColor=a.getUniform("SCENEJS_uReflectFresnelEdgeColor")),b.emit&&(this._uEmitFresnelCenterBias=a.getUniform("SCENEJS_uEmitFresnelCenterBias"),this._uEmitFresnelEdgeBias=a.getUniform("SCENEJS_uEmitFresnelEdgeBias"),this._uEmitFresnelPower=a.getUniform("SCENEJS_uEmitFresnelPower"),this._uEmitFresnelCenterColor=a.getUniform("SCENEJS_uEmitFresnelCenterColor"),this._uEmitFresnelEdgeColor=a.getUniform("SCENEJS_uEmitFresnelEdgeColor")),b.fragment&&(this._uFragmentFresnelCenterBias=a.getUniform("SCENEJS_uFragmentFresnelCenterBias"),this._uFragmentFresnelEdgeBias=a.getUniform("SCENEJS_uFragmentFresnelEdgeBias"),this._uFragmentFresnelPower=a.getUniform("SCENEJS_uFragmentFresnelPower"),this._uFragmentFresnelCenterColor=a.getUniform("SCENEJS_uFragmentFresnelCenterColor"),this._uFragmentFresnelEdgeColor=a.getUniform("SCENEJS_uFragmentFresnelEdgeColor"))},draw:function(){var a=(this.program.gl,this.core);a.diffuse&&(this._uDiffuseFresnelCenterBias&&this._uDiffuseFresnelCenterBias.setValue(a.diffuse.centerBias),this._uDiffuseFresnelEdgeBias&&this._uDiffuseFresnelEdgeBias.setValue(a.diffuse.edgeBias),this._uDiffuseFresnelPower&&this._uDiffuseFresnelPower.setValue(a.diffuse.power),this._uDiffuseFresnelCenterColor&&this._uDiffuseFresnelCenterColor.setValue(a.diffuse.centerColor),this._uDiffuseFresnelEdgeColor&&this._uDiffuseFresnelEdgeColor.setValue(a.diffuse.edgeColor)),a.specular&&(this._uSpecularFresnelCenterBias&&this._uSpecularFresnelCenterBias.setValue(a.specular.centerBias),this._uSpecularFresnelEdgeBias&&this._uSpecularFresnelEdgeBias.setValue(a.specular.edgeBias),this._uSpecularFresnelPower&&this._uSpecularFresnelPower.setValue(a.specular.power),this._uSpecularFresnelCenterColor&&this._uSpecularFresnelCenterColor.setValue(a.specular.centerColor),this._uSpecularFresnelEdgeColor&&this._uSpecularFresnelEdgeColor.setValue(a.specular.edgeColor)),a.alpha&&(this._uAlphaFresnelCenterBias&&this._uAlphaFresnelCenterBias.setValue(a.alpha.centerBias),this._uAlphaFresnelEdgeBias&&this._uAlphaFresnelEdgeBias.setValue(a.alpha.edgeBias),this._uAlphaFresnelPower&&this._uAlphaFresnelPower.setValue(a.alpha.power),this._uAlphaFresnelCenterColor&&this._uAlphaFresnelCenterColor.setValue(a.alpha.centerColor),this._uAlphaFresnelEdgeColor&&this._uAlphaFresnelEdgeColor.setValue(a.alpha.edgeColor)),a.reflect&&(this._uReflectFresnelCenterBias&&this._uReflectFresnelCenterBias.setValue(a.reflect.centerBias),this._uReflectFresnelEdgeBias&&this._uReflectFresnelEdgeBias.setValue(a.reflect.edgeBias),this._uReflectFresnelPower&&this._uReflectFresnelPower.setValue(a.reflect.power),this._uReflectFresnelCenterColor&&this._uReflectFresnelCenterColor.setValue(a.reflect.centerColor),this._uReflectFresnelEdgeColor&&this._uReflectFresnelEdgeColor.setValue(a.reflect.edgeColor)),a.emit&&(this._uEmitFresnelCenterBias&&this._uEmitFresnelCenterBias.setValue(a.emit.centerBias),this._uEmitFresnelEdgeBias&&this._uEmitFresnelEdgeBias.setValue(a.emit.edgeBias),this._uEmitFresnelPower&&this._uEmitFresnelPower.setValue(a.emit.power),this._uEmitFresnelCenterColor&&this._uEmitFresnelCenterColor.setValue(a.emit.centerColor),this._uEmitFresnelEdgeColor&&this._uEmitFresnelEdgeColor.setValue(a.emit.edgeColor)),a.fragment&&(this._uFragmentFresnelCenterBias&&this._uFragmentFresnelCenterBias.setValue(a.fragment.centerBias),this._uFragmentFresnelEdgeBias&&this._uFragmentFresnelEdgeBias.setValue(a.fragment.edgeBias),this._uFragmentFresnelPower&&this._uFragmentFresnelPower.setValue(a.fragment.power),this._uFragmentFresnelCenterColor&&this._uFragmentFresnelCenterColor.setValue(a.fragment.centerColor),this._uFragmentFresnelEdgeColor&&this._uFragmentFresnelEdgeColor.setValue(a.fragment.edgeColor))}}),SceneJS_ChunkFactory.createChunkType({type:"cubemap",build:function(){this._uCubeMapSampler=this._uCubeMapSampler||[],this._uCubeMapIntensity=this._uCubeMapIntensity||[];var a=this.core.layers;if(a)for(var b,c=this.program.draw,d=0,e=a.length;e>d;d++)b=a[d],this._uCubeMapSampler[d]="SCENEJS_uCubeMapSampler"+d,this._uCubeMapIntensity[d]=c.getUniform("SCENEJS_uCubeMapIntensity"+d)},draw:function(a){var b=this.core.layers;if(b)for(var c,d=this.program.draw,e=0,f=b.length;f>e;e++)c=b[e],this._uCubeMapSampler[e]&&c.texture&&(d.bindTexture(this._uCubeMapSampler[e],c.texture,a.textureUnit),a.textureUnit=(a.textureUnit+1)%SceneJS.WEBGL_INFO.MAX_TEXTURE_UNITS,this._uCubeMapIntensity[e]&&this._uCubeMapIntensity[e].setValue(c.intensity))}}),SceneJS_ChunkFactory.createChunkType({type:"xform",build:function(){var a=this.program.draw;this._uMatLocationDraw=a.getUniform("SCENEJS_uMMatrix"),this._uNormalMatLocationDraw=a.getUniform("SCENEJS_uMNMatrix");var b=this.program.pick;this._uMatLocationPick=b.getUniform("SCENEJS_uMMatrix")},draw:function(a){(SceneJS_configsModule.configs.forceXFormCoreRebuild===!0||this.core.dirty&&this.core.build)&&this.core.build();this.program.gl;this._uMatLocationDraw&&this._uMatLocationDraw.setValue(this.core.mat),this._uNormalMatLocationDraw&&this._uNormalMatLocationDraw.setValue(this.core.normalMat),a.modelMat=this.core.mat},pick:function(a){this.core.dirty&&this.core.build();this.program.gl;this._uMatLocationPick&&this._uMatLocationPick.setValue(this.core.mat),a.modelMat=this.core.mat}}); \ No newline at end of file +F||(F=this.pickBuf=new SceneJS._webgl.RenderBuffer({canvas:this._canvas})),this.render(),F.bind(),F.clear(),this._doDrawList({pickObject:!0,clear:!0}),this._canvas.gl.finish();var H=F.read(C,D),I=H[0]+256*H[1]+256*H[2]*256+256*H[3]*256*256;if(n=this._objectPickList[I]){G={canvasPos:E};var J=n.name;J&&(G.name=J.name,G.path=J.path,G.nodeId=J.nodeId)}if(m.pickRegion&&(F.clear(),this._doDrawList({pickRegion:!0,object:n,clear:!0}),H=F.read(C,D),0!==H[0]||0!==H[1]||0!==H[2]||0!==H[3])){G=G||{canvasPos:E};var K,L,M={r:H[0]/255,g:H[1]/255,b:H[2]/255,a:H[3]/255},N=this._frameCtx.regionData,O=.01,P={};for(y=0,z=N.length;z>y;y++)if(K=N[y].color,M&&N[y].data&&(L=Math.max(Math.abs(M.r-K.r),Math.abs(M.g-K.g),Math.abs(M.b-K.b),Math.abs(M.a-(void 0===K.a?M.a:K.a))),O>L)){P=N[y].data;break}G.color=M,G.regionData=P}if(m.pickTriangle&&n){F.clear(),this._doDrawList({pickTriangle:!0,object:n,clear:!0}),H=F.read(C,D);var Q=H[0]+256*H[1]+256*H[2]*256+256*H[3]*256*256;Q*=3,G.primitiveIndex=Q;var R=n.geometry;if("triangles"===R.primitiveName){G.primitive="triangle",a(A,n,E,b,c);var S=R.arrays.indices,T=S[Q],U=S[Q+1],V=S[Q+2],W=3*T,X=3*U,Y=3*V,Z=SceneJS_math_vec3();Z[0]=T,Z[1]=U,Z[2]=V,G.indices=Z;var $=n.morphGeometry,_=$.targets;if(_&&_.length>0&&_[0].positions)this._lerpTargets($.keys,$.targets,"positions",T,U,V,$.factor,d,e,f);else{var aa=R.arrays.positions;d[0]=aa[W],d[1]=aa[W+1],d[2]=aa[W+2],e[0]=aa[X],e[1]=aa[X+1],e[2]=aa[X+2],f[0]=aa[Y],f[1]=aa[Y+1],f[2]=aa[Y+2]}var ba=G.position=SceneJS_math_rayPlaneIntersect(b,c,d,e,f,SceneJS_math_vec3());o.set(ba),o[3]=1,SceneJS_math_transformVector4(n.modelTransform.matrix,o,p),G.worldPos=p.slice(0,3);var ca=G.barycentric=SceneJS_math_cartesianToBarycentric2(ba,d,e,f,SceneJS_math_vec3()),da=!1;if(_&&_.length>0&&_[0].normals&&(this._lerpTargets($.keys,$.targets,"normals",T,U,V,$.factor,g,h,i),da=!0),!da){var ea=R.arrays.normals;ea&&(g[0]=ea[W],g[1]=ea[W+1],g[2]=ea[W+2],h[0]=ea[X],h[1]=ea[X+1],h[2]=ea[X+2],i[0]=ea[Y],i[1]=ea[Y+1],i[2]=ea[Y+2],da=!0)}da&&(G.normal=SceneJS_math_addVec3(SceneJS_math_addVec3(SceneJS_math_mulVec3Scalar(g,ca[0],q),SceneJS_math_mulVec3Scalar(h,ca[1],r),s),SceneJS_math_mulVec3Scalar(i,ca[2],t),SceneJS_math_vec3()));var fa=R.arrays.uvs;if(fa&&fa.length>0){G.uvs=[];var ga,ha,ia=2*T,ja=2*U,ka=2*V;for(y=0,z=fa.length;z>y;y++)ga=fa[y],ga?(j[0]=ga[ia],j[1]=ga[ia+1],k[0]=ga[ja],k[1]=ga[ja+1],l[0]=ga[ka],l[1]=ga[ka+1],ha=SceneJS_math_addVec3(SceneJS_math_addVec3(SceneJS_math_mulVec2Scalar(j,ca[0],u),SceneJS_math_mulVec2Scalar(k,ca[1],v),w),SceneJS_math_mulVec2Scalar(l,ca[2],x),SceneJS_math_vec3()),G.uvs.push(ha)):ga.push(null);fa.length>0&&(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;ke;e++)this._pickDrawList[e].pick(c);else if(a.pickRegion||a.pickTriangle){if(a.object)for(var g,h=a.object.chunks,e=0,f=h.length;f>e;e++)g=h[e],g&&g.pick&&g.pick(c);else if(a.pickRegion)for(var e=0,f=this._pickDrawListLen;f>e;e++)this._pickDrawList[e].pick(c)}else for(var f=a.opaqueOnly&&this._drawListTransparentIndex>=0?this._drawListTransparentIndex:this._drawListLen,e=0;f>e;e++)this._drawList[e].draw(c);if(b.flush(),c.renderBuf&&c.renderBuf.unbind(),c.VAO){c.VAO.bindVertexArrayOES(null);for(var e=0;10>e;e++)b.disableVertexAttribArray(e)}},SceneJS_Display.prototype.readPixels=function(a,b,c){this._readPixelBuf||(this._readPixelBuf=new SceneJS._webgl.RenderBuffer({canvas:this._canvas})),this._readPixelBuf.bind(),this._readPixelBuf.clear(),this.render({force:!0,opaqueOnly:c});for(var d,e,f=0;b>f;f++)d=a[f]||(a[f]={}),e=this._readPixelBuf.read(d.x,d.y),d.r=e[0],d.g=e[1],d.b=e[2],d.a=e[3];this._readPixelBuf.unbind()},SceneJS_Display.prototype._unpackDepth=function(a){var b=[a[0]/256,a[1]/256,a[2]/256,a[3]/256],c=[1/16777216,1/65536,1/256,1];return SceneJS_math_dotVector4(b,c)},SceneJS_Display.prototype.destroy=function(){this._programFactory.destroy()};var SceneJS_ProgramSourceFactory=new function(){function a(){return l(),m("attribute vec3 SCENEJS_aVertex;"),m("attribute vec4 SCENEJS_aColor;"),m("uniform mat4 SCENEJS_uMMatrix;"),m("uniform mat4 SCENEJS_uVMatrix;"),m("uniform mat4 SCENEJS_uVNMatrix;"),m("uniform mat4 SCENEJS_uPMatrix;"),m("varying vec4 SCENEJS_vWorldVertex;"),G&&(m("attribute vec2 SCENEJS_aRegionMapUV;"),m("varying vec2 SCENEJS_vRegionMapUV;")),F&&(m("uniform float SCENEJS_uMorphFactor;"),p.morphGeometry.targets[0].vertexBuf&&m("attribute vec3 SCENEJS_aMorphVertex;")),m("varying vec4 SCENEJS_vColor;"),m("void main(void) {"),m(" vec4 tmpVertex=vec4(SCENEJS_aVertex, 1.0); "),F&&p.morphGeometry.targets[0].vertexBuf&&m(" tmpVertex = vec4(mix(tmpVertex.xyz, SCENEJS_aMorphVertex, SCENEJS_uMorphFactor), 1.0); "),m(" SCENEJS_vWorldVertex = SCENEJS_uMMatrix * tmpVertex; "),m("mat4 vPosMatrix = SCENEJS_uVMatrix;"),B&&m("vPosMatrix[3].xyz = vec3(0.0);"),m(" gl_Position = SCENEJS_uPMatrix * (vPosMatrix * SCENEJS_vWorldVertex);"),G&&m("SCENEJS_vRegionMapUV = SCENEJS_aRegionMapUV;"),m("SCENEJS_vColor = SCENEJS_aColor;"),m("}"),n()}function b(){if(l(),m("precision "+o(p._canvas.gl)+" float;"),m("varying vec4 SCENEJS_vWorldVertex;"),m("varying vec4 SCENEJS_vColor;"),m("uniform float SCENEJS_uPickMode;"),m("uniform vec4 SCENEJS_uPickColor;"),m("uniform bool SCENEJS_uClipping;"),E)for(var a=0;a 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?!1:e()}function d(){return p.texture.layers&&p.texture.layers.length>0?e():!1}function e(){return p.geometry.uvBufs?!0:p.morphGeometry.targets&&(p.morphGeometry.targets[0].uvBuf||p.morphGeometry.targets[0].uvBuf2)?!0:!1}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?!0:a.morphGeometry.targets&&a.morphGeometry.targets[0].normalBuf?!0:!1}function h(a){if(a.texture){var b=a.texture.layers;if(!b)return!1;for(var c=0,d=b.length;d>c;c++)if("normals"==b[c].applyTo)return!0}return!1}function i(){if(p.renderTarget&&p.renderTarget.targets)for(var a=p.renderTarget.targets,b=0,c=a.length;c>b;b++)if("depth"===a[b].bufType)return!0;return!1}function j(){var a=p.shader.shaders||{};if(a.vertex&&a.vertex.code&&""!=a.vertex.code&&SceneJS._isEmpty(a.vertex.hooks))return[a.vertex.code];var b,c,d=a.vertex||{},e=d.hooks||{},f=a.fragment||{},g=f.hooks||{};if(l(),m("uniform mat4 SCENEJS_uMMatrix;"),m("uniform mat4 SCENEJS_uVMatrix;"),m("uniform mat4 SCENEJS_uPMatrix;"),m("attribute vec3 SCENEJS_aVertex;"),m("uniform vec3 SCENEJS_uWorldEye;"),m("varying vec3 SCENEJS_vViewEyeVec;"),z&&(m("attribute vec3 SCENEJS_aNormal;"),m("uniform mat4 SCENEJS_uMNMatrix;"),m("uniform mat4 SCENEJS_uVNMatrix;"),m("varying vec3 SCENEJS_vViewNormal;"),w&&m("varying vec3 SCENEJS_vWorldNormal;"),D&&(m("attribute vec4 SCENEJS_aTangent;"),m("varying vec3 SCENEJS_vTangent;"))),x&&(c=p.geometry.uvBufs))for(var b=0,h=c.length;h>b;b++)c[b]&&m("attribute vec2 SCENEJS_aUVCoord"+b+";");if(p.geometry.colorBuf&&(m("attribute vec4 SCENEJS_aVertexColor;"),m("varying vec4 SCENEJS_vColor;")),(E||z)&&m("varying vec4 SCENEJS_vWorldVertex;"),m("varying vec4 SCENEJS_vViewVertex;"),x&&(c=p.geometry.uvBufs))for(b=0,h=c.length;h>b;b++)c[b]&&m("varying vec2 SCENEJS_vUVCoord"+b+";");if(H&&(m("attribute vec2 SCENEJS_aRegionMapUV;"),m("varying vec2 SCENEJS_vRegionMapUV;")),F&&(m("uniform float SCENEJS_uMorphFactor;"),p.morphGeometry.targets[0].vertexBuf&&m("attribute vec3 SCENEJS_aMorphVertex;"),z&&p.morphGeometry.targets[0].normalBuf&&m("attribute vec3 SCENEJS_aMorphNormal;"),D&&m("attribute vec3 SCENEJS_aMorphTangent;")),d.code&&m("\n"+d.code+"\n"),C&&(m("void billboard(inout mat4 mat) {"),m(" mat[0][0] = -1.0;"),m(" mat[0][1] = 0.0;"),m(" mat[0][2] = 0.0;"),p.billboard.spherical&&(m(" mat[1][0] = 0.0;"),m(" mat[1][1] = 1.0;"),m(" mat[1][2] = 0.0;")),m(" mat[2][0] = 0.0;"),m(" mat[2][1] = 0.0;"),m(" mat[2][2] =1.0;"),m("}")),m("void main(void) {"),D&&m("vec3 modelTangent = SCENEJS_aTangent.xyz;"),m(" vec4 tmpVertex=vec4(SCENEJS_aVertex, 1.0); "),m(" vec4 modelVertex = tmpVertex; "),z&&m(" vec4 modelNormal = vec4(SCENEJS_aNormal, 0.0); "),F&&(p.morphGeometry.targets[0].vertexBuf&&(m(" vec4 vMorphVertex = vec4(SCENEJS_aMorphVertex, 1.0); "),m(" modelVertex = vec4(mix(modelVertex.xyz, vMorphVertex.xyz, SCENEJS_uMorphFactor), 1.0); ")),z&&p.morphGeometry.targets[0].normalBuf&&(m(" vec4 vMorphNormal = vec4(SCENEJS_aMorphNormal, 1.0); "),m(" modelNormal = vec4( mix(modelNormal.xyz, vMorphNormal.xyz, SCENEJS_uMorphFactor), 1.0); ")),D&&m(" modelTangent = mix(modelTangent, SCENEJS_aMorphTangent, SCENEJS_uMorphFactor); ")),m("mat4 modelMatrix = SCENEJS_uMMatrix;"),m("mat4 viewMatrix = SCENEJS_uVMatrix;"),z&&(m("mat4 modelNormalMatrix = SCENEJS_uMNMatrix;"),m("mat4 viewNormalMatrix = SCENEJS_uVNMatrix;")),m("vec4 worldVertex;"),m("vec4 viewVertex;"),B&&m("viewMatrix[3].xyz = vec3(0.0);"),C?(m(" mat4 modelViewMatrix = viewMatrix * modelMatrix;"),m(" billboard(modelMatrix);"),m(" billboard(viewMatrix);"),m(" billboard(modelViewMatrix);"),z&&(m(" mat4 modelViewNormalMatrix = viewNormalMatrix * modelNormalMatrix;"),m(" billboard(modelNormalMatrix);"),m(" billboard(viewNormalMatrix);"),m(" billboard(modelViewNormalMatrix);")),e.viewMatrix&&m("viewMatrix = "+e.viewMatrix+"(viewMatrix);"),m(" worldVertex = modelMatrix * modelVertex;"),m(" viewVertex = modelViewMatrix * modelVertex;")):(e.viewMatrix&&m("viewMatrix = "+e.viewMatrix+"(viewMatrix);"),m(" worldVertex = modelMatrix * modelVertex;"),m(" viewVertex = viewMatrix * worldVertex; ")),e.viewPos&&m("viewVertex="+e.viewPos+"(viewVertex);"),z&&(m(" vec3 worldNormal = (modelNormalMatrix * modelNormal).xyz; "),m(" SCENEJS_vViewNormal = (viewNormalMatrix * vec4(worldNormal, 1.0)).xyz;"),w&&m(" SCENEJS_vWorldNormal = worldNormal;")),(E||z||g.worldPos)&&m(" SCENEJS_vWorldVertex = worldVertex;"),m(" SCENEJS_vViewVertex = viewVertex;"),m(e.projMatrix?"gl_Position = "+e.projMatrix+"(SCENEJS_uPMatrix) * viewVertex;":" gl_Position = SCENEJS_uPMatrix * viewVertex;"),D&&(m("modelTangent = normalize((viewNormalMatrix * modelNormalMatrix * vec4(modelTangent, 1.0)).xyz);"),m("vec3 bitangent = cross(SCENEJS_vViewNormal, modelTangent);"),m("mat3 TBM = mat3(modelTangent, bitangent, SCENEJS_vViewNormal);"),m("SCENEJS_vTangent = modelTangent;")),m("SCENEJS_vViewEyeVec = ((viewMatrix * vec4(SCENEJS_uWorldEye, 0.0)).xyz - viewVertex.xyz);"),D&&m("SCENEJS_vViewEyeVec *= TBM;"),x&&(c=p.geometry.uvBufs))for(b=0,h=c.length;h>b;b++)c[b]&&m("SCENEJS_vUVCoord"+b+" = SCENEJS_aUVCoord"+b+";");return p.geometry.colorBuf&&m("SCENEJS_vColor = SCENEJS_aVertexColor;"),H&&m("SCENEJS_vRegionMapUV = SCENEJS_aRegionMapUV;"),m("gl_PointSize = 3.0;"),m("}"),n()}function k(){var a=p.shader.shaders||{};if(a.fragment&&a.fragment.code&&""!=a.fragment.code&&SceneJS._isEmpty(a.fragment.hooks))return[a.fragment.code];var b=a.fragment||{},c=b.hooks||{},d=p.fresnel.diffuse,e=p.fresnel.specular,f=p.fresnel.alpha,g=p.fresnel.reflect,h=p.fresnel.emit,i=p.fresnel.fragment;if(l(),m("precision "+o(p._canvas.gl)+" float;"),m("uniform mat4 SCENEJS_uVMatrix;"),(E||z)&&m("varying vec4 SCENEJS_vWorldVertex;"),m("varying vec4 SCENEJS_vViewVertex;"),m("uniform float SCENEJS_uZNear;"),m("uniform float SCENEJS_uZFar;"),m("uniform vec3 SCENEJS_uWorldEye;"),E)for(var j=0;jj;j++)k[j]&&m("varying vec2 SCENEJS_vUVCoord"+j+";");if(x)for(var r,j=0,q=p.texture.layers.length;q>j;j++)r=p.texture.layers[j],m("uniform sampler2D SCENEJS_uSampler"+j+";"),r.matrix&&m("uniform mat4 SCENEJS_uLayer"+j+"Matrix;"),m("uniform float SCENEJS_uLayer"+j+"BlendFactor;")}if(z&&y)for(var r,j=0,q=p.cubemap.layers.length;q>j;j++)r=p.cubemap.layers[j],m("uniform samplerCube SCENEJS_uCubeMapSampler"+j+";"),m("uniform float SCENEJS_uCubeMapIntensity"+j+";");if(H&&(m("varying vec2 SCENEJS_vRegionMapUV;"),m("uniform sampler2D SCENEJS_uRegionMapSampler;"),m("uniform vec3 SCENEJS_uRegionMapRegionColor;"),m("uniform vec3 SCENEJS_uRegionMapHighlightFactor;"),m("uniform float SCENEJS_uRegionMapHideAlpha;")),m("uniform bool SCENEJS_uClipping;"),A&&m("uniform vec3 SCENEJS_uSolidColor;"),m("uniform bool SCENEJS_uDepthMode;"),m("uniform bool SCENEJS_uTransparent;"),p.geometry.colorBuf&&m("varying vec4 SCENEJS_vColor;"),m("uniform vec3 SCENEJS_uAmbientColor;"),m("uniform vec3 SCENEJS_uMaterialColor;"),m("uniform vec3 SCENEJS_uMaterialSpecularColor;"),m("uniform vec3 SCENEJS_uMaterialEmitColor;"),m("uniform float SCENEJS_uMaterialSpecular;"),m("uniform float SCENEJS_uMaterialShine;"),m("uniform float SCENEJS_uMaterialAlpha;"),m("uniform float SCENEJS_uMaterialEmit;"),d&&(m("uniform float SCENEJS_uDiffuseFresnelCenterBias;"),m("uniform float SCENEJS_uDiffuseFresnelEdgeBias;"),m("uniform float SCENEJS_uDiffuseFresnelPower;"),m("uniform vec3 SCENEJS_uDiffuseFresnelCenterColor;"),m("uniform vec3 SCENEJS_uDiffuseFresnelEdgeColor;")),e&&(m("uniform float SCENEJS_uSpecularFresnelCenterBias;"),m("uniform float SCENEJS_uSpecularFresnelEdgeBias;"),m("uniform float SCENEJS_uSpecularFresnelPower;"),m("uniform vec3 SCENEJS_uSpecularFresnelCenterColor;"),m("uniform vec3 SCENEJS_uSpecularFresnelEdgeColor;")),f&&(m("uniform float SCENEJS_uAlphaFresnelCenterBias;"),m("uniform float SCENEJS_uAlphaFresnelEdgeBias;"),m("uniform float SCENEJS_uAlphaFresnelPower;"),m("uniform vec3 SCENEJS_uAlphaFresnelCenterColor;"),m("uniform vec3 SCENEJS_uAlphaFresnelEdgeColor;")),g&&(m("uniform float SCENEJS_uReflectFresnelCenterBias;"),m("uniform float SCENEJS_uReflectFresnelEdgeBias;"),m("uniform float SCENEJS_uReflectFresnelPower;"),m("uniform vec3 SCENEJS_uReflectFresnelCenterColor;"),m("uniform vec3 SCENEJS_uReflectFresnelEdgeColor;")),h&&(m("uniform float SCENEJS_uEmitFresnelCenterBias;"),m("uniform float SCENEJS_uEmitFresnelEdgeBias;"),m("uniform float SCENEJS_uEmitFresnelPower;"),m("uniform vec3 SCENEJS_uEmitFresnelCenterColor;"),m("uniform vec3 SCENEJS_uEmitFresnelEdgeColor;")),i&&(m("uniform float SCENEJS_uFragmentFresnelCenterBias;"),m("uniform float SCENEJS_uFragmentFresnelEdgeBias;"),m("uniform float SCENEJS_uFragmentFresnelPower;"),m("uniform vec3 SCENEJS_uFragmentFresnelCenterColor;"),m("uniform vec3 SCENEJS_uFragmentFresnelEdgeColor;")),m("varying vec3 SCENEJS_vViewEyeVec;"),z){m("uniform mat4 SCENEJS_uVNMatrix;"),m("varying vec3 SCENEJS_vViewNormal;"),w&&m("varying vec3 SCENEJS_vWorldNormal;"),D&&m("varying vec3 SCENEJS_vTangent;");for(var s,j=0;j 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;q>j;j++){r=p.texture.layers[j];var t=r.applyFrom;if("normal"==t&&z){if(!p.geometry.normalBuf){SceneJS.log.warn("Texture layer applyFrom='normal' but geo has no normal vectors");continue}m("texturePos=vec4(viewNormalVec.xyz, 1.0);")}else{var u=t.match(/\d+$/),v=u?parseInt(u[0]):0,k=p.geometry.uvBufs;if(!k[v]){SceneJS.log.warn("Texture layer applyTo='uv' but geometry has no UV coordinates for layer "+v);continue}m("texturePos = vec4(SCENEJS_vUVCoord"+v+".s, SCENEJS_vUVCoord"+v+".t, 1.0, 1.0);")}m(r.matrix?"textureCoord=(SCENEJS_uLayer"+j+"Matrix * texturePos).xy;":"textureCoord=texturePos.xy;"),"alpha"==r.applyTo&&("multiply"==r.blendMode?m("alpha = alpha * (SCENEJS_uLayer"+j+"BlendFactor * texture2D(SCENEJS_uSampler"+j+", vec2(textureCoord.x, 1.0 - textureCoord.y)).b);"):"add"==r.blendMode&&m("alpha = ((1.0 - SCENEJS_uLayer"+j+"BlendFactor) * alpha) + (SCENEJS_uLayer"+j+"BlendFactor * texture2D(SCENEJS_uSampler"+j+", vec2(textureCoord.x, 1.0 - textureCoord.y)).b);")),"baseColor"==r.applyTo&&m("multiply"==r.blendMode?"color = color * (SCENEJS_uLayer"+j+"BlendFactor * texture2D(SCENEJS_uSampler"+j+", vec2(textureCoord.x, 1.0 - textureCoord.y)).rgb);":"color = ((1.0 - SCENEJS_uLayer"+j+"BlendFactor) * color) + (SCENEJS_uLayer"+j+"BlendFactor * texture2D(SCENEJS_uSampler"+j+", vec2(textureCoord.x, 1.0 - textureCoord.y)).rgb);"),"emit"==r.applyTo&&m("multiply"==r.blendMode?"emit = emit * (SCENEJS_uLayer"+j+"BlendFactor * texture2D(SCENEJS_uSampler"+j+", vec2(textureCoord.x, 1.0 - textureCoord.y)).r);":"emit = ((1.0 - SCENEJS_uLayer"+j+"BlendFactor) * emit) + (SCENEJS_uLayer"+j+"BlendFactor * texture2D(SCENEJS_uSampler"+j+", vec2(textureCoord.x, 1.0 - textureCoord.y)).r);"),"specular"==r.applyTo&&z&&m("multiply"==r.blendMode?"specular = specular * (SCENEJS_uLayer"+j+"BlendFactor * texture2D(SCENEJS_uSampler"+j+", vec2(textureCoord.x, 1.0 - textureCoord.y)).r);":"specular = ((1.0 - SCENEJS_uLayer"+j+"BlendFactor) * specular) + (SCENEJS_uLayer"+j+"BlendFactor * texture2D(SCENEJS_uSampler"+j+", vec2(textureCoord.x, 1.0 - textureCoord.y)).r);"),"shine"==r.applyTo&&m("multiply"==r.blendMode?"shine = shine * (SCENEJS_uLayer"+j+"BlendFactor * texture2D(SCENEJS_uSampler"+j+", vec2(textureCoord.x, 1.0 - textureCoord.y)).r);":"shine = ((1.0 - SCENEJS_uLayer"+j+"BlendFactor) * shine) + (SCENEJS_uLayer"+j+"BlendFactor * texture2D(SCENEJS_uSampler"+j+", vec2(textureCoord.x, 1.0 - textureCoord.y)).r);"),"normals"==r.applyTo&&z&&m("viewNormalVec = normalize(texture2D(SCENEJS_uSampler"+j+", vec2(textureCoord.x, -textureCoord.y)).xyz * 2.0 - 1.0);")}if(z&&y){m("float reflectFactor = 1.0;"),g&&(m("float reflectFresnel = fresnel(worldEyeVec, worldNormal, SCENEJS_uReflectFresnelEdgeBias, SCENEJS_uReflectFresnelCenterBias, SCENEJS_uReflectFresnelPower);"),m("reflectFactor *= mix(SCENEJS_uReflectFresnelEdgeColor.b, SCENEJS_uReflectFresnelCenterColor.b, reflectFresnel);")),m("vec4 v = SCENEJS_uVNMatrix * vec4(SCENEJS_vViewEyeVec, 1.0);"),m("vec3 v1 = v.xyz;"),m("v = SCENEJS_uVNMatrix * vec4(viewNormalVec, 1.0);"),m("vec3 v2 = v.xyz;"),m("vec3 envLookup = reflect(v1, v2);"),m("envLookup.y = envLookup.y * -1.0;"),m("vec4 envColor;");for(var j=0,q=p.cubemap.layers.length;q>j;j++)r=p.cubemap.layers[j],m("envColor = textureCube(SCENEJS_uCubeMapSampler"+j+", envLookup);"),m("color = mix(color, envColor.rgb, reflectFactor * specular * SCENEJS_uCubeMapIntensity"+j+");")}if(m(" vec4 fragColor;"),z){m(" vec3 lightValue = vec3(0.0, 0.0, 0.0);"),m(" vec3 specularValue = vec3(0.0, 0.0, 0.0);"),m(" vec3 viewLightVec;"),m(" float dotN;"),m(" float lightDist;"),D&&(m("vec3 tangent = normalize(SCENEJS_vTangent);"),m("vec3 bitangent = cross(SCENEJS_vViewNormal, tangent);"),m("mat3 TBM = mat3(tangent, bitangent, SCENEJS_vViewNormal);"));for(var s,j=0,q=p.lights.lights.length;q>j;j++)s=p.lights.lights[j],"ambient"!=s.mode&&("point"==s.mode&&("world"==s.space?(m("viewLightVec = SCENEJS_uLightPos"+j+" - SCENEJS_vWorldVertex.xyz;"),m("viewLightVec = vec3(SCENEJS_uVMatrix * vec4(viewLightVec, 0.0)).xyz;"),D&&m("viewLightVec *= TBM;")):(m("viewLightVec = SCENEJS_uLightPos"+j+".xyz - SCENEJS_vViewVertex.xyz;"),D&&m("viewLightVec *= TBM;")),m("dotN = max(dot(viewNormalVec, normalize(viewLightVec)), 0.0);"),m("lightDist = length( SCENEJS_uLightPos"+j+" - SCENEJS_vWorldVertex.xyz);"),m("attenuation = 1.0 - ( SCENEJS_uLightAttenuation"+j+"[0] + SCENEJS_uLightAttenuation"+j+"[1] * lightDist + SCENEJS_uLightAttenuation"+j+"[2] * lightDist * lightDist);"),s.diffuse&&m(" lightValue += dotN * SCENEJS_uLightColor"+j+" * attenuation;"),s.specular&&m(" specularValue += specularColor * SCENEJS_uLightColor"+j+" * specular * pow(max(dot(reflect(normalize(-viewLightVec), normalize(-viewNormalVec)), normalize(-SCENEJS_vViewVertex.xyz)), 0.0), shine) * attenuation;")),"dir"==s.mode&&("world"==s.space?(m("viewLightVec = normalize(SCENEJS_uLightDir"+j+");"),m("viewLightVec = vec3(SCENEJS_uVMatrix * vec4(viewLightVec, 0.0)).xyz;"),D&&m("viewLightVec *= TBM;")):(m("viewLightVec = normalize(SCENEJS_uLightDir"+j+");"),D&&m("viewLightVec *= TBM;")),m("viewLightVec = -viewLightVec;"),m("dotN = max(dot(viewNormalVec, normalize(viewLightVec)), 0.0);"),s.diffuse&&m("lightValue += dotN * SCENEJS_uLightColor"+j+";"),s.specular&&m("specularValue += specularColor * SCENEJS_uLightColor"+j+" * specular * pow(max(dot(reflect(normalize(-viewLightVec), normalize(-viewNormalVec)), normalize(-SCENEJS_vViewVertex.xyz)), 0.0), shine);")));p.geometry.colorBuf&&m("alpha *= colorA;"),(d||e||f||h)&&(d&&(m("float diffuseFresnel = fresnel(worldEyeVec, worldNormal, SCENEJS_uDiffuseFresnelEdgeBias, SCENEJS_uDiffuseFresnelCenterBias, SCENEJS_uDiffuseFresnelPower);"),m("color.rgb *= mix(SCENEJS_uDiffuseFresnelEdgeColor.rgb, SCENEJS_uDiffuseFresnelCenterColor.rgb, diffuseFresnel);")),e&&(m("float specFresnel = fresnel(worldEyeVec, worldNormal, SCENEJS_uSpecularFresnelEdgeBias, SCENEJS_uSpecularFresnelCenterBias, SCENEJS_uSpecularFresnelPower);"),m("specularValue *= mix(SCENEJS_uSpecularFresnelEdgeColor.rgb, SCENEJS_uSpecularFresnelCenterColor.rgb, specFresnel);")),f&&(m("float alphaFresnel = fresnel(worldEyeVec, worldNormal, SCENEJS_uAlphaFresnelEdgeBias, SCENEJS_uAlphaFresnelCenterBias, SCENEJS_uAlphaFresnelPower);"),m("alpha *= mix(SCENEJS_uAlphaFresnelEdgeColor.r, SCENEJS_uAlphaFresnelCenterColor.r, alphaFresnel);")),h&&(m("float emitFresnel = fresnel(worldEyeVec, worldNormal, SCENEJS_uEmitFresnelEdgeBias, SCENEJS_uEmitFresnelCenterBias, SCENEJS_uEmitFresnelPower);"),m("emitColor.rgb *= mix(SCENEJS_uEmitFresnelEdgeColor.rgb, SCENEJS_uEmitFresnelCenterColor.rgb, emitFresnel);"))),m("fragColor = vec4((specularValue.rgb + color.rgb * (lightValue.rgb + ambient.rgb)) + (emit * emitColor.rgb), alpha);")}else m("fragColor = vec4((color.rgb + (emit * color.rgb)) * (vec3(1.0, 1.0, 1.0) + ambient.rgb), alpha);");return H&&(m("vec3 regionColor = texture2D(SCENEJS_uRegionMapSampler, vec2(SCENEJS_vRegionMapUV.s, 1.0 - SCENEJS_vRegionMapUV.t)).rgb;"),m("float tolerance = 0.01;"),m("vec3 colorDelta = abs(SCENEJS_uRegionMapRegionColor - regionColor);"),"highlight"===p.regionMap.mode||"hide"===p.regionMap.mode?(m("if (max(colorDelta.x, max(colorDelta.y, colorDelta.z)) < tolerance) {"),m("highlight"===p.regionMap.mode?" fragColor.rgb *= SCENEJS_uRegionMapHighlightFactor;":" fragColor.a = SCENEJS_uRegionMapHideAlpha;"),m("}")):(m("if (max(colorDelta.x, max(colorDelta.y, colorDelta.z)) > 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(){K=[]}function m(a){K.push(a||"")}function n(){return K}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="";this.getSource=function(e,l){var m=J[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(),m=new SceneJS_ProgramSource(e,a(p),b(p),j(p),k(p)),J[e]=m,m)},this.putSource=function(a){var b=J[a];b&&0==--b.useCount&&(J[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){this._canvas=a.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._nextProgramId++,a,d,this._canvas.gl),this._programs[a]=c}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])},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){this.id=a,this.hash=c.hash,this.source=c,this.gl=d,this.draw=null,this.pick=null,this.useCount=0,this.build(d)};SceneJS_Program.prototype.build=function(a){this.gl=a,this.draw=new SceneJS._webgl.Program(a,[this.source.drawVertexSrc.join("\n")],[this.source.drawFragmentSrc.join("\n")]),this.pick=new SceneJS._webgl.Program(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.sortKey=null,this.chunks=[],this.chunksLen=0,this.program=null,this.layer=null,this.texture=null,this.flags=null,this.tag=null};SceneJS.RenderContext=function(a){this._frameCtx=a},SceneJS.RenderContext.prototype.getCameraMatrix=function(){return this._frameCtx.cameraMat},SceneJS.RenderContext.prototype.getViewMatrix=function(){return this._frameCtx.viewMat},SceneJS.RenderContext.prototype.getModelMatrix=function(){return this._frameCtx.modelMat},SceneJS.RenderContext.prototype.getCanvasPos=function(a){this.getProjPos(a);var b=this._frameCtx.canvas.canvas,c=this._frameCtx.canvas.resolutionScaling,d=b.width/c,e=b.height/c,f=this._pc,g=f[0]/f[3]*d*.5,h=f[1]/f[3]*e*.5; +return{x:g+.5*d,y:e-h-.5*e}},SceneJS.RenderContext.prototype.getCameraPos=function(a){return this.getProjPos(a),this._camPos=SceneJS_math_normalizeVec3(this._pc,[0,0,0]),{x:this._camPos[0],y:this._camPos[1],z:this._camPos[2]}},SceneJS.RenderContext.prototype.getProjPos=function(a){return this.getViewPos(a),this._pc=SceneJS_math_transformPoint3(this._frameCtx.cameraMat,this._vc),{x:this._pc[0],y:this._pc[1],z:this._pc[2],w:this._pc[3]}},SceneJS.RenderContext.prototype.getViewPos=function(a){return this.getWorldPos(a),this._vc=SceneJS_math_transformPoint3(this._frameCtx.viewMat,this._wc),{x:this._vc[0],y:this._vc[1],z:this._vc[2],w:this._vc[3]}},SceneJS.RenderContext.prototype.getWorldPos=function(a){return this._wc=SceneJS_math_transformPoint3(this._frameCtx.modelMat,a||[0,0,0]),{x:this._wc[0],y:this._wc[1],z:this._wc[2],w:this._wc[3]}};var SceneJS_Chunk=function(){};SceneJS_Chunk.prototype.init=function(a,b,c,d){this.id=a,this.program=b,this.core=c,this.core2=d,this.build&&this.build()};var SceneJS_ChunkFactory=function(){this._chunks={},this.chunkTypes=SceneJS_ChunkFactory.chunkTypes};SceneJS_ChunkFactory.chunkTypes={},SceneJS_ChunkFactory._freeChunks={},SceneJS_ChunkFactory.createChunkType=function(a){if(!a.type)throw"'type' expected in params";var b=SceneJS_Chunk,c=function(){this.useCount=0,this.init.apply(this,arguments)};return c.prototype=new b,c.prototype.constructor=c,a.drawAndPick&&(a.draw=a.pick=a.drawAndPick),SceneJS_ChunkFactory.chunkTypes[a.type]=c,SceneJS._apply(a,c.prototype),SceneJS_ChunkFactory._freeChunks[a.type]={chunks:[],chunksLen:0},c},SceneJS_ChunkFactory.prototype.getChunk=function(a,b,c,d,e){var f=SceneJS_ChunkFactory.chunkTypes[b];if(!f)throw"chunk type not supported: '"+b+"'";var g=this._chunks[a];return g?(g.useCount++,g):(g=new f(a,c,d,e),g.type=b,g.useCount=1,this._chunks[a]=g,g)},SceneJS_ChunkFactory.prototype.putChunk=function(a){0!=a.useCount&&--a.useCount<=0&&(a.recycle&&a.recycle(),delete this._chunks[a.id])},SceneJS_ChunkFactory.prototype.webglRestored=function(){var a;for(var b in this._chunks)this._chunks.hasOwnProperty(b)&&(a=this._chunks[b],a&&a.build&&a.build())},SceneJS_ChunkFactory.createChunkType({type:"camera",build:function(){this._uPMatrixDraw=this.program.draw.getUniform("SCENEJS_uPMatrix"),this._uZNearDraw=this.program.draw.getUniform("SCENEJS_uZNear"),this._uZFarDraw=this.program.draw.getUniform("SCENEJS_uZFar"),this._uPMatrixPick=this.program.pick.getUniform("SCENEJS_uPMatrix"),this._uZNearPick=this.program.pick.getUniform("SCENEJS_uZNear"),this._uZFarPick=this.program.pick.getUniform("SCENEJS_uZFar")},draw:function(a){this.core.checkAspect&&this.core.checkAspect(this.core,a.aspect);this.program.gl;this._uPMatrixDraw&&this._uPMatrixDraw.setValue(this.core.mat),this._uZNearDraw&&this._uZNearDraw.setValue(this.core.optics.near),this._uZFarDraw&&this._uZFarDraw.setValue(this.core.optics.far),a.cameraMat=this.core.mat},pick:function(a){this.core.checkAspect&&this.core.checkAspect(this.core,a.aspect);this.program.gl;this._uPMatrixPick&&this._uPMatrixPick.setValue(this.core.mat),a.rayPick&&(this._uZNearPick&&this._uZNearPick.setValue(this.core.optics.near),this._uZFarPick&&this._uZFarPick.setValue(this.core.optics.far)),a.cameraMat=this.core.mat}}),SceneJS_ChunkFactory.createChunkType({type:"clips",build:function(){this._draw=this._draw||[];for(var a=this.program.draw,b=0,c=this.core.clips.length;c>b;b++)this._draw[b]={uClipMode:a.getUniform("SCENEJS_uClipMode"+b),uClipNormalAndDist:a.getUniform("SCENEJS_uClipNormalAndDist"+b)};this._pick=this._pick||[];for(var d=this.program.pick,b=0,c=this.core.clips.length;c>b;b++)this._pick[b]={uClipMode:d.getUniform("SCENEJS_uClipMode"+b),uClipNormalAndDist:d.getUniform("SCENEJS_uClipNormalAndDist"+b)}},drawAndPick:function(a){for(var b,c,d,e=a.picking,f=e?this._pick:this._draw,g=this.core.clips,h=(this.program.gl,0),i=g.length;i>h;h++)e?(b=f[h].uClipMode,c=f[h].uClipNormalAndDist):(b=f[h].uClipMode,c=f[h].uClipNormalAndDist),b&&c&&(d=g[h],"inside"==d.mode?(b.setValue(2),c.setValue(d.normalAndDist)):"outside"==d.mode?(b.setValue(1),c.setValue(d.normalAndDist)):b.setValue(0))}}),SceneJS_ChunkFactory.createChunkType({type:"draw",unique:!0,build:function(){this._depthModeDraw=this.program.draw.getUniform("SCENEJS_uDepthMode"),this._uPickColor=this.program.pick.getUniform("SCENEJS_uPickColor")},draw:function(a){var b=this.core,c=this.program.gl;this._depthModeDraw&&this._depthModeDraw.setValue(a.depthMode),c.drawElements(b.primitive,b.indexBuf.numItems,b.indexBuf.itemType,0)},pick:function(a){var b=this.core,c=this.program.gl;if(a.pickObject||a.pickRegion){if(a.pickObject&&this._uPickColor){var d=a.pickIndex>>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])}c.drawElements(b.primitive,b.indexBuf.numItems,b.indexBuf.itemType,0)}else if(a.pickTriangle){var h=b.getPickIndices();h&&c.drawElements(b.primitive,h.numItems,h.itemType,0)}}}),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)}}}),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|b.STENCIL_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;1e3>c&&(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");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.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)):this._aVertexDraw&&this._aVertexDraw.bindFloatArrayBuffer(this.core2.vertexBuf),this._aMorphNormalDraw?(this._aNormalDraw.bindFloatArrayBuffer(d.normalBuf),this._aMorphNormalDraw.bindFloatArrayBuffer(e.normalBuf)):this._aNormalDraw&&this._aNormalDraw.bindFloatArrayBuffer(this.core2.normalBuf),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]))):this._aTangentDraw)}for(var g,h=0,i=this._aUVDraw.length;i>h;h++)g=this.core2.uvBufs[h],g&&this._aUVDraw[h].bindFloatArrayBuffer(g);this._aColorDraw&&this._aColorDraw.bindFloatArrayBuffer(this.core2.colorBuf),this.setDrawMorphFactor()},setDrawMorphFactor:function(){this._uMorphFactorDraw&&this._uMorphFactorDraw.setValue(this.core.factor)},draw:function(a){var b=this.core.targets&&this.core.targets.length,c=this.core2.interleavedBuf&&!this.core2.interleavedBuf.dirty;if(this.VAO&&a.VAO){if(a.VAO.bindVertexArrayOES(this.VAO),b){if(this.VAOMorphKey1==this.core.key1&&this.VAOMorphKey2==this.core.key2)return void this.setDrawMorphFactor()}else if(c||!this.VAOHasInterleavedBuf)return}else a.VAO&&(a.VAO.bindVertexArrayOES(null),this.VAO=a.VAO.createVertexArrayOES(),a.VAO.bindVertexArrayOES(this.VAO));if(b)this.morphDraw(a);else{if(c){this.VAOHasInterleavedBuf=!0,this.core2.interleavedBuf.bind(),this._aVertexDraw&&this._aVertexDraw.bindInterleavedFloatArrayBuffer(3,this.core2.interleavedStride,this.core2.interleavedPositionOffset),this._aNormalDraw&&this._aNormalDraw.bindInterleavedFloatArrayBuffer(3,this.core2.interleavedStride,this.core2.interleavedNormalOffset);for(var d=0,e=this._aUVDraw.length;e>d;d++)this._aUVDraw[d].bindInterleavedFloatArrayBuffer(2,this.core2.interleavedStride,this.core2.interleavedUVOffsets[d]);this._aColorDraw&&this._aColorDraw.bindInterleavedFloatArrayBuffer(4,this.core2.interleavedStride,this.core2.interleavedColorOffset)}else{this.VAOHasInterleavedBuf=!1,this._aVertexDraw&&this._aVertexDraw.bindFloatArrayBuffer(this.core2.vertexBuf),this._aNormalDraw&&this._aNormalDraw.bindFloatArrayBuffer(this.core2.normalBuf);for(var f,d=0,e=this._aUVDraw.length;e>d;d++)f=this.core2.uvBufs[d],f&&this._aUVDraw[d].bindFloatArrayBuffer(f);this._aColorDraw&&this._aColorDraw.bindFloatArrayBuffer(this.core2.colorBuf)}if(this._aTangentDraw){var g=a.normalMapUVLayerIdx;g>=0&&this._aTangentDraw.bindFloatArrayBuffer(this.core2.getTangents(g))}}if(this._aRegionMapUVDraw){var h=a.regionMapUVLayerIdx;if(h>=0){var i=this.core2.uvBufs;hc;c++)switch(a[c].mode){case"ambient":this._uAmbientColor[c]=b.draw.getUniform("SCENEJS_uAmbientColor");break;case"dir":this._uLightColor[c]=b.draw.getUniform("SCENEJS_uLightColor"+c),this._uLightPos[c]=null,this._uLightDir[c]=b.draw.getUniform("SCENEJS_uLightDir"+c);break;case"point":this._uLightColor[c]=b.draw.getUniform("SCENEJS_uLightColor"+c),this._uLightPos[c]=b.draw.getUniform("SCENEJS_uLightPos"+c),this._uLightDir[c]=null,this._uLightAttenuation[c]=b.draw.getUniform("SCENEJS_uLightAttenuation"+c)}},draw:function(a){a.dirty&&this.build();for(var b,c=this.core.lights,d=(this.program.gl,0),e=c.length;e>d;d++)b=c[d],this._uAmbientColor[d]?this._uAmbientColor[d].setValue(b.color):(this._uLightColor[d]&&this._uLightColor[d].setValue(b.color),this._uLightPos[d]&&(this._uLightPos[d].setValue(b.pos),this._uLightAttenuation[d]&&this._uLightAttenuation[d].setValue(b.attenuation)),this._uLightDir[d]&&this._uLightDir[d].setValue(b.dir))}}),SceneJS_ChunkFactory.createChunkType({type:"listeners",programGlobal:!0,build:function(){},draw:function(a){for(var b=this.core.listeners,c=a.renderListenerCtx,d=b.length-1;d>=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._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),a.viewMat=this.core.mat},pick:function(a){this.program.gl;this._uvMatrixPick&&this._uvMatrixPick.setValue(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;10>d;d++)c.disableVertexAttribArray(d);a.drawProgram=this.program.draw},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;10>d;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:"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;g>f;f++){c=b[f];for(d in c)c.hasOwnProperty(d)&&e.setUniform(d,c[d])}}}),SceneJS_ChunkFactory.createChunkType({type:"shaderParams",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;g>f;f++){c=b[f];for(d in c)c.hasOwnProperty(d)&&e.setUniform(d,c[d])}}}),SceneJS_ChunkFactory.createChunkType({type:"style",programGlobal:!0,drawAndPick:function(a){var b=this.core.lineWidth;if(a.lineWidth!=b){var c=this.program.gl;c.lineWidth(b),a.lineWidth=b}}}),SceneJS_ChunkFactory.createChunkType({type:"texture",build:function(){this._uTexSampler=this._uTexSampler||[],this._uTexMatrix=this._uTexMatrix||[],this._uTexBlendFactor=this._uTexBlendFactor||[];var a=this.core.layers;if(a)for(var b,c=this.program.draw,d=0,e=a.length;e>d;d++)b=a[d],this._uTexSampler[d]="SCENEJS_uSampler"+d,this._uTexMatrix[d]=c.getUniform("SCENEJS_uLayer"+d+"Matrix"),this._uTexBlendFactor[d]=c.getUniform("SCENEJS_uLayer"+d+"BlendFactor")},draw:function(a){a.textureUnit=0,a.normalMapUVLayerIdx=-1;var b=this.core.layers;if(b)for(var c,d=this.program.draw,e=0,f=b.length;f>e;e++)c=b[e],this._uTexSampler[e]&&c.texture&&(d.bindTexture(this._uTexSampler[e],c.texture,a.textureUnit),a.textureUnit=(a.textureUnit+1)%SceneJS.WEBGL_INFO.MAX_TEXTURE_UNITS,c._matrixDirty&&c.buildMatrix&&c.buildMatrix.call(c),this._uTexMatrix[e]&&this._uTexMatrix[e].setValue(c.matrixAsArray),this._uTexBlendFactor[e]&&this._uTexBlendFactor[e].setValue(c.blendFactor),c.isNormalMap&&(a.normalMapUVLayerIdx=c.uvLayerIdx));a.texture=this.core}}),SceneJS_ChunkFactory.createChunkType({type:"fresnel",build:function(){var a=this.program.draw,b=this.core;b.diffuse&&(this._uDiffuseFresnelCenterBias=a.getUniform("SCENEJS_uDiffuseFresnelCenterBias"),this._uDiffuseFresnelEdgeBias=a.getUniform("SCENEJS_uDiffuseFresnelEdgeBias"),this._uDiffuseFresnelPower=a.getUniform("SCENEJS_uDiffuseFresnelPower"),this._uDiffuseFresnelCenterColor=a.getUniform("SCENEJS_uDiffuseFresnelCenterColor"),this._uDiffuseFresnelEdgeColor=a.getUniform("SCENEJS_uDiffuseFresnelEdgeColor")),b.specular&&(this._uSpecularFresnelCenterBias=a.getUniform("SCENEJS_uSpecularFresnelCenterBias"),this._uSpecularFresnelEdgeBias=a.getUniform("SCENEJS_uSpecularFresnelEdgeBias"),this._uSpecularFresnelPower=a.getUniform("SCENEJS_uSpecularFresnelPower"),this._uSpecularFresnelCenterColor=a.getUniform("SCENEJS_uSpecularFresnelCenterColor"),this._uSpecularFresnelEdgeColor=a.getUniform("SCENEJS_uSpecularFresnelEdgeColor")),b.alpha&&(this._uAlphaFresnelCenterBias=a.getUniform("SCENEJS_uAlphaFresnelCenterBias"),this._uAlphaFresnelEdgeBias=a.getUniform("SCENEJS_uAlphaFresnelEdgeBias"),this._uAlphaFresnelPower=a.getUniform("SCENEJS_uAlphaFresnelPower"),this._uAlphaFresnelCenterColor=a.getUniform("SCENEJS_uAlphaFresnelCenterColor"),this._uAlphaFresnelEdgeColor=a.getUniform("SCENEJS_uAlphaFresnelEdgeColor")),b.reflect&&(this._uReflectFresnelCenterBias=a.getUniform("SCENEJS_uReflectFresnelCenterBias"),this._uReflectFresnelEdgeBias=a.getUniform("SCENEJS_uReflectFresnelEdgeBias"),this._uReflectFresnelPower=a.getUniform("SCENEJS_uReflectFresnelPower"),this._uReflectFresnelCenterColor=a.getUniform("SCENEJS_uReflectFresnelCenterColor"),this._uReflectFresnelEdgeColor=a.getUniform("SCENEJS_uReflectFresnelEdgeColor")),b.emit&&(this._uEmitFresnelCenterBias=a.getUniform("SCENEJS_uEmitFresnelCenterBias"),this._uEmitFresnelEdgeBias=a.getUniform("SCENEJS_uEmitFresnelEdgeBias"),this._uEmitFresnelPower=a.getUniform("SCENEJS_uEmitFresnelPower"),this._uEmitFresnelCenterColor=a.getUniform("SCENEJS_uEmitFresnelCenterColor"),this._uEmitFresnelEdgeColor=a.getUniform("SCENEJS_uEmitFresnelEdgeColor")),b.fragment&&(this._uFragmentFresnelCenterBias=a.getUniform("SCENEJS_uFragmentFresnelCenterBias"),this._uFragmentFresnelEdgeBias=a.getUniform("SCENEJS_uFragmentFresnelEdgeBias"),this._uFragmentFresnelPower=a.getUniform("SCENEJS_uFragmentFresnelPower"),this._uFragmentFresnelCenterColor=a.getUniform("SCENEJS_uFragmentFresnelCenterColor"),this._uFragmentFresnelEdgeColor=a.getUniform("SCENEJS_uFragmentFresnelEdgeColor"))},draw:function(){var a=(this.program.gl,this.core);a.diffuse&&(this._uDiffuseFresnelCenterBias&&this._uDiffuseFresnelCenterBias.setValue(a.diffuse.centerBias),this._uDiffuseFresnelEdgeBias&&this._uDiffuseFresnelEdgeBias.setValue(a.diffuse.edgeBias),this._uDiffuseFresnelPower&&this._uDiffuseFresnelPower.setValue(a.diffuse.power),this._uDiffuseFresnelCenterColor&&this._uDiffuseFresnelCenterColor.setValue(a.diffuse.centerColor),this._uDiffuseFresnelEdgeColor&&this._uDiffuseFresnelEdgeColor.setValue(a.diffuse.edgeColor)),a.specular&&(this._uSpecularFresnelCenterBias&&this._uSpecularFresnelCenterBias.setValue(a.specular.centerBias),this._uSpecularFresnelEdgeBias&&this._uSpecularFresnelEdgeBias.setValue(a.specular.edgeBias),this._uSpecularFresnelPower&&this._uSpecularFresnelPower.setValue(a.specular.power),this._uSpecularFresnelCenterColor&&this._uSpecularFresnelCenterColor.setValue(a.specular.centerColor),this._uSpecularFresnelEdgeColor&&this._uSpecularFresnelEdgeColor.setValue(a.specular.edgeColor)),a.alpha&&(this._uAlphaFresnelCenterBias&&this._uAlphaFresnelCenterBias.setValue(a.alpha.centerBias),this._uAlphaFresnelEdgeBias&&this._uAlphaFresnelEdgeBias.setValue(a.alpha.edgeBias),this._uAlphaFresnelPower&&this._uAlphaFresnelPower.setValue(a.alpha.power),this._uAlphaFresnelCenterColor&&this._uAlphaFresnelCenterColor.setValue(a.alpha.centerColor),this._uAlphaFresnelEdgeColor&&this._uAlphaFresnelEdgeColor.setValue(a.alpha.edgeColor)),a.reflect&&(this._uReflectFresnelCenterBias&&this._uReflectFresnelCenterBias.setValue(a.reflect.centerBias),this._uReflectFresnelEdgeBias&&this._uReflectFresnelEdgeBias.setValue(a.reflect.edgeBias),this._uReflectFresnelPower&&this._uReflectFresnelPower.setValue(a.reflect.power),this._uReflectFresnelCenterColor&&this._uReflectFresnelCenterColor.setValue(a.reflect.centerColor),this._uReflectFresnelEdgeColor&&this._uReflectFresnelEdgeColor.setValue(a.reflect.edgeColor)),a.emit&&(this._uEmitFresnelCenterBias&&this._uEmitFresnelCenterBias.setValue(a.emit.centerBias),this._uEmitFresnelEdgeBias&&this._uEmitFresnelEdgeBias.setValue(a.emit.edgeBias),this._uEmitFresnelPower&&this._uEmitFresnelPower.setValue(a.emit.power),this._uEmitFresnelCenterColor&&this._uEmitFresnelCenterColor.setValue(a.emit.centerColor),this._uEmitFresnelEdgeColor&&this._uEmitFresnelEdgeColor.setValue(a.emit.edgeColor)),a.fragment&&(this._uFragmentFresnelCenterBias&&this._uFragmentFresnelCenterBias.setValue(a.fragment.centerBias),this._uFragmentFresnelEdgeBias&&this._uFragmentFresnelEdgeBias.setValue(a.fragment.edgeBias),this._uFragmentFresnelPower&&this._uFragmentFresnelPower.setValue(a.fragment.power),this._uFragmentFresnelCenterColor&&this._uFragmentFresnelCenterColor.setValue(a.fragment.centerColor),this._uFragmentFresnelEdgeColor&&this._uFragmentFresnelEdgeColor.setValue(a.fragment.edgeColor))}}),SceneJS_ChunkFactory.createChunkType({type:"cubemap",build:function(){this._uCubeMapSampler=this._uCubeMapSampler||[],this._uCubeMapIntensity=this._uCubeMapIntensity||[];var a=this.core.layers;if(a)for(var b,c=this.program.draw,d=0,e=a.length;e>d;d++)b=a[d],this._uCubeMapSampler[d]="SCENEJS_uCubeMapSampler"+d,this._uCubeMapIntensity[d]=c.getUniform("SCENEJS_uCubeMapIntensity"+d)},draw:function(a){var b=this.core.layers;if(b)for(var c,d=this.program.draw,e=0,f=b.length;f>e;e++)c=b[e],this._uCubeMapSampler[e]&&c.texture&&(d.bindTexture(this._uCubeMapSampler[e],c.texture,a.textureUnit),a.textureUnit=(a.textureUnit+1)%SceneJS.WEBGL_INFO.MAX_TEXTURE_UNITS,this._uCubeMapIntensity[e]&&this._uCubeMapIntensity[e].setValue(c.intensity))}}),SceneJS_ChunkFactory.createChunkType({type:"xform",build:function(){var a=this.program.draw;this._uMatLocationDraw=a.getUniform("SCENEJS_uMMatrix"),this._uNormalMatLocationDraw=a.getUniform("SCENEJS_uMNMatrix");var b=this.program.pick;this._uMatLocationPick=b.getUniform("SCENEJS_uMMatrix")},draw:function(a){(SceneJS_configsModule.configs.forceXFormCoreRebuild===!0||this.core.dirty&&this.core.build)&&this.core.build();this.program.gl;this._uMatLocationDraw&&this._uMatLocationDraw.setValue(this.core.mat),this._uNormalMatLocationDraw&&this._uNormalMatLocationDraw.setValue(this.core.normalMat),a.modelMat=this.core.mat},pick:function(a){this.core.dirty&&this.core.build();this.program.gl;this._uMatLocationPick&&this._uMatLocationPick.setValue(this.core.mat),a.modelMat=this.core.mat}}); \ No newline at end of file