diff --git a/Gruntfile.js b/Gruntfile.js index 3cba60ae..01bccb11 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -44,11 +44,11 @@ module.exports = function (grunt) { copy: { minified: { src: '<%= build_dir %>/<%= PROJECT_NAME %>-<%= ENGINE_VERSION %>.min.js', - dest: 'build/<%= PROJECT_NAME %>.min.js' + dest: 'api/latest/<%= PROJECT_NAME %>.min.js' }, unminified: { src: '<%= build_dir %>/<%= PROJECT_NAME %>-<%= ENGINE_VERSION %>.js', - dest: 'build/<%= PROJECT_NAME %>.js' + dest: 'api/latest/<%= PROJECT_NAME %>.js' } } }); diff --git a/api/latest/scenejs.js b/api/latest/scenejs.js index 4bebfd82..39e3598e 100644 --- a/api/latest/scenejs.js +++ b/api/latest/scenejs.js @@ -4,7 +4,7 @@ * A WebGL-based 3D scene graph from xeoLabs * http://scenejs.org/ * - * Built on 2015-06-03 + * Built on 2015-06-11 * * MIT License * Copyright 2015, Lindsay Kay @@ -5830,85 +5830,159 @@ SceneJS._webgl.nextHighestPowerOfTwo = function (x) { return x + 1; }; -; -SceneJS._webgl.Uniform = function (gl, program, name, type, size, location, index, logging) { +;SceneJS._webgl.Uniform = function (gl, program, name, type, size, location, index, logging) { var func = null; - this.numberValue = false; - if (type == gl.BOOL) { - this.numberValue = true; + + var value = null; + + if (type === gl.BOOL) { + func = function (v) { + if (value === v) { + return; + } + value = v; gl.uniform1i(location, v); }; - } else if (type == gl.BOOL_VEC2) { + + } else if (type === gl.BOOL_VEC2) { + func = function (v) { + if (value !== null && value[0] === v[0] && value[1] === v[1]) { + return; + } + value = v; gl.uniform2iv(location, v); }; - } else if (type == gl.BOOL_VEC3) { + + } else if (type === gl.BOOL_VEC3) { + func = function (v) { + if (value !== null && value[0] === v[0] && value[1] === v[1] && value[2] === v[2]) { + return; + } + value = v; gl.uniform3iv(location, v); }; - } else if (type == gl.BOOL_VEC4) { + + } else if (type === gl.BOOL_VEC4) { + func = function (v) { + if (value !== null && value[0] === v[0] && value[1] === v[1] && value[2] === v[2] && value[3] === v[3]) { + return; + } + value = v; gl.uniform4iv(location, v); }; - } else if (type == gl.INT) { - this.numberValue = true; + + } else if (type === gl.INT) { + func = function (v) { + if (value === v) { + return; + } + value = v; gl.uniform1iv(location, v); }; - } else if (type == gl.INT_VEC2) { + + } else if (type === gl.INT_VEC2) { + func = function (v) { + if (value !== null && value[0] === v[0] && value[1] === v[1]) { + return; + } + value = v; gl.uniform2iv(location, v); }; - } else if (type == gl.INT_VEC3) { + + } else if (type === gl.INT_VEC3) { + func = function (v) { + if (value !== null && value[0] === v[0] && value[1] === v[1] && value[2] === v[2]) { + return; + } + value = v; gl.uniform3iv(location, v); }; - } else if (type == gl.INT_VEC4) { + + } else if (type === gl.INT_VEC4) { + func = function (v) { + if (value !== null && value[0] === v[0] && value[1] === v[1] && value[2] === v[2] && value[3] === v[3]) { + return; + } + value = v; gl.uniform4iv(location, v); }; - } else if (type == gl.FLOAT) { - this.numberValue = true; + + } else if (type === gl.FLOAT) { + func = function (v) { + if (value === v) { + return; + } + value = v; gl.uniform1f(location, v); }; - } else if (type == gl.FLOAT_VEC2) { + + } else if (type === gl.FLOAT_VEC2) { + func = function (v) { + if (value !== null && value[0] === v[0] && value[1] === v[1]) { + return; + } + value = v; gl.uniform2fv(location, v); }; - } else if (type == gl.FLOAT_VEC3) { + + } else if (type === gl.FLOAT_VEC3) { + func = function (v) { + if (value !== null && value[0] === v[0] && value[1] === v[1] && value[2] === v[2]) { + return; + } + value = v; gl.uniform3fv(location, v); }; - } else if (type == gl.FLOAT_VEC4) { + + } else if (type === gl.FLOAT_VEC4) { + func = function (v) { + if (value !== null && value[0] === v[0] && value[1] === v[1] && value[2] === v[2] && value[3] === v[3]) { + return; + } + value = v; gl.uniform4fv(location, v); }; - } else if (type == gl.FLOAT_MAT2) { + + } else if (type === gl.FLOAT_MAT2) { + func = function (v) { gl.uniformMatrix2fv(location, gl.FALSE, v); }; - } else if (type == gl.FLOAT_MAT3) { + + } else if (type === gl.FLOAT_MAT3) { + func = function (v) { gl.uniformMatrix3fv(location, gl.FALSE, v); }; - } else if (type == gl.FLOAT_MAT4) { + + } else if (type === gl.FLOAT_MAT4) { + func = function (v) { + + // Caching this matrix is actually slower than not caching + gl.uniformMatrix4fv(location, gl.FALSE, v); }; + } else { throw "Unsupported shader uniform type: " + type; } this.setValue = func; - - this.getValue = function () { - return gl.getUniform(program, location); - }; - this.getLocation = function () { return location; }; @@ -8170,7 +8244,8 @@ SceneJS_NodeFactory.prototype.putNode = function (node) { backfaces: true, // Show backfaces frontface: "ccw", // Default vertex winding for front face reflective: true, // Reflects reflection node cubemap, if it exists, by default. - hash: "refl" + solid: false, // When true, renders backfaces without texture or shading, for a cheap solid cross-section effect + hash: "refl;;" }; var coreStack = []; @@ -8200,7 +8275,8 @@ SceneJS_NodeFactory.prototype.putNode = function (node) { this._core.backfaces = true; // Show backfaces this._core.frontface = "ccw"; // Default vertex winding for front face this._core.reflective = true; // Reflects reflection node cubemap, if it exists, by default. - if (params.flags) { // 'flags' property is actually optional in the node definition + this._core.solid = false; // Renders backfaces without texture or shading, for a cheap solid cross-section effect + if (params.flags) { // 'flags' property is actually optional in the node definition this.setFlags(params.flags); } } @@ -8246,6 +8322,14 @@ SceneJS_NodeFactory.prototype.putNode = function (node) { this._engine.branchDirty(this); this._engine.display.imageDirty = true; } + + if (flags.solid != undefined) { + core.solid = flags.solid; + core.hash = core.reflective ? "refl" : ""; + this._engine.branchDirty(this); + this._engine.display.imageDirty = true; + } + return this; }; @@ -8272,7 +8356,8 @@ SceneJS_NodeFactory.prototype.putNode = function (node) { transparent: core.transparent, backfaces: core.backfaces, frontface: core.frontface, - reflective: core.reflective + reflective: core.reflective, + solid: core.solid }; }; @@ -8357,7 +8442,7 @@ SceneJS_NodeFactory.prototype.putNode = function (node) { reflective = !!reflective; if (this._core.reflective != reflective) { this._core.reflective = reflective; - this._core.hash = reflective ? "refl" : ""; + this._core.hash = (reflective ? "refl" : "") + this._core.solid ? ";s" : ";;"; this._engine.branchDirty(this); this._engine.display.imageDirty = true; } @@ -8368,6 +8453,22 @@ SceneJS_NodeFactory.prototype.putNode = function (node) { return this._core.reflective; }; + SceneJS.Flags.prototype.setSolid = function(solid) { + solid = !!solid; + if (this._core.solid != solid) { + this._core.solid = solid; + this._core.hash = (this._core.reflective ? "refl" : "") + solid ? ";s;" : ";;"; + this._engine.branchDirty(this); + this._engine.display.imageDirty = true; + } + return this; + }; + + SceneJS.Flags.prototype.getSolid = function() { + return this._core.solid; + }; + + SceneJS.Flags.prototype._compile = function(ctx) { this._engine.display.flags = coreStack[stackLen++] = this._core; this._compileNodes(ctx); @@ -10575,6 +10676,8 @@ new (function () { */ core.factor = (factor - keys[key1]) / (keys[key2] - keys[key1]); + this._factor = factor; + var morphUpdate = frameUpdate || oldFactor != core.factor; core.key1 = key1; @@ -10592,7 +10695,7 @@ new (function () { }; SceneJS.MorphGeometry.prototype.getFactor = function () { - return this._core.factor; + return this._factor; }; SceneJS.MorphGeometry.prototype.getKeys = function () { @@ -15504,7 +15607,6 @@ SceneJS_Display.prototype._doDrawList = function (params) { var VAO = gl.getExtension("OES_vertex_array_object"); frameCtx.VAO = (VAO) ? VAO : null; - frameCtx.VAO = null; gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight); @@ -15566,7 +15668,6 @@ var SceneJS_ProgramSourceFactory = new (function () { this._sourceCache = {}; // Source codes are shared across all scenes - /** * Get sourcecode for a program to render the given states */ @@ -15603,9 +15704,6 @@ var SceneJS_ProgramSourceFactory = new (function () { this._composePickingVertexShader = function (states) { var morphing = !!states.morphGeometry.targets; var src = [ - - "precision mediump float;", - "attribute vec3 SCENEJS_aVertex;", "uniform mat4 SCENEJS_uMMatrix;", "uniform mat4 SCENEJS_uVMatrix;", @@ -15648,8 +15746,10 @@ var SceneJS_ProgramSourceFactory = new (function () { var clipping = states.clips.clips.length > 0; + var floatPrecision = getFSFloatPrecision(states._canvas.gl); + var src = [ - "precision mediump float;" + "precision " + floatPrecision + " float;" ]; src.push("varying vec4 SCENEJS_vWorldVertex;"); @@ -15770,9 +15870,7 @@ var SceneJS_ProgramSourceFactory = new (function () { var clipping = states.clips.clips.length > 0; var morphing = !!states.morphGeometry.targets; - var src = [ - "precision mediump float;" - ]; + var src = []; src.push("uniform mat4 SCENEJS_uMMatrix;"); // Model matrix src.push("uniform mat4 SCENEJS_uVMatrix;"); // View matrix @@ -16066,12 +16164,15 @@ var SceneJS_ProgramSourceFactory = new (function () { var texturing = this._isTexturing(states); var cubeMapping = this._isCubeMapping(states); var normals = this._hasNormals(states); + var solid = states.flags.solid; var tangents = this._hasTangents(states); var clipping = states.clips.clips.length > 0; + var floatPrecision = getFSFloatPrecision(states._canvas.gl); + var src = ["\n"]; - src.push("precision mediump float;"); + src.push("precision " + floatPrecision + " float;"); if (clipping) { @@ -16124,10 +16225,13 @@ var SceneJS_ProgramSourceFactory = new (function () { } } - /* True when lighting - */ + // True when lighting src.push("uniform bool SCENEJS_uClipping;"); + // True when interior surfaces of solid cross-sections + // are to be rendered without texture and shading + src.push("uniform bool SCENEJS_uSolid;"); + // Added in v4.0 to support depth targets src.push("uniform bool SCENEJS_uDepthMode;"); @@ -16190,6 +16294,18 @@ var SceneJS_ProgramSourceFactory = new (function () { src.push("}"); } + if (normals) { + + if (solid) { + + src.push(" float a = dot(normalize(SCENEJS_vViewNormal), normalize(SCENEJS_vViewEyeVec));"); + src.push(" if (a < 0.0) {"); + src.push(" gl_FragColor = vec4(0.4, 0.4, 1.0, 1.0);"); + src.push(" return;"); + src.push(" }"); + } + } + src.push(" vec3 ambient= SCENEJS_uAmbientColor;"); if (texturing && states.geometry.uvBuf && fragmentHooks.texturePos) { @@ -16466,6 +16582,22 @@ var SceneJS_ProgramSourceFactory = new (function () { return false; } + function getFSFloatPrecision(gl) { + if (!gl.getShaderPrecisionFormat) { + return "mediump"; + } + + if (gl.getShaderPrecisionFormat(gl.FRAGMENT_SHADER, gl.HIGH_FLOAT).precision > 0) { + return "highp"; + } + + if (gl.getShaderPrecisionFormat(gl.FRAGMENT_SHADER, gl.MEDIUM_FLOAT).precision > 0) { + return "mediump"; + } + + return "lowp"; + } + })();;/** * @class Source code for pick and draw shader programs, to be compiled into one or more {@link SceneJS_Program}s * @private @@ -16655,11 +16787,6 @@ var SceneJS_Program = function(id, hash, source, gl) { * This is also re-called to re-create them after WebGL context loss. */ SceneJS_Program.prototype.build = function(gl) { - /** - * Current draw uniform state cached as a bitfield to avoid costly extra uniform1i calls - * @type Number - */ - this.drawUniformFlags = 0; this.gl = gl; this.draw = new SceneJS._webgl.Program(gl, [this.source.drawVertexSrc.join("\n")], [this.source.drawFragmentSrc.join("\n")]); @@ -17046,13 +17173,13 @@ SceneJS_ChunkFactory.prototype.webglRestored = function () { build : function() { - this._uPMatrixDraw = this.program.draw.getUniformLocation("SCENEJS_uPMatrix"); - this._uZNearDraw = this.program.draw.getUniformLocation("SCENEJS_uZNear"); - this._uZFarDraw = this.program.draw.getUniformLocation("SCENEJS_uZFar"); + 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.getUniformLocation("SCENEJS_uPMatrix"); - this._uZNearPick = this.program.pick.getUniformLocation("SCENEJS_uZNear"); - this._uZFarPick = this.program.pick.getUniformLocation("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(frameCtx) { @@ -17064,15 +17191,15 @@ SceneJS_ChunkFactory.prototype.webglRestored = function () { var gl = this.program.gl; if (this._uPMatrixDraw) { - gl.uniformMatrix4fv(this._uPMatrixDraw, gl.FALSE, this.core.mat); + this._uPMatrixDraw.setValue(this.core.mat); } if (this._uZNearDraw) { - gl.uniform1f(this._uZNearDraw, this.core.optics.near); + this._uZNearDraw.setValue(this.core.optics.near); } if (this._uZFarDraw) { - gl.uniform1f(this._uZFarDraw, this.core.optics.far); + this._uZFarDraw.setValue(this.core.optics.far); } frameCtx.cameraMat = this.core.mat; // Query only in draw pass @@ -17088,17 +17215,17 @@ SceneJS_ChunkFactory.prototype.webglRestored = function () { var gl = this.program.gl; if (this._uPMatrixPick) { - gl.uniformMatrix4fv(this._uPMatrixPick, gl.FALSE, this.core.mat); + this._uPMatrixPick.setValue(this.core.mat); } if (frameCtx.rayPick) { // Z-pick pass: feed near and far clip planes into shader if (this._uZNearPick) { - gl.uniform1f(this._uZNearPick, this.core.optics.near); + this._uZNearPick.setValue(this.core.optics.near); } if (this._uZFarPick) { - gl.uniform1f(this._uZFarPick, this.core.optics.far); + this._uZFarPick.setValue(this.core.optics.far); } } @@ -17119,8 +17246,8 @@ SceneJS_ChunkFactory.createChunkType({ for (var i = 0, len = this.core.clips.length; i < len; i++) { this._draw[i] = { - uClipMode :draw.getUniformLocation("SCENEJS_uClipMode" + i), - uClipNormalAndDist: draw.getUniformLocation("SCENEJS_uClipNormalAndDist" + i) + uClipMode :draw.getUniform("SCENEJS_uClipMode" + i), + uClipNormalAndDist: draw.getUniform("SCENEJS_uClipNormalAndDist" + i) }; } @@ -17130,8 +17257,8 @@ SceneJS_ChunkFactory.createChunkType({ for (var i = 0, len = this.core.clips.length; i < len; i++) { this._pick[i] = { - uClipMode :pick.getUniformLocation("SCENEJS_uClipMode" + i), - uClipNormalAndDist: pick.getUniformLocation("SCENEJS_uClipNormalAndDist" + i) + uClipMode :pick.getUniform("SCENEJS_uClipMode" + i), + uClipNormalAndDist: pick.getUniform("SCENEJS_uClipNormalAndDist" + i) }; } }, @@ -17162,16 +17289,16 @@ SceneJS_ChunkFactory.createChunkType({ if (clip.mode == "inside") { - gl.uniform1f(mode, 2); - gl.uniform4fv(normalAndDist, clip.normalAndDist); + mode.setValue(2); + normalAndDist.setValue(clip.normalAndDist); } else if (clip.mode == "outside") { - gl.uniform1f(mode, 1); - gl.uniform4fv(normalAndDist, clip.normalAndDist); + mode.setValue(1); + normalAndDist.setValue(clip.normalAndDist); } else { // disabled - gl.uniform1f(mode, 0); + mode.setValue(0); } } } @@ -17181,7 +17308,7 @@ SceneJS_ChunkFactory.createChunkType({ */ SceneJS_ChunkFactory.createChunkType({ - type:"draw", + type: "draw", /** * As we apply a list of state chunks in a {@link SceneJS_Display}, we track the ID of each chunk @@ -17190,18 +17317,31 @@ SceneJS_ChunkFactory.createChunkType({ * We don't want that for draw chunks however, because they contain GL drawElements calls, * which we need to do for each object. */ - unique:true, + unique: true, - build:function () { - this._depthModeDraw = this.program.draw.getUniformLocation("SCENEJS_uDepthMode"); - this._depthModePick = this.program.pick.getUniformLocation("SCENEJS_uDepthMode"); + build: function () { + this._depthModeDraw = this.program.draw.getUniform("SCENEJS_uDepthMode"); + this._depthModePick = this.program.pick.getUniform("SCENEJS_uDepthMode"); }, - drawAndPick:function (frameCtx) { + drawAndPick: function (frameCtx) { + var gl = this.program.gl; + var indexType = this.program.UINT_INDEX_ENABLED ? gl.UNSIGNED_INT : gl.UNSIGNED_SHORT; - gl.uniform1i(frameCtx.pick ? this._depthModePick : this._depthModeDraw, frameCtx.depthMode); + + if (frameCtx.pick) { + if (this._depthModePick) { + this._depthModePick.setValue(frameCtx.depthMode); + } + } else { + if (this._depthModeDraw) { + this._depthModeDraw.setValue(frameCtx.depthMode); + } + } + gl.drawElements(this.core.primitive, this.core.indexBuf.numItems, indexType, 0); + //frameCtx.textureUnit = 0; } }); @@ -17216,11 +17356,12 @@ SceneJS_ChunkFactory.createChunkType({ var draw = this.program.draw; - this._uClippingDraw = draw.getUniformLocation("SCENEJS_uClipping"); + this._uClippingDraw = draw.getUniform("SCENEJS_uClipping"); + this._uSolidDraw = draw.getUniform("SCENEJS_uSolid"); var pick = this.program.pick; - this._uClippingPick = pick.getUniformLocation("SCENEJS_uClipping"); + this._uClippingPick = pick.getUniform("SCENEJS_uClipping"); }, drawAndPick: function (frameCtx) { @@ -17273,13 +17414,19 @@ SceneJS_ChunkFactory.createChunkType({ } if (frameCtx.pick) { - gl.uniform1i(this._uClippingPick, this.core.clipping); + + if (this._uClippingPick) { + this._uClippingPick.setValue(this.core.clipping); + } } else { - var drawUniforms = (this.core.clipping ? 1 : 0); - if (this.program.drawUniformFlags != drawUniforms) { - gl.uniform1i(this._uClippingDraw, this.core.clipping); - this.program.drawUniformFlags = drawUniforms; + + if (this._uClippingDraw) { + this._uClippingDraw.setValue(this.core.clipping); + } + + if (this._uSolidDraw) { + this._uSolidDraw.setValue(this.core.solid); } } } @@ -17353,13 +17500,13 @@ SceneJS_ChunkFactory.createChunkType({ this._aMorphVertexDraw = draw.getAttribute("SCENEJS_aMorphVertex"); this._aMorphNormalDraw = draw.getAttribute("SCENEJS_aMorphNormal"); - this._uMorphFactorDraw = draw.getUniformLocation("SCENEJS_uMorphFactor"); + this._uMorphFactorDraw = draw.getUniform("SCENEJS_uMorphFactor"); var pick = this.program.pick; this._aVertexPick = pick.getAttribute("SCENEJS_aVertex"); this._aMorphVertexPick = pick.getAttribute("SCENEJS_aMorphVertex"); - this._uMorphFactorPick = pick.getUniformLocation("SCENEJS_uMorphFactor"); + this._uMorphFactorPick = pick.getUniform("SCENEJS_uMorphFactor"); this.VAO = null; this.VAOMorphKey1 = 0; @@ -17415,7 +17562,7 @@ SceneJS_ChunkFactory.createChunkType({ setDrawMorphFactor:function () { if (this._uMorphFactorDraw) { - this.program.gl.uniform1f(this._uMorphFactorDraw, this.core.factor); // Bind LERP factor + this._uMorphFactorDraw.setValue*(this.core.factor); // Bind LERP factor } }, @@ -17511,7 +17658,7 @@ SceneJS_ChunkFactory.createChunkType({ } if (this._uMorphFactorPick) { - this.program.gl.uniform1f(this._uMorphFactorPick, this.core.factor); // Bind LERP factor + this._uMorphFactorPick.setValue(this.core.factor); // Bind LERP factor } }, @@ -17556,20 +17703,20 @@ SceneJS_ChunkFactory.createChunkType({ switch (lights[i].mode) { case "ambient": - this._uAmbientColor[i] = (program.draw.getUniformLocation("SCENEJS_uAmbientColor")); + this._uAmbientColor[i] = (program.draw.getUniform("SCENEJS_uAmbientColor")); break; case "dir": - this._uLightColor[i] = program.draw.getUniformLocation("SCENEJS_uLightColor" + i); + this._uLightColor[i] = program.draw.getUniform("SCENEJS_uLightColor" + i); this._uLightPos[i] = null; - this._uLightDir[i] = program.draw.getUniformLocation("SCENEJS_uLightDir" + i); + this._uLightDir[i] = program.draw.getUniform("SCENEJS_uLightDir" + i); break; case "point": - this._uLightColor[i] = program.draw.getUniformLocation("SCENEJS_uLightColor" + i); - this._uLightPos[i] = program.draw.getUniformLocation("SCENEJS_uLightPos" + i); + this._uLightColor[i] = program.draw.getUniform("SCENEJS_uLightColor" + i); + this._uLightPos[i] = program.draw.getUniform("SCENEJS_uLightPos" + i); this._uLightDir[i] = null; - this._uLightAttenuation[i] = program.draw.getUniformLocation("SCENEJS_uLightAttenuation" + i); + this._uLightAttenuation[i] = program.draw.getUniform("SCENEJS_uLightAttenuation" + i); break; } } @@ -17591,24 +17738,24 @@ SceneJS_ChunkFactory.createChunkType({ light = lights[i]; if (this._uAmbientColor[i]) { - gl.uniform3fv(this._uAmbientColor[i], light.color); + this._uAmbientColor[i].setValue(light.color); } else { if (this._uLightColor[i]) { - gl.uniform3fv(this._uLightColor[i], light.color); + this._uLightColor[i].setValue(light.color); } if (this._uLightPos[i]) { - gl.uniform3fv(this._uLightPos[i], light.pos); + this._uLightPos[i].setValue(light.pos); if (this._uLightAttenuation[i]) { - gl.uniform3fv(this._uLightAttenuation[i], light.attenuation); + this._uLightAttenuation[i].setValue(light.attenuation); } } if (this._uLightDir[i]) { - gl.uniform3fv(this._uLightDir[i], light.dir); + this._uLightDir[i].setValue(light.dir); } } } @@ -17646,11 +17793,11 @@ SceneJS_ChunkFactory.createChunkType({ build : function() { - this._uvMatrixDraw = this.program.draw.getUniformLocation("SCENEJS_uVMatrix"); - this._uVNMatrixDraw = this.program.draw.getUniformLocation("SCENEJS_uVNMatrix"); - this._uWorldEyeDraw = this.program.draw.getUniformLocation("SCENEJS_uWorldEye"); + 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.getUniformLocation("SCENEJS_uVMatrix"); + this._uvMatrixPick = this.program.pick.getUniform("SCENEJS_uVMatrix"); }, draw : function(frameCtx) { @@ -17662,15 +17809,15 @@ SceneJS_ChunkFactory.createChunkType({ var gl = this.program.gl; if (this._uvMatrixDraw) { - gl.uniformMatrix4fv(this._uvMatrixDraw, gl.FALSE, this.core.mat); + this._uvMatrixDraw.setValue(this.core.mat); } if (this._uVNMatrixDraw) { - gl.uniformMatrix4fv(this._uVNMatrixDraw, gl.FALSE, this.core.normalMat); + this._uVNMatrixDraw.setValue(this.core.normalMat); } if (this._uWorldEyeDraw) { - gl.uniform3fv(this._uWorldEyeDraw, this.core.lookAt.eye); + this._uWorldEyeDraw.setValue(this.core.lookAt.eye); } frameCtx.viewMat = this.core.mat; @@ -17681,7 +17828,7 @@ SceneJS_ChunkFactory.createChunkType({ var gl = this.program.gl; if (this._uvMatrixPick) { - gl.uniformMatrix4fv(this._uvMatrixPick, gl.FALSE, this.core.mat); + this._uvMatrixPick.setValue(this.core.mat); } frameCtx.viewMat = this.core.mat; @@ -17693,55 +17840,44 @@ SceneJS_ChunkFactory.createChunkType({ type: "material", - build : function() { + build: function () { var draw = this.program.draw; - this._uMaterialBaseColor = draw.getUniformLocation("SCENEJS_uMaterialColor"); - this._uMaterialSpecularColor = draw.getUniformLocation("SCENEJS_uMaterialSpecularColor"); - this._uMaterialSpecular = draw.getUniformLocation("SCENEJS_uMaterialSpecular"); - this._uMaterialShine = draw.getUniformLocation("SCENEJS_uMaterialShine"); - this._uMaterialEmit = draw.getUniformLocation("SCENEJS_uMaterialEmit"); - this._uMaterialAlpha = draw.getUniformLocation("SCENEJS_uMaterialAlpha"); + this._uMaterialBaseColor = draw.getUniform("SCENEJS_uMaterialColor"); + this._uMaterialSpecularColor = draw.getUniform("SCENEJS_uMaterialSpecularColor"); + this._uMaterialSpecular = draw.getUniform("SCENEJS_uMaterialSpecular"); + this._uMaterialShine = draw.getUniform("SCENEJS_uMaterialShine"); + this._uMaterialEmit = draw.getUniform("SCENEJS_uMaterialEmit"); + this._uMaterialAlpha = draw.getUniform("SCENEJS_uMaterialAlpha"); }, - draw : function() { + draw: function () { var gl = this.program.gl; - var materialSettings = this.program.draw.materialSettings; if (this._uMaterialBaseColor) { - gl.uniform3fv(this._uMaterialBaseColor, this.core.baseColor); + this._uMaterialBaseColor.setValue(this.core.baseColor); } - if (this._uMaterialSpecularColor && - (materialSettings.specularColor[0] != this.core.specularColor[0] || - materialSettings.specularColor[1] != this.core.specularColor[1] || - materialSettings.specularColor[2] != this.core.specularColor[2])) { - gl.uniform3fv(this._uMaterialSpecularColor, this.core.specularColor); - materialSettings.specularColor[0] = this.core.specularColor[0]; - materialSettings.specularColor[1] = this.core.specularColor[1]; - materialSettings.specularColor[2] = this.core.specularColor[2]; + if (this._uMaterialSpecularColor) { + this._uMaterialSpecularColor.setValue(this.core.specularColor); } - if (this._uMaterialSpecular && materialSettings.specular != this.core.specular) { - gl.uniform1f(this._uMaterialSpecular, this.core.specular); - materialSettings.specular = this.core.specular; + if (this._uMaterialSpecular) { + this._uMaterialSpecular.setValue(this.core.specular); } - if (this._uMaterialShine && materialSettings.shine != this.core.shine) { - gl.uniform1f(this._uMaterialShine, this.core.shine); - materialSettings.shine = this.core.shine; + if (this._uMaterialShine) { + this._uMaterialShine.setValue(this.core.shine); } - if (this._uMaterialEmit && materialSettings.emit != this.core.emit) { - gl.uniform1f(this._uMaterialEmit, this.core.emit); - materialSettings.emit = this.core.emit; + if (this._uMaterialEmit) { + this._uMaterialEmit.setValue(this.core.emit); } - if (this._uMaterialAlpha && materialSettings.alpha != this.core.alpha) { - gl.uniform1f(this._uMaterialAlpha, this.core.alpha); - materialSettings.alpha = this.core.alpha; + if (this._uMaterialAlpha) { + this._uMaterialAlpha.setValue(this.core.alpha); } } }); @@ -17752,11 +17888,11 @@ SceneJS_ChunkFactory.createChunkType({ type: "name", - build : function() { - this._uPickColor = this.program.pick.getUniformLocation("SCENEJS_uPickColor"); + build: function () { + this._uPickColor = this.program.pick.getUniform("SCENEJS_uPickColor"); }, - pick : function(frameCtx) { + pick: function (frameCtx) { if (this._uPickColor && this.core.name) { @@ -17766,7 +17902,7 @@ SceneJS_ChunkFactory.createChunkType({ var g = frameCtx.pickIndex >> 8 & 0xFF; var r = frameCtx.pickIndex & 0xFF; - this.program.gl.uniform3fv(this._uPickColor, [r / 255, g / 255, b / 255]); + this._uPickColor.setValue([r / 255, g / 255, b / 255]); } } });;SceneJS_ChunkFactory.createChunkType({ @@ -17776,9 +17912,9 @@ SceneJS_ChunkFactory.createChunkType({ build : function() { // Note that "program" chunks are always after "renderTarget" chunks - this._depthModeDraw = this.program.draw.getUniformLocation("SCENEJS_uDepthMode"); - this._depthModePick = this.program.pick.getUniformLocation("SCENEJS_uDepthMode"); - this._rayPickMode = this.program.pick.getUniformLocation("SCENEJS_uRayPickMode"); + this._depthModeDraw = this.program.draw.getUniform("SCENEJS_uDepthMode"); + this._depthModePick = this.program.pick.getUniform("SCENEJS_uDepthMode"); + this._rayPickMode = this.program.pick.getUniform("SCENEJS_uRayPickMode"); }, draw : function(frameCtx) { @@ -17786,7 +17922,9 @@ SceneJS_ChunkFactory.createChunkType({ drawProgram.bind(); frameCtx.textureUnit = 0; var gl = this.program.gl; - gl.uniform1i(this._depthModeDraw, frameCtx.depthMode); + if (this._depthModeDraw) { + this._depthModeDraw.setValue(frameCtx.depthMode); + } if (!frameCtx.VAO) { for (var i = 0; i < 10; i++) { gl.disableVertexAttribArray(i); @@ -17800,8 +17938,12 @@ SceneJS_ChunkFactory.createChunkType({ var pickProgram = this.program.pick; pickProgram.bind(); var gl = this.program.gl; - gl.uniform1i(this._rayPickMode, frameCtx.rayPick); - gl.uniform1i(this._depthModePick, frameCtx.depthMode); + if (this._rayPickMode) { + this._rayPickMode.setValue(frameCtx.rayPick); + } + if (this._depthModePick) { + this._depthModePick.setValue(frameCtx.depthMode); + } frameCtx.textureUnit = 0; for (var i = 0; i < 10; i++) { gl.disableVertexAttribArray(i); @@ -18135,19 +18277,19 @@ SceneJS_ChunkFactory.createChunkType({ type: "xform", - build : function() { + build: function () { var draw = this.program.draw; - this._uMatLocationDraw = draw.getUniformLocation("SCENEJS_uMMatrix"); - this._uNormalMatLocationDraw = draw.getUniformLocation("SCENEJS_uMNMatrix"); + this._uMatLocationDraw = draw.getUniform("SCENEJS_uMMatrix"); + this._uNormalMatLocationDraw = draw.getUniform("SCENEJS_uMNMatrix"); var pick = this.program.pick; - this._uMatLocationPick = pick.getUniformLocation("SCENEJS_uMMatrix"); + this._uMatLocationPick = pick.getUniform("SCENEJS_uMMatrix"); }, - draw : function(frameCtx) { + draw: function (frameCtx) { /* Rebuild core's matrix from matrices at cores on path up to root */ @@ -18158,17 +18300,17 @@ SceneJS_ChunkFactory.createChunkType({ var gl = this.program.gl; if (this._uMatLocationDraw) { - gl.uniformMatrix4fv(this._uMatLocationDraw, gl.FALSE, this.core.mat); + this._uMatLocationDraw.setValue(this.core.mat); } if (this._uNormalMatLocationDraw) { - gl.uniformMatrix4fv(this._uNormalMatLocationDraw, gl.FALSE, this.core.normalMat); + this._uNormalMatLocationDraw.setValue(this.core.normalMat); } frameCtx.modelMat = this.core.mat; }, - pick : function(frameCtx) { + pick: function (frameCtx) { /* Rebuild core's matrix from matrices at cores on path up to root */ @@ -18179,7 +18321,7 @@ SceneJS_ChunkFactory.createChunkType({ var gl = this.program.gl; if (this._uMatLocationPick) { - gl.uniformMatrix4fv(this._uMatLocationPick, gl.FALSE, this.core.mat); + this._uMatLocationPick.setValue(this.core.mat); } frameCtx.modelMat = this.core.mat; diff --git a/api/latest/scenejs.min.js b/api/latest/scenejs.min.js index 4ceae41e..3952cf72 100644 --- a/api/latest/scenejs.min.js +++ b/api/latest/scenejs.min.js @@ -4,7 +4,7 @@ * A WebGL-based 3D scene graph from xeoLabs * http://scenejs.org/ * - * Built on 2015-06-03 + * Built on 2015-06-11 * * MIT License * Copyright 2015, Lindsay Kay @@ -14,9 +14,9 @@ if(void 0===require){var requirejs,require,define;!function(ba){function J(a){return"[object Function]"===N.call(a)}function K(a){return"[object Array]"===N.call(a)}function z(a,b){if(a){var c;for(c=0;c-1&&(!a[c]||!b(a[c],c,a));c-=1);}}function t(a,b){return ha.call(a,b)}function m(a,b){return t(a,b)&&a[b]}function H(a,b){for(var c in a)if(t(a,c)&&b(a[c],c))break}function S(a,b,c,d){return b&&H(b,function(b,e){(c||!t(a,e))&&(d&&"string"!=typeof b?(a[e]||(a[e]={}),S(a[e],b,c,d)):a[e]=b)}),a}function v(a,b){return function(){return b.apply(a,arguments)}}function ca(a){throw a}function da(a){if(!a)return a;var b=ba;return z(a.split("."),function(a){b=b[a]}),b}function B(a,b,c,d){return b=Error(b+"\nhttp://requirejs.org/docs/errors.html#"+a),b.requireType=a,b.requireModules=d,c&&(b.originalError=c),b}function ia(a){function b(a,b,c){var d,e,f,g,h,i,j,k=b&&b.split("/");d=k;var l=C.map,n=l&&l["*"];if(a&&"."===a.charAt(0))if(b){for(d=m(C.pkgs,b)?k=[b]:k.slice(0,k.length-1),b=a=d.concat(a.split("/")),d=0;b[d];d+=1)if(e=b[d],"."===e)b.splice(d,1),d-=1;else if(".."===e){if(1===d&&(".."===b[2]||".."===b[0]))break;d>0&&(b.splice(d-1,2),d-=2)}d=m(C.pkgs,b=a[0]),a=a.join("/"),d&&a===b+"/"+d.main&&(a=b)}else 0===a.indexOf("./")&&(a=a.substring(2));if(c&&l&&(k||n)){for(b=a.split("/"),d=b.length;d>0;d-=1){if(f=b.slice(0,d).join("/"),k)for(e=k.length;e>0;e-=1)if((c=m(l,k.slice(0,e).join("/")))&&(c=m(c,f))){g=c,h=d;break}if(g)break;!i&&n&&m(n,f)&&(i=m(n,f),j=d)}!g&&i&&(g=i,h=j),g&&(b.splice(0,h,g),a=b.join("/"))}return a}function c(a){A&&z(document.getElementsByTagName("script"),function(b){return b.getAttribute("data-requiremodule")===a&&b.getAttribute("data-requirecontext")===w.contextName?(b.parentNode.removeChild(b),!0):void 0})}function d(a){var b=m(C.paths,a);return b&&K(b)&&1-1&&(b=a.substring(0,c),a=a.substring(c+1,a.length)),[b,a]}function f(a,c,d,f){var g,h,i=null,j=c?c.name:null,k=a,l=!0,n="";return a||(l=!1,a="_@r"+(M+=1)),a=e(a),i=a[0],a=a[1],i&&(i=b(i,j,f),h=m(I,i)),a&&(i?n=h&&h.normalize?h.normalize(a,function(a){return b(a,j,f)}):b(a,j,f):(n=b(a,j,f),a=e(n),i=a[0],n=a[1],d=!0,g=w.nameToUrl(n))),d=!i||h||d?"":"_unnormalized"+(N+=1),{prefix:i,name:n,parentMap:c,unnormalized:!!d,url:g,originalName:k,isDefine:l,id:(i?i+"!"+n:n)+d}}function g(a){var b=a.id,c=m(D,b);return c||(c=D[b]=new w.Module(a)),c}function i(a,b,c){var d=a.id,e=m(D,d);!t(I,d)||e&&!e.defineEmitComplete?(e=g(a),e.error&&"error"===b?c(e.error):e.on(b,c)):"defined"===b&&c(I[d])}function j(a,b){var c=a.requireModules,d=!1;b?b(a):(z(c,function(b){(b=m(D,b))&&(b.error=a,b.events.error&&(d=!0,b.emit("error",a)))}),d||h.onError(a))}function k(){U.length&&(ja.apply(G,[G.length-1,0].concat(U)),U=[])}function l(a){delete D[a],delete E[a]}function n(a,b,c){var d=a.map.id;a.error?a.emit("error",a.error):(b[d]=!0,z(a.depMaps,function(d,e){var f=d.id,g=m(D,f);g&&!a.depMatched[e]&&!c[f]&&(m(b,f)?(a.defineDep(e,I[f]),a.check()):n(g,b,c))}),c[d]=!0)}function o(){var a,b,e,f,g=(e=1e3*C.waitSeconds)&&w.startTime+e<(new Date).getTime(),h=[],i=[],k=!1,l=!0;if(!s){if(s=!0,H(E,function(e){if(a=e.map,b=a.id,e.enabled&&(a.isDefine||i.push(e),!e.error))if(!e.inited&&g)d(b)?k=f=!0:(h.push(b),c(b));else if(!e.inited&&e.fetched&&a.isDefine&&(k=!0,!a.prefix))return l=!1}),g&&h.length)return e=B("timeout","Load timeout for modules: "+h,null,h),e.contextName=w.contextName,j(e);l&&z(i,function(a){n(a,{},{})}),g&&!f||!k||!A&&!ea||y||(y=setTimeout(function(){y=0,o()},50)),s=!1}}function p(a){t(I,a[0])||g(f(a[0],null,!0)).init(a[1],a[2])}function q(a){var a=a.currentTarget||a.srcElement,b=w.onScriptLoad;return a.detachEvent&&!Z?a.detachEvent("onreadystatechange",b):a.removeEventListener("load",b,!1),b=w.onScriptError,(!a.detachEvent||Z)&&a.removeEventListener("error",b,!1),{node:a,id:a&&a.getAttribute("data-requiremodule")}}function r(){var a;for(k();G.length;){if(a=G.shift(),null===a[0])return j(B("mismatch","Mismatched anonymous define() module: "+a[a.length-1]));p(a)}}var s,u,w,x,y,C={waitSeconds:7,baseUrl:"./",paths:{},pkgs:{},shim:{},config:{}},D={},E={},F={},G=[],I={},L={},M=1,N=1;return x={require:function(a){return a.require?a.require:a.require=w.makeRequire(a.map)},exports:function(a){return a.usingExports=!0,a.map.isDefine?a.exports?a.exports:a.exports=I[a.map.id]={}:void 0},module:function(a){return a.module?a.module:a.module={id:a.map.id,uri:a.map.url,config:function(){var b=m(C.pkgs,a.map.id);return(b?m(C.config,a.map.id+"/"+b.main):m(C.config,a.map.id))||{}},exports:I[a.map.id]}}},u=function(a){this.events=m(F,a.id)||{},this.map=a,this.shim=m(C.shim,a.id),this.depExports=[],this.depMaps=[],this.depMatched=[],this.pluginMaps={},this.depCount=0},u.prototype={init:function(a,b,c,d){d=d||{},this.inited||(this.factory=b,c?this.on("error",c):this.events.error&&(c=v(this,function(a){this.emit("error",a)})),this.depMaps=a&&a.slice(0),this.errback=c,this.inited=!0,this.ignore=d.ignore,d.enabled||this.enabled?this.enable():this.check())},defineDep:function(a,b){this.depMatched[a]||(this.depMatched[a]=!0,this.depCount-=1,this.depExports[a]=b)},fetch:function(){if(!this.fetched){this.fetched=!0,w.startTime=(new Date).getTime();var a=this.map;if(!this.shim)return a.prefix?this.callPlugin():this.load();w.makeRequire(this.map,{enableBuildCallback:!0})(this.shim.deps||[],v(this,function(){return a.prefix?this.callPlugin():this.load()}))}},load:function(){var a=this.map.url;L[a]||(L[a]=!0,w.load(this.map.id,a))},check:function(){if(this.enabled&&!this.enabling){var a,b,c=this.map.id;b=this.depExports;var d=this.exports,e=this.factory;if(this.inited){if(this.error)this.emit("error",this.error);else if(!this.defining){if(this.defining=!0,1>this.depCount&&!this.defined){if(J(e)){if(this.events.error&&this.map.isDefine||h.onError!==ca)try{d=w.execCb(c,e,b,d)}catch(f){a=f}else d=w.execCb(c,e,b,d);if(this.map.isDefine&&((b=this.module)&&void 0!==b.exports&&b.exports!==this.exports?d=b.exports:void 0===d&&this.usingExports&&(d=this.exports)),a)return a.requireMap=this.map,a.requireModules=this.map.isDefine?[this.map.id]:null,a.requireType=this.map.isDefine?"define":"require",j(this.error=a)}else d=e;this.exports=d,this.map.isDefine&&!this.ignore&&(I[c]=d,h.onResourceLoad)&&h.onResourceLoad(w,this.map,this.depMaps),l(c),this.defined=!0}this.defining=!1,this.defined&&!this.defineEmitted&&(this.defineEmitted=!0,this.emit("defined",this.exports),this.defineEmitComplete=!0)}}else this.fetch()}},callPlugin:function(){var a=this.map,c=a.id,d=f(a.prefix);this.depMaps.push(d),i(d,"defined",v(this,function(d){var e,k;k=this.map.name;var n=this.map.parentMap?this.map.parentMap.name:null,o=w.makeRequire(a.parentMap,{enableBuildCallback:!0});this.map.unnormalized?(d.normalize&&(k=d.normalize(k,function(a){return b(a,n,!0)})||""),d=f(a.prefix+"!"+k,this.map.parentMap),i(d,"defined",v(this,function(a){this.init([],function(){return a},null,{enabled:!0,ignore:!0})})),(k=m(D,d.id))&&(this.depMaps.push(d),this.events.error&&k.on("error",v(this,function(a){this.emit("error",a)})),k.enable())):(e=v(this,function(a){this.init([],function(){return a},null,{enabled:!0})}),e.error=v(this,function(a){this.inited=!0,this.error=a,a.requireModules=[c],H(D,function(a){0===a.map.id.indexOf(c+"_unnormalized")&&l(a.map.id)}),j(a)}),e.fromText=v(this,function(b,d){var i=a.name,k=f(i),l=Q;d&&(b=d),l&&(Q=!1),g(k),t(C.config,c)&&(C.config[i]=C.config[c]);try{h.exec(b)}catch(m){return j(B("fromtexteval","fromText eval for "+c+" failed: "+m,m,[c]))}l&&(Q=!0),this.depMaps.push(k),w.completeLoad(i),o([i],e)}),d.load(a.name,o,e,C))})),w.enable(d,this),this.pluginMaps[d.id]=d},enable:function(){E[this.map.id]=this,this.enabling=this.enabled=!0,z(this.depMaps,v(this,function(a,b){var c,d;if("string"==typeof a){if(a=f(a,this.map.isDefine?this.map:this.map.parentMap,!1,!this.skipMap),this.depMaps[b]=a,c=m(x,a.id))return void(this.depExports[b]=c(this));this.depCount+=1,i(a,"defined",v(this,function(a){this.defineDep(b,a),this.check()})),this.errback&&i(a,"error",v(this,this.errback))}c=a.id,d=D[c],!t(x,c)&&d&&!d.enabled&&w.enable(a,this)})),H(this.pluginMaps,v(this,function(a){var b=m(D,a.id);b&&!b.enabled&&w.enable(a,this)})),this.enabling=!1,this.check()},on:function(a,b){var c=this.events[a];c||(c=this.events[a]=[]),c.push(b)},emit:function(a,b){z(this.events[a],function(a){a(b)}),"error"===a&&delete this.events[a]}},w={config:C,contextName:a,registry:D,defined:I,urlFetched:L,defQueue:G,Module:u,makeModuleMap:f,nextTick:h.nextTick,onError:j,configure:function(a){a.baseUrl&&"/"!==a.baseUrl.charAt(a.baseUrl.length-1)&&(a.baseUrl+="/");var b=C.pkgs,c=C.shim,d={paths:!0,config:!0,map:!0};H(a,function(a,b){d[b]?"map"===b?(C.map||(C.map={}),S(C[b],a,!0,!0)):S(C[b],a,!0):C[b]=a}),a.shim&&(H(a.shim,function(a,b){K(a)&&(a={deps:a}),!a.exports&&!a.init||a.exportsFn||(a.exportsFn=w.makeShimExports(a)),c[b]=a}),C.shim=c),a.packages&&(z(a.packages,function(a){a="string"==typeof a?{name:a}:a,b[a.name]={name:a.name,location:a.location||a.name,main:(a.main||"main").replace(ka,"").replace(fa,"")}}),C.pkgs=b),H(D,function(a,b){!a.inited&&!a.map.unnormalized&&(a.map=f(b))}),(a.deps||a.callback)&&w.require(a.deps||[],a.callback)},makeShimExports:function(a){return function(){var b;return a.init&&(b=a.init.apply(ba,arguments)),b||a.exports&&da(a.exports)}},makeRequire:function(c,d){function e(b,i,k){var l,m;return d.enableBuildCallback&&i&&J(i)&&(i.__requireJsBuild=!0),"string"==typeof b?J(i)?j(B("requireargs","Invalid require call"),k):c&&t(x,b)?x[b](D[c.id]):h.get?h.get(w,b,c,e):(l=f(b,c,!1,!0),l=l.id,t(I,l)?I[l]:j(B("notloaded",'Module name "'+l+'" has not been loaded yet for context: '+a+(c?"":". Use require([])")))):(r(),w.nextTick(function(){r(),m=g(f(null,c)),m.skipMap=d.skipMap,m.init(b,i,k,{enabled:!0}),o()}),e)}return d=d||{},S(e,{isBrowser:A,toUrl:function(a){var d,e=a.lastIndexOf("."),f=a.split("/")[0];return-1!==e&&("."!==f&&".."!==f||e>1)&&(d=a.substring(e,a.length),a=a.substring(0,e)),w.nameToUrl(b(a,c&&c.id,!0),d,!0)},defined:function(a){return t(I,f(a,c,!1,!0).id)},specified:function(a){return a=f(a,c,!1,!0).id,t(I,a)||t(D,a)}}),c||(e.undef=function(a){k();var b=f(a,c,!0),d=m(D,a);delete I[a],delete L[b.url],delete F[a],d&&(d.events.defined&&(F[a]=d.events),l(a))}),e},enable:function(a){m(D,a.id)&&g(a).enable()},completeLoad:function(a){var b,c,e=m(C.shim,a)||{},f=e.exports;for(k();G.length;){if(c=G.shift(),null===c[0]){if(c[0]=a,b)break;b=!0}else c[0]===a&&(b=!0);p(c)}if(c=m(D,a),!b&&!t(I,a)&&c&&!c.inited){if(C.enforceDefine&&(!f||!da(f)))return d(a)?void 0:j(B("nodefine","No define call for "+a,null,[a]));p([a,e.deps||[],e.exportsFn])}o()},nameToUrl:function(a,b,c){var d,e,f,g,i,j;if(h.jsExtRegExp.test(a))g=a+(b||"");else{for(d=C.paths,e=C.pkgs,g=a.split("/"),i=g.length;i>0;i-=1){if(j=g.slice(0,i).join("/"),f=m(e,j),j=m(d,j)){K(j)&&(j=j[0]),g.splice(0,i,j);break}if(f){a=a===f.name?f.location+"/"+f.main:f.location,g.splice(0,i,a);break}}g=g.join("/"),g+=b||(/\?/.test(g)||c?"":".js"),g=("/"===g.charAt(0)||g.match(/^[\w\+\.\-]+:/)?"":C.baseUrl)+g}return C.urlArgs?g+((-1===g.indexOf("?")?"?":"&")+C.urlArgs):g},load:function(a,b){h.load(w,a,b)},execCb:function(a,b,c,d){return b.apply(d,c)},onScriptLoad:function(a){("load"===a.type||la.test((a.currentTarget||a.srcElement).readyState))&&(R=null,a=q(a),w.completeLoad(a.id))},onScriptError:function(a){var b=q(a);return d(b.id)?void 0:j(B("scripterror","Script error for: "+b.id,a,[b.id]))}},w.require=w.makeRequire(),w}var h,x,y,E,L,F,R,M,s,ga,ma=/(\/\*([\s\S]*?)\*\/|([^:]|^)\/\/(.*)$)/gm,na=/[^.]\s*require\s*\(\s*["']([^'"\s]+)["']\s*\)/g,fa=/\.js$/,ka=/^\.\//;x=Object.prototype;var N=x.toString,ha=x.hasOwnProperty,ja=Array.prototype.splice,A=!("undefined"==typeof window||!navigator||!window.document),ea=!A&&"undefined"!=typeof importScripts,la=A&&"PLAYSTATION 3"===navigator.platform?/^complete$/:/^(complete|loaded)$/,Z="undefined"!=typeof opera&&"[object Opera]"===opera.toString(),G={},u={},U=[],Q=!1;if("undefined"==typeof define){if("undefined"!=typeof requirejs){if(J(requirejs))return;u=requirejs,requirejs=void 0}"undefined"!=typeof require&&!J(require)&&(u=require,require=void 0),h=requirejs=function(a,b,c,d){var e,f="_";return!K(a)&&"string"!=typeof a&&(e=a,K(b)?(a=b,b=c,c=d):a=[]),e&&e.context&&(f=e.context),(d=m(G,f))||(d=G[f]=h.s.newContext(f)),e&&d.configure(e),d.require(a,b,c)},h.config=function(a){return h(a)},h.nextTick="undefined"!=typeof setTimeout?function(a){setTimeout(a,4)}:function(a){a()},require||(require=h),h.version="2.1.6",h.jsExtRegExp=/^\/|:|\?|\.js$/,h.isBrowser=A,x=h.s={contexts:G,newContext:ia},h({}),z(["toUrl","undef","defined","specified"],function(a){h[a]=function(){var b=G._;return b.require[a].apply(b,arguments)}}),A&&(y=x.head=document.getElementsByTagName("head")[0],E=document.getElementsByTagName("base")[0])&&(y=x.head=E.parentNode),h.onError=ca,h.load=function(a,b,c){var d,e=a&&a.config||{};if(A)return d=e.xhtml?document.createElementNS("http://www.w3.org/1999/xhtml","html:script"):document.createElement("script"),d.type=e.scriptType||"text/javascript",d.charset="utf-8",d.async=!0,d.setAttribute("data-requirecontext",a.contextName),d.setAttribute("data-requiremodule",b),!d.attachEvent||d.attachEvent.toString&&0>d.attachEvent.toString().indexOf("[native code")||Z?(d.addEventListener("load",a.onScriptLoad,!1),d.addEventListener("error",a.onScriptError,!1)):(Q=!0,d.attachEvent("onreadystatechange",a.onScriptLoad)),d.src=c,M=d,E?y.insertBefore(d,E):y.appendChild(d),M=null,d;if(ea)try{importScripts(c),a.completeLoad(b)}catch(f){a.onError(B("importscripts","importScripts failed for "+b+" at "+c,f,[b]))}},A&&O(document.getElementsByTagName("script"),function(a){return y||(y=a.parentNode),(L=a.getAttribute("data-main"))?(s=L,u.baseUrl||(F=s.split("/"),s=F.pop(),ga=F.length?F.join("/")+"/":"./",u.baseUrl=ga),s=s.replace(fa,""),h.jsExtRegExp.test(s)&&(s=L),u.deps=u.deps?u.deps.concat(s):[s],!0):void 0}),define=function(a,b,c){var d,e;"string"!=typeof a&&(c=b,b=a,a=null),K(b)||(c=b,b=null),!b&&J(c)&&(b=[],c.length&&(c.toString().replace(ma,"").replace(na,function(a,c){b.push(c)}),b=(1===c.length?["require"]:["require","exports","module"]).concat(b))),Q&&((d=M)||(R&&"interactive"===R.readyState||O(document.getElementsByTagName("script"),function(a){return"interactive"===a.readyState?R=a:void 0}),d=R),d&&(a||(a=d.getAttribute("data-requiremodule")),e=G[d.getAttribute("data-requirecontext")])),(e?e.defQueue:U).push([a,b,c])},define.amd={jQuery:!0},h.exec=function(b){return eval(b)},h(u)}}(this)}WebGLDebugUtils=function(){function a(a){if(null==m){m={};for(var b in a)"number"==typeof a[b]&&(m[a[b]]=b)}}function b(){if(null==m)throw"WebGLDebugUtils.init(ctx) not called"}function c(a){return b(),void 0!==m[a]}function d(a){b();var c=m[a];return void 0!==c?c:"*UNKNOWN WebGL ENUM (0x"+a.toString(16)+")"}function e(a,b,c){var e=l[a];return void 0!==e&&e[b]?d(c):null===c?"null":void 0===c?"undefined":c.toString()}function f(a,b){for(var c="",d=0;dd;++d)a.disableVertexAttribArray(d),a.vertexAttribPointer(d,4,a.FLOAT,!1,0,0),a.vertexAttrib1f(d,0);a.deleteBuffer(c);for(var e=a.getParameter(a.MAX_TEXTURE_IMAGE_UNITS),d=0;e>d;++d)a.activeTexture(a.TEXTURE0+d),a.bindTexture(a.TEXTURE_CUBE_MAP,null),a.bindTexture(a.TEXTURE_2D,null);for(a.activeTexture(a.TEXTURE0),a.useProgram(null),a.bindBuffer(a.ARRAY_BUFFER,null),a.bindBuffer(a.ELEMENT_ARRAY_BUFFER,null),a.bindFramebuffer(a.FRAMEBUFFER,null),a.bindRenderbuffer(a.RENDERBUFFER,null),a.disable(a.BLEND),a.disable(a.CULL_FACE),a.disable(a.DEPTH_TEST),a.disable(a.DITHER),a.disable(a.SCISSOR_TEST),a.blendColor(0,0,0,0),a.blendEquation(a.FUNC_ADD),a.blendFunc(a.ONE,a.ZERO),a.clearColor(0,0,0,0),a.clearDepth(1),a.clearStencil(-1),a.colorMask(!0,!0,!0,!0),a.cullFace(a.BACK),a.depthFunc(a.LESS),a.depthMask(!0),a.depthRange(0,1),a.frontFace(a.CCW),a.hint(a.GENERATE_MIPMAP_HINT,a.DONT_CARE),a.lineWidth(1),a.pixelStorei(a.PACK_ALIGNMENT,4),a.pixelStorei(a.UNPACK_ALIGNMENT,4),a.pixelStorei(a.UNPACK_FLIP_Y_WEBGL,!1),a.pixelStorei(a.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!1),a.UNPACK_COLORSPACE_CONVERSION_WEBGL&&a.pixelStorei(a.UNPACK_COLORSPACE_CONVERSION_WEBGL,a.BROWSER_DEFAULT_WEBGL),a.polygonOffset(0,0),a.sampleCoverage(1,!1),a.scissor(0,0,a.canvas.width,a.canvas.height),a.stencilFunc(a.ALWAYS,0,4294967295),a.stencilMask(4294967295),a.stencilOp(a.KEEP,a.KEEP,a.KEEP),a.viewport(0,0,a.canvas.width,a.canvas.height),a.clear(a.COLOR_BUFFER_BIT|a.DEPTH_BUFFER_BIT|a.STENCIL_BUFFER_BIT);a.getError(););}function j(a){function b(a){return"function"==typeof a?a:function(b){a.handleEvent(b)}}function c(a){var b=a.addEventListener;a.addEventListener=function(c,d,e){switch(c){case"webglcontextlost":x(d);break;case"webglcontextrestored":y(d);break;default:b.apply(a,arguments)}}}function d(){for(var a=Object.keys(w),b=0;b=0&&setTimeout(function(){a.restoreContext()},v)},0)}},a.restoreContext=function(){q&&o.length&&setTimeout(function(){if(!u)throw"can not restore. webglcontestlost listener did not call event.preventDefault";h(),i(l),q=!1,t=0,u=!1;for(var a=o.slice(),b=j("context restored"),c=0;c0)return!1;if(0===b.length)return!0;for(var c in b)if(a.call(b,c))return!1;return!0},this.reset=function(){var a=[];for(var b in this._engines)this._engines.hasOwnProperty(b)&&(a.push(this._engines[b]),delete this._engines[b],this._engineIds.removeItem(b));for(;a.length>0;)a.pop().destroy();SceneJS_events.fireEvent(SceneJS_events.RESET)}};!function(){var a;SceneJS.on("configs",function(b){if(b.pluginPath!=a){a=b.pluginPath;var c=a+"/lib";require.config({paths:{scenejsPluginDeps:c}})}})}();var SceneJS_eventManager=function(){this._handlerIds=new SceneJS_Map,this.typeHandlers={}};SceneJS_eventManager.prototype.createEvent=function(a){this.typeHandlers[a]||(this.typeHandlers[a]={handlers:{},numSubs:0})},SceneJS_eventManager.prototype.onEvent=function(a,b){var c=this.typeHandlers[a]||(this.typeHandlers[a]={handlers:{},numSubs:0}),d=this._handlerIds.addItem(a),e=c.handlers;return e[d]=b,c.numSubs++,d},SceneJS_eventManager.prototype.fireEvent=function(a,b){var c=this.typeHandlers[a]||(this.typeHandlers[a]={handlers:{},numSubs:0});if(c.numSubs>0){var d=c.handlers;for(var e in d)d.hasOwnProperty(e)&&d[e](b)}},SceneJS_eventManager.prototype.unEvent=function(a){var b=this._handlerIds.items[a];if(b){this._handlerIds.removeItem(a);var c=this.typeHandlers[b];c&&(delete c[a],this.typeHandlers[b].numSubs--)}},SceneJS.Plugins=new function(){function a(a,c,f,g){var h=d[a]||(d[a]={});h[c]=g,b(f,0,function(){for(var b=a+c,d=e[b]||(e[b]=[]);d.length>0;)d.pop()(g);delete e[b]})}function b(a,d,e){if(!a||d>=a.length)return void e();var f=a[d],g=SceneJS_configsModule.configs.pluginPath;if(!g)throw"no pluginPath config";f=g+"/"+f,c(f,function(){b(a,d+1,e)})}function c(a,b){var c=document.createElement("script");c.type="text/javascript",c.readyState?c.onreadystatechange=function(){("loaded"==c.readyState||"complete"==c.readyState)&&(c.onreadystatechange=null,b&&b())}:c.onload=function(){b&&b()},c.src=a,document.getElementsByTagName("head")[0].appendChild(c)}var d={},e={};this.addPlugin=function(){var b,c,d=arguments[0],e=arguments[1];4==arguments.length?(b=arguments[2],c=arguments[3]):c=arguments[2],a(d,e,b,c)},this.hasPlugin=function(a,b){var c=d[a];return c&&!!c[b]},this.getPlugin=function(a,b,f){var g=d[a];if(g){var h=g[b];if(h)return void f(h)}var i=a+b,j=e[i]||(e[i]=[]);if(j.push(f),!(j.length>1)){var k=SceneJS_configsModule.configs.pluginPath;if(!k)throw"no pluginPath config";var l=k+"/"+a+"/"+b+".js";c(l)}}};var SceneJS_events=new function(){this.ERROR=0,this.RESET=1,this.NODE_CREATED=2,this.SCENE_CREATED=3,this.SCENE_COMPILING=4,this.SCENE_DESTROYED=5,this.OBJECT_COMPILING=6,this.WEBGL_CONTEXT_LOST=7,this.WEBGL_CONTEXT_RESTORED=8;var a=[];this.addListener=function(b,c,d){var e=a[b];e||(e=[],a[b]=e);for(var f={command:c,priority:void 0==d?e.length:d},g=-1,h=0,i=e.length;i>h;h++)if(!e[h]){g=h;break}0>g&&(e.push(f),g=e.length-1);var j=b+"."+g;return j},this.removeListener=function(b){var c=b.lastIndexOf("."),d=parseInt(b.substr(0,c)),e=parseInt(b.substr(c+1)),f=a[d];f&&delete f[e]},this.fireEvent=function(b,c){var d=a[b];if(d){c=c||{};for(var e=0;e',e.appendChild(f)}var h=document.getElementById(b);if(!h)throw SceneJS_error.fatalError(SceneJS.errors.CANVAS_NOT_FOUND,"SceneJS.Scene attribute 'canvasId' does not match any elements in the page");this.canvasId=b,this.options=d||{},this.canvas=this.options.simulateWebGLContextLost?WebGLDebugUtils.makeLostContextSimulatingCanvas(h):h,this.ssaaMultiplier=this.options.ssaaMultiplier||1,this.canvas.width=this.canvas.clientWidth*this.ssaaMultiplier,this.canvas.height=this.canvas.clientHeight*this.ssaaMultiplier,this.contextAttr=c,this.gl=null,this.initWebGL()};SceneJS_Canvas.prototype._WEBGL_CONTEXT_NAMES=["webgl","experimental-webgl","webkit-3d","moz-webgl","moz-glweb20"],SceneJS_Canvas.prototype.initWebGL=function(){for(var a=0;!this.gl&&af;f++)d.createNode(a.nodes[f],function(a){c.addNode(a),++e==g&&(b&&b(c),d.scene.publish("nodes/"+c.id,c))});else b&&(b(c),d.scene.publish("nodes/"+c.id,c))})},SceneJS_Engine.prototype._doDestroyNodes=function(){for(var a;this._numNodesToDestroy>0;)a=this._nodesToDestroy[--this._numNodesToDestroy],a._doDestroy(),this._coreFactory.putCore(a._core),this._nodeFactory.putNode(a)},SceneJS_Engine.prototype.findNode=function(a){return this._nodeFactory.nodes.items[a]},SceneJS_Engine.prototype.findNodes=function(a){var b=new RegExp(a),c=[],d=this._nodeFactory.nodes.items;for(var e in d)d.hasOwnProperty(e)&&b.test(e)&&c.push(d[e]);return c},SceneJS_Engine.prototype.hasCore=function(a,b){return this._coreFactory.hasCore(a,b)},SceneJS_Engine.prototype.branchDirty=function(a){if(!this.sceneDirty&&a!=window){a.branchDirty=!0,a.dirty=!0;for(var b=a.parent;b&&!b.dirty&&!b.branchDirty;b=b.parent)b.dirty=!0;this._sceneBranchesDirty=!0}},SceneJS_Engine.prototype.renderFrame=function(a){var b=!1;if(this._needCompile()||a&&a.force)for(var c=(new Date).getTime(),d=a&&a.force,e=0;e0?setTimeout(window[e],1e3/d.fps):requestAnimationFrame(window[e]))},setTimeout(window[e],0)}},SceneJS_Engine.prototype.pick=function(a,b,c){this._needCompile()&&this._doCompile();var d=this.display.pick({canvasX:a,canvasY:b,rayPick:c?c.rayPick:!1});return d},SceneJS_Engine.prototype.readPixels=function(a,b){return this._needCompile()&&this._doCompile(),this.display.readPixels(a,b)},SceneJS_Engine.prototype._needCompile=function(){return this.display.imageDirty||this.display.drawListDirty||this.display.stateSortDirty||this.display.stateOrderDirty||this.display.objectListDirty||this._sceneBranchesDirty||this.sceneDirty},SceneJS_Engine.prototype._doCompile=function(){if(this._sceneBranchesDirty||this.sceneDirty){this._sceneBranchesDirty=!1,SceneJS_events.fireEvent(SceneJS_events.SCENE_COMPILING,{engine:this}),this.pubSubProxy=new SceneJS_PubSubProxy(this.scene,null);var a={pubSubProxy:this.pubSubProxy};this.scene._compileNodes(a),this.sceneDirty=!1}this._doDestroyNodes()},SceneJS_Engine.prototype.pause=function(a){this.paused=a},SceneJS_Engine.prototype.stop=function(){this.running&&(this.running=!1,this.paused=!1,window["__scenejs_sceneLoop"+this.id]=null)},SceneJS_Engine.prototype.destroyNode=function(a){this._nodesToDestroy[this._numNodesToDestroy++]=a;var b=this.sceneStatus.nodes[a.id];b&&(this.sceneStatus.numTasks-=b.numTasks,delete this.sceneStatus.nodes[a.id])},SceneJS_Engine.prototype.destroy=function(){this.destroyed=!0},self.Int32Array||(self.Int32Array=Array,self.Float32Array=Array),function(){for(var a=0,b=["ms","moz","webkit","o"],c=0;ch;h++)i[h](g);SceneJS.publish("configs",this.configs)},this.getConfigs=function(a){if(a){for(var b=this.configs,c=a.split("."),d=0;b&&dc;c++)b.push("----");e=b.join("")},this.error=function(a){this._log("error",a)},this.warn=function(a){this._log("warn",a)},this.info=function(a){this._log("info",a)},this.debug=function(a){this._log("debug",a)},this.setFuncs=function(a){if(a){b=a;for(var d in c)this._flush(d)}},this._flush=function(a){var d=c[a];if(d){var e=b?b[a]:null;if(e){for(var f=0;fy;++y)f=b[y],c=f[0],d=f[1],e=f[2],g[y]=[i*c+m*d+q*e+u,j*c+n*d+r*e+v,k*c+o*d+s*e+w,l*c+p*d+t*e+x];return g},SceneJS_math_transformVector3=function(a,b){var c=b[0],d=b[1],e=b[2];return[a[0]*c+a[4]*d+a[8]*e,a[1]*c+a[5]*d+a[9]*e,a[2]*c+a[6]*d+a[10]*e]},SceneJS_math_transformVector4=function(a,b){var c=b[0],d=b[1],e=b[2],f=b[3];return[a[0]*c+a[4]*d+a[8]*e+a[12]*f,a[1]*c+a[5]*d+a[9]*e+a[13]*f,a[2]*c+a[6]*d+a[10]*e+a[14]*f,a[3]*c+a[7]*d+a[11]*e+a[15]*f]},SceneJS_math_projectVec4=function(a){var b=1/a[3];return[a[0]*b,a[1]*b,a[2]*b,1]},SceneJS_math_Plane3=function(a,b,c){if(this.normal=[0,0,1],this.offset=0,a&&b){var d=a[0],e=a[1],f=a[2];if(this.offset=b,c){var g=Math.sqrt(d*d+e*e+f*f);g>0&&(g=1/g,this.normal[0]=d*g,this.normal[1]=e*g,this.normal[2]=f*g,this.offset*=g)}}},SceneJS_math_MAX_DOUBLE=Number.POSITIVE_INFINITY,SceneJS_math_MIN_DOUBLE=Number.NEGATIVE_INFINITY,SceneJS_math_Box3=function(a,b){this.min=a||[SceneJS_math_MAX_DOUBLE,SceneJS_math_MAX_DOUBLE,SceneJS_math_MAX_DOUBLE],this.max=b||[SceneJS_math_MIN_DOUBLE,SceneJS_math_MIN_DOUBLE,SceneJS_math_MIN_DOUBLE],this.init=function(a,b){return this.min[0]=a[0],this.min[1]=a[1],this.min[2]=a[2],this.max[0]=b[0],this.max[1]=b[1],this.max[2]=b[2],this},this.fromPoints=function(a){for(var b=a.length,c=0;b>c;++c){var d=a[c][3],e=a[c][0]/d,f=a[c][1]/d,g=a[c][2]/d;ethis.max[0]&&(this.max[0]=e),f>this.max[1]&&(this.max[1]=f),g>this.max[2]&&(this.max[2]=g)}return this},this.isEmpty=function(){return this.min[0]>=this.max[0]&&this.min[1]>=this.max[1]&&this.min[2]>=this.max[2]},this.getCenter=function(){return[(this.max[0]+this.min[0])/2,(this.max[1]+this.min[1])/2,(this.max[2]+this.min[2])/2]},this.getSize=function(){return[this.max[0]-this.min[0],this.max[1]-this.min[1],this.max[2]-this.min[2]]},this.getFacesAreas=function(){var a=this.size;return[a[1]*a[2],a[0]*a[2],a[0]*a[1]]},this.getSurfaceArea=function(){var a=this.getFacesAreas();return 2*(a[0]+a[1]+a[2])},this.getVolume=function(){var a=this.size;return a[0]*a[1]*a[2]},this.getOffset=function(a){return this.min[0]-=a,this.min[1]-=a,this.min[2]-=a,this.max[0]+=a,this.max[1]+=a,this.max[2]+=a,this}},SceneJS_math_AxisBox3=function(a,b){var c=a[0],d=a[1],e=a[2],f=b[0],g=b[1],h=b[2];this.verts=[[c,d,e],[f,d,e],[f,g,e],[c,g,e],[c,d,h],[f,d,h],[f,g,h],[c,g,h]],this.toBox3=function(){for(var a=new SceneJS_math_Box3,b=0;8>b;++b)for(var c=this.verts[b],d=0;3>d;++d)c[d]a.max[d]&&(a.max[d]=c[d])}},SceneJS_math_Sphere3=function(a,b){this.center=[a[0],a[1],a[2]],this.radius=b,this.isEmpty=function(){return 0===this.radius},this.surfaceArea=function(){return 4*Math.PI*this.radius*this.radius},this.getVolume=function(){var a=this.radius;return 4/3*Math.PI*a*a*a}},SceneJS_math_billboardMat=function(a){var b=[SceneJS_math_getColMat4(a,0),SceneJS_math_getColMat4(a,1),SceneJS_math_getColMat4(a,2)],c=[SceneJS_math_lenVec4(b[0]),SceneJS_math_lenVec4(b[1]),SceneJS_math_lenVec4(b[2])],d=SceneJS_math_mat4();SceneJS_math_rcpVec3(c,d);var e=SceneJS_math_scalingMat4v(c);SceneJS_math_mulVec4Scalar(b[0],d[0]),SceneJS_math_mulVec4Scalar(b[1],d[1]),SceneJS_math_mulVec4Scalar(b[2],d[2]);var f=SceneJS_math_identityMat4();return SceneJS_math_setRowMat4(f,0,b[0]),SceneJS_math_setRowMat4(f,1,b[1]),SceneJS_math_setRowMat4(f,2,b[2]),SceneJS_math_mulMat4(f,e)},SceneJS_math_FrustumPlane=function(a,b,c,d){var e=1/Math.sqrt(a*a+b*b+c*c);this.normal=[a*e,b*e,c*e],this.offset=d*e,this.testVertex=[this.normal[0]>=0?1:0,this.normal[1]>=0?1:0,this.normal[2]>=0?1:0]},SceneJS_math_OUTSIDE_FRUSTUM=3,SceneJS_math_INTERSECT_FRUSTUM=4,SceneJS_math_INSIDE_FRUSTUM=5,SceneJS_math_Frustum=function(a,b,c){var d=SceneJS_math_mat4();SceneJS_math_mulMat4(b,a,d);var e=d[0],f=d[1],g=d[2],h=d[3],i=d[4],j=d[5],k=d[6],l=d[7],m=d[8],n=d[9],o=d[10],p=d[11],q=d[12],r=d[13],s=d[14],t=d[15],u=[new SceneJS_math_FrustumPlane(h-e,l-i,p-m,t-q),new SceneJS_math_FrustumPlane(h+e,l+i,p+m,t+q),new SceneJS_math_FrustumPlane(h-f,l-j,p-n,t-r),new SceneJS_math_FrustumPlane(h+f,l+j,p+n,t+r),new SceneJS_math_FrustumPlane(h-g,l-k,p-o,t-s),new SceneJS_math_FrustumPlane(h+g,l+k,p+o,t+s)],v=[SceneJS_math_getColMat4(a,0),SceneJS_math_getColMat4(a,1),SceneJS_math_getColMat4(a,2)],w=[SceneJS_math_lenVec4(v[0]),SceneJS_math_lenVec4(v[1]),SceneJS_math_lenVec4(v[2])],x=SceneJS_math_rcpVec3(w),y=SceneJS_math_scalingMat4v(w),z=SceneJS_math_scalingMat4v(x);SceneJS_math_mulVec4Scalar(v[0],x[0]),SceneJS_math_mulVec4Scalar(v[1],x[1]),SceneJS_math_mulVec4Scalar(v[2],x[2]);var A=SceneJS_math_identityMat4();SceneJS_math_setRowMat4(A,0,v[0]),SceneJS_math_setRowMat4(A,1,v[1]),SceneJS_math_setRowMat4(A,2,v[2]),this.matrix||(this.matrix=SceneJS_math_mat4()),SceneJS_math_mulMat4(b,a,this.matrix),this.billboardMatrix||(this.billboardMatrix=SceneJS_math_mat4()),SceneJS_math_mulMat4(z,SceneJS_math_mulMat4(A,y),this.billboardMatrix),this.viewport=c.slice(0,4),this.textAxisBoxIntersection=function(a){for(var b=SceneJS_math_INSIDE_FRUSTUM,c=[a.min,a.max],d=null,e=0;6>e;++e){if(d=u[e],d.normal[0]*c[d.testVertex[0]][0]+d.normal[1]*c[d.testVertex[1]][1]+d.normal[2]*c[d.testVertex[2]][2]+d.offset<0)return SceneJS_math_OUTSIDE_FRUSTUM;d.normal[0]*c[1-d.testVertex[0]][0]+d.normal[1]*c[1-d.testVertex[1]][1]+d.normal[2]*c[1-d.testVertex[2]][2]+d.offset<0&&(b=SceneJS_math_INTERSECT_FRUSTUM)}return b},this.getProjectedSize=function(a){var b=SceneJS_math_mat4();SceneJS_math_subVec3(a.max,a.min,b);var d=SceneJS_math_lenVec3(b),e=Math.abs(d),f=[.5*(a.min[0]+a.max[0]),.5*(a.min[1]+a.max[1]),.5*(a.min[2]+a.max[2]),0],g=.5*e,h=[-g,0,0,1],i=[g,0,0,1];return h=SceneJS_math_mulMat4v4(this.billboardMatrix,h),h=SceneJS_math_addVec4(h,f),h=SceneJS_math_projectVec4(SceneJS_math_mulMat4v4(this.matrix,h)),i=SceneJS_math_mulMat4v4(this.billboardMatrix,i),i=SceneJS_math_addVec4(i,f),i=SceneJS_math_projectVec4(SceneJS_math_mulMat4v4(this.matrix,i)),c[2]*Math.abs(i[0]-h[0])},this.getProjectedState=function(a){for(var b,d,e,f=SceneJS_math_transformPoints3(this.matrix,a),g=1e7,h=1e7,i=-1e7,j=-1e7,k=f.length,l=0;k>l;++l)b=SceneJS_math_projectVec4(f[l]),d=b[0],e=b[1],-.5>d&&(d=-.5),-.5>e&&(e=-.5),d>.5&&(d=.5),e>.5&&(e=.5),g>d&&(g=d),h>e&&(h=e),d>i&&(i=d),e>j&&(j=e);g+=.5,h+=.5,i+=.5,j+=.5;var m=c[2],n=c[3];g*=m+15,h*=n+15,i*=m+15,j*=n+15;var o=SceneJS_math_mat4();SceneJS_math_subVec2([i,j],[g,h],o);var p=SceneJS_math_lenVec2(o);return 0>g&&(g=0),i>m&&(i=m),0>h&&(h=0),j>n&&(j=n),{canvasBox:{min:[g,h],max:[i,j]},canvasSize:p}}},SceneJS_math_identityQuaternion=function(){return[0,0,0,1]},SceneJS_math_angleAxisQuaternion=function(a,b,c,d){var e=d/180*Math.PI,f=e/2,g=Math.sin(f);return[g*a,g*b,g*c,Math.cos(f)]},SceneJS_math_mulQuaternions=function(a,b){var c=a[0],d=a[1],e=a[2],f=a[3],g=b[0],h=b[1],i=b[2],j=b[3];return[f*g+c*j+d*i-e*h,f*h+d*j+e*g-c*i,f*i+e*j+c*h-d*g,f*j-c*g-d*h-e*i]},SceneJS_math_newMat4FromQuaternion=function(a){var b=a[0],c=a[1],d=a[2],e=a[3],f=2*b,g=2*c,h=2*d,i=f*e,j=g*e,k=h*e,l=f*b,m=g*b,n=h*b,o=g*c,p=h*c,q=h*d,r=SceneJS_math_identityMat4();return SceneJS_math_setCellMat4(r,0,0,1-(o+q)),SceneJS_math_setCellMat4(r,0,1,m-k),SceneJS_math_setCellMat4(r,0,2,n+j),SceneJS_math_setCellMat4(r,1,0,m+k),SceneJS_math_setCellMat4(r,1,1,1-(l+q)),SceneJS_math_setCellMat4(r,1,2,p-i),SceneJS_math_setCellMat4(r,2,0,n-j),SceneJS_math_setCellMat4(r,2,1,p+i),SceneJS_math_setCellMat4(r,2,2,1-(l+o)),r},SceneJS_math_slerp=function(a,b,c){var d=.0174532925*b[3],e=.0174532925*c[3],f=d*e+b[0]*c[0]+b[1]*c[1]+b[2]*c[2];if(Math.abs(f)>=1)return[b[0],b[1],b[2],b[3]];var g=Math.acos(f),h=Math.sqrt(1-f*f);if(Math.abs(h)<.001)return[.5*b[0]+.5*c[0],.5*b[1]+.5*c[1],.5*b[2]+.5*c[2],.5*b[3]+.5*c[3]];var i=Math.sin((1-a)*g)/h,j=Math.sin(a*g)/h;return[b[0]*i+c[0]*j,b[1]*i+c[1]*j,b[2]*i+c[2]*j,57.295779579*(d*i+e*j)]},SceneJS_math_normalizeQuaternion=function(a){var b=SceneJS_math_lenVec4([a[0],a[1],a[2],a[3]]);return[a[0]/b,a[1]/b,a[2]/b,a[3]/b]},SceneJS_math_conjugateQuaternion=function(a){return[-a[0],-a[1],-a[2],a[3]]},SceneJS_math_angleAxisFromQuaternion=function(a){a=SceneJS_math_normalizeQuaternion(a);var b=a[3],c=2*Math.acos(b),d=Math.sqrt(1-b*b);return.001>d?{x:a[0],y:a[1],z:a[2],angle:57.295779579*c}:{x:a[0]/d,y:a[1]/d,z:a[2]/d,angle:57.295779579*c}},SceneJS_sceneStatusModule=new function(){function a(a){var b=document.getElementsByTagName("body")[0],c=document.createElement("div"),d=c.style;return d.position="absolute",d.width="200px",d.right="10px",d.top="0",d.padding="10px",d["z-index"]="10000",b.appendChild(c),c}function b(a,b){var c=document.createElement("div"),d=c.style;return d["font-family"]="Helvetica",d["font-size"]="14px",d.padding="5px",d.margin="4px",d["padding-left"]="12px",d.border="1px solid #000055",d.color="black",d.background="#AAAAAA",d.opacity="0.8",d["border-radius"]="3px",d["-moz-border-radius"]="3px",d["box-shadow"]="3px 3px 3px #444444",c.innerHTML=b,a.appendChild(c),c}function c(a){a.style.background="#AAFFAA";var b=.8,c=setInterval(function(){0>=b?(a.parentNode.removeChild(a),clearInterval(c)):(a.style.opacity=b,b-=.1)},100)}function d(a){a.style.background="#FFAAAA"}this.sceneStatus={};var e=new SceneJS_Map,f={},g={},h=this;SceneJS_events.addListener(SceneJS_events.SCENE_DESTROYED,function(a){var b=a.engine.id;delete h.sceneStatus[b],delete g[b]}),this.taskStarted=function(c,d){var h=SceneJS_configsModule.configs.statusPopups!==!1,i=c.getScene(),j=i.getId(),k=c.getId(),l=i.getCanvas(),m=e.addItem(),n=this.sceneStatus[j];n||(n=this.sceneStatus[j]={numTasks:0}),n.numTasks++;var o=g[j];o||(o=g[j]={sceneId:j,nodeStates:{},scene:i,popupContainer:h?a(l):null,descCounts:{}});var p=o.descCounts[d];void 0==p&&(p=o.descCounts[d]=0),o.descCounts[d]++;var q=o.nodeStates[k];q||(q=o.nodeStates[k]={nodeId:k,numTasks:0,tasks:{}}),d=d+" "+o.descCounts[d]+"...",q.numTasks++;var r={sceneState:o,nodeState:q,description:d,element:h?b(o.popupContainer,d):null};return q.tasks[m]=r,f[m]=r,m},this.taskFinished=function(a){if(-1==a||null==a)return null;var b=f[a];if(!b)return null;var d=b.sceneState;this.sceneStatus[d.sceneId].numTasks--,b.element&&c(b.element);var e=b.nodeState;return--e.numTasks<0&&(e.numTasks=0),delete e.tasks[a],0==e.numTasks&&delete d.nodeStates[e.nodeId],null},this.taskFailed=function(a){if(-1==a||null==a)return null;var b=f[a];if(!b)return null;var c=!!SceneJS_configsModule.configs.statusPopups,e=b.sceneState;this.sceneStatus[e.sceneId].numTasks--,c&&d(b.element);var g=b.nodeState;return g.numTasks--,delete g.tasks[a],0==g.numTasks&&delete b.sceneState.nodeStates[g.nodeId],null}};SceneJS._webgl={},SceneJS._webgl.ArrayBuffer=function(a,b,c,d,e,f){this.allocated=!1,this.gl=a,this.type=b, -this.numItems=d,this.itemSize=e,this.usage=f,this._allocate(c,d)},SceneJS._webgl.ArrayBuffer.prototype._allocate=function(a,b){if(this.allocated=!1,this.handle=this.gl.createBuffer(),!this.handle)throw SceneJS_error.fatalError(SceneJS.errors.OUT_OF_VRAM,"Failed to allocate WebGL ArrayBuffer");this.handle&&(this.gl.bindBuffer(this.type,this.handle),this.gl.bufferData(this.type,a,this.usage),this.gl.bindBuffer(this.type,null),this.numItems=b,this.length=a.length,this.allocated=!0)},SceneJS._webgl.ArrayBuffer.prototype.setData=function(a,b){this.allocated&&(a.length>this.length?(this.destroy(),this._allocate(a,a.length)):b||0===b?this.gl.bufferSubData(this.type,b,a):this.gl.bufferData(this.type,a))},SceneJS._webgl.ArrayBuffer.prototype.unbind=function(){this.allocated&&this.gl.bindBuffer(this.type,null)},SceneJS._webgl.ArrayBuffer.prototype.destroy=function(){this.allocated&&(this.gl.deleteBuffer(this.handle),this.handle=null,this.allocated=!1)},SceneJS._webgl.ArrayBuffer.prototype.bind=function(){this.allocated&&this.gl.bindBuffer(this.type,this.handle)},SceneJS._webgl.Attribute=function(a,b,c,d,e,f){this.gl=a,this.location=f,this.bindFloatArrayBuffer=function(b){b&&(b.bind(),a.enableVertexAttribArray(f),a.vertexAttribPointer(f,b.itemSize,a.FLOAT,!1,0,0))}},SceneJS._webgl.Attribute.prototype.bindInterleavedFloatArrayBuffer=function(a,b,c){this.gl.enableVertexAttribArray(this.location),this.gl.vertexAttribPointer(this.location,a,this.gl.FLOAT,!1,b,c)},SceneJS._webgl.enumMap={funcAdd:"FUNC_ADD",funcSubtract:"FUNC_SUBTRACT",funcReverseSubtract:"FUNC_REVERSE_SUBTRACT",zero:"ZERO",one:"ONE",srcColor:"SRC_COLOR",oneMinusSrcColor:"ONE_MINUS_SRC_COLOR",dstColor:"DST_COLOR",oneMinusDstColor:"ONE_MINUS_DST_COLOR",srcAlpha:"SRC_ALPHA",oneMinusSrcAlpha:"ONE_MINUS_SRC_ALPHA",dstAlpha:"DST_ALPHA",oneMinusDstAlpha:"ONE_MINUS_DST_ALPHA",contantColor:"CONSTANT_COLOR",oneMinusConstantColor:"ONE_MINUS_CONSTANT_COLOR",constantAlpha:"CONSTANT_ALPHA",oneMinusConstantAlpha:"ONE_MINUS_CONSTANT_ALPHA",srcAlphaSaturate:"SRC_ALPHA_SATURATE",front:"FRONT",back:"BACK",frontAndBack:"FRONT_AND_BACK",never:"NEVER",less:"LESS",equal:"EQUAL",lequal:"LEQUAL",greater:"GREATER",notequal:"NOTEQUAL",gequal:"GEQUAL",always:"ALWAYS",cw:"CW",ccw:"CCW",linear:"LINEAR",nearest:"NEAREST",linearMipMapNearest:"LINEAR_MIPMAP_NEAREST",nearestMipMapNearest:"NEAREST_MIPMAP_NEAREST",nearestMipMapLinear:"NEAREST_MIPMAP_LINEAR",linearMipMapLinear:"LINEAR_MIPMAP_LINEAR",repeat:"REPEAT",clampToEdge:"CLAMP_TO_EDGE",mirroredRepeat:"MIRRORED_REPEAT",alpha:"ALPHA",rgb:"RGB",rgba:"RGBA",luminance:"LUMINANCE",luminanceAlpha:"LUMINANCE_ALPHA",textureBinding2D:"TEXTURE_BINDING_2D",textureBindingCubeMap:"TEXTURE_BINDING_CUBE_MAP",compareRToTexture:"COMPARE_R_TO_TEXTURE",unsignedByte:"UNSIGNED_BYTE"},SceneJS._webgl.RenderBuffer=function(a){this.allocated=!1,this.canvas=a.canvas,this.gl=a.canvas.gl,this.buf=null,this.bound=!1},SceneJS._webgl.RenderBuffer.prototype.webglRestored=function(a){this.gl=a,this.buf=null,this.allocated=!1,this.bound=!1},SceneJS._webgl.RenderBuffer.prototype.bind=function(){this._touch(),this.bound||(this.gl.bindFramebuffer(this.gl.FRAMEBUFFER,this.buf.framebuf),this.bound=!0)},SceneJS._webgl.RenderBuffer.prototype._touch=function(){var a=this.canvas.canvas.width,b=this.canvas.canvas.height;if(this.buf){if(this.buf.width==a&&this.buf.height==b)return;this.gl.deleteTexture(this.buf.texture),this.gl.deleteFramebuffer(this.buf.framebuf),this.gl.deleteRenderbuffer(this.buf.renderbuf)}this.buf={framebuf:this.gl.createFramebuffer(),renderbuf:this.gl.createRenderbuffer(),texture:this.gl.createTexture(),width:a,height:b},this.gl.bindFramebuffer(this.gl.FRAMEBUFFER,this.buf.framebuf),this.gl.bindTexture(this.gl.TEXTURE_2D,this.buf.texture),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_MAG_FILTER,this.gl.NEAREST),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_MIN_FILTER,this.gl.NEAREST),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_WRAP_S,this.gl.CLAMP_TO_EDGE),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_WRAP_T,this.gl.CLAMP_TO_EDGE);try{this.gl.texImage2D(this.gl.TEXTURE_2D,0,this.gl.RGBA,a,b,0,this.gl.RGBA,this.gl.UNSIGNED_BYTE,null)}catch(c){var d=new WebGLUnsignedByteArray(a*b*3);this.gl.texImage2D(this.gl.TEXTURE_2D,0,this.gl.RGBA,a,b,0,this.gl.RGBA,this.gl.UNSIGNED_BYTE,d)}if(this.gl.bindRenderbuffer(this.gl.RENDERBUFFER,this.buf.renderbuf),this.gl.renderbufferStorage(this.gl.RENDERBUFFER,this.gl.DEPTH_COMPONENT16,a,b),this.gl.framebufferTexture2D(this.gl.FRAMEBUFFER,this.gl.COLOR_ATTACHMENT0,this.gl.TEXTURE_2D,this.buf.texture,0),this.gl.framebufferRenderbuffer(this.gl.FRAMEBUFFER,this.gl.DEPTH_ATTACHMENT,this.gl.RENDERBUFFER,this.buf.renderbuf),this.gl.bindTexture(this.gl.TEXTURE_2D,null),this.gl.bindRenderbuffer(this.gl.RENDERBUFFER,null),this.gl.bindFramebuffer(this.gl.FRAMEBUFFER,null),this.gl.bindFramebuffer(this.gl.FRAMEBUFFER,this.buf.framebuf),!this.gl.isFramebuffer(this.buf.framebuf))throw SceneJS_error.fatalError(SceneJS.errors.INVALID_FRAMEBUFFER,"Invalid framebuffer");var e=this.gl.checkFramebufferStatus(this.gl.FRAMEBUFFER);switch(e){case this.gl.FRAMEBUFFER_COMPLETE:break;case this.gl.FRAMEBUFFER_INCOMPLETE_ATTACHMENT:throw SceneJS_error.fatalError(SceneJS.errors.ERROR,"Incomplete framebuffer: FRAMEBUFFER_INCOMPLETE_ATTACHMENT");case this.gl.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:throw SceneJS_error.fatalError(SceneJS.errors.ERROR,"Incomplete framebuffer: FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT");case this.gl.FRAMEBUFFER_INCOMPLETE_DIMENSIONS:throw SceneJS_error.fatalError(SceneJS.errors.ERROR,"Incomplete framebuffer: FRAMEBUFFER_INCOMPLETE_DIMENSIONS");case this.gl.FRAMEBUFFER_UNSUPPORTED:throw SceneJS_error.fatalError(SceneJS.errors.ERROR,"Incomplete framebuffer: FRAMEBUFFER_UNSUPPORTED");default:throw SceneJS_error.fatalError(SceneJS.errors.ERROR,"Incomplete framebuffer: "+e)}this.bound=!1},SceneJS._webgl.RenderBuffer.prototype.clear=function(){if(!this.bound)throw"Render buffer not bound";this.gl.clear(this.gl.COLOR_BUFFER_BIT|this.gl.DEPTH_BUFFER_BIT),this.gl.disable(this.gl.BLEND)},SceneJS._webgl.RenderBuffer.prototype.read=function(a,b){var c=a,d=this.canvas.canvas.height-b,e=new Uint8Array(4);return this.gl.readPixels(c,d,1,1,this.gl.RGBA,this.gl.UNSIGNED_BYTE,e),e},SceneJS._webgl.RenderBuffer.prototype.unbind=function(){this.gl.bindFramebuffer(this.gl.FRAMEBUFFER,null),this.bound=!1},SceneJS._webgl.RenderBuffer.prototype.getTexture=function(){var a=this;return{bind:function(b){return a.buf&&a.buf.texture?(a.gl.activeTexture(a.gl["TEXTURE"+b]),a.gl.bindTexture(a.gl.TEXTURE_2D,a.buf.texture),!0):!1},unbind:function(b){a.buf&&a.buf.texture&&(a.gl.activeTexture(a.gl["TEXTURE"+b]),a.gl.bindTexture(a.gl.TEXTURE_2D,null))}}},SceneJS._webgl.RenderBuffer.prototype.destroy=function(){this.buf&&(this.gl.deleteTexture(this.buf.texture),this.gl.deleteFramebuffer(this.buf.framebuf),this.gl.deleteRenderbuffer(this.buf.renderbuf),this.buf=null,this.bound=!1)},SceneJS._webgl.Program=function(a,b,c){this.allocated=!1,this.gl=a,this._uniforms={},this._samplers={},this._attributes={},this.uniformValues=[],this.materialSettings={specularColor:[0,0,0],specular:0,shine:0,emit:0,alpha:0},this._shaders=[];var d,e,f,g,h,i;for(e=0;ee;++e)f=a.getActiveUniform(this.handle,e),f&&(g=f.name,"\x00"==g[g.length-1]&&(g=g.substr(0,g.length-1)),h=a.getUniformLocation(this.handle,g),f.type==a.SAMPLER_2D||f.type==a.SAMPLER_CUBE||35682==f.type?this._samplers[g]=new SceneJS._webgl.Sampler(a,this.handle,g,f.type,f.size,h):(this._uniforms[g]=new SceneJS._webgl.Uniform(a,this.handle,g,f.type,f.size,h,k),this.uniformValues[k]=null,++k));var l=a.getProgramParameter(this.handle,a.ACTIVE_ATTRIBUTES);for(e=0;l>e;e++)d=a.getActiveAttrib(this.handle,e),d&&(h=a.getAttribLocation(this.handle,d.name),this._attributes[d.name]=new SceneJS._webgl.Attribute(a,this.handle,d.name,d.type,d.size,h));this.allocated=!0}},SceneJS._webgl.Program.prototype.bind=function(){this.allocated&&this.gl.useProgram(this.handle)},SceneJS._webgl.Program.prototype.getUniformLocation=function(a){if(this.allocated){var b=this._uniforms[a];return b?b.getLocation():void 0}},SceneJS._webgl.Program.prototype.getUniform=function(a){if(this.allocated){var b=this._uniforms[a];return b?b:void 0}},SceneJS._webgl.Program.prototype.getAttribute=function(a){if(this.allocated){var b=this._attributes[a];return b?b:void 0}},SceneJS._webgl.Program.prototype.bindFloatArrayBuffer=function(a,b){if(this.allocated){var c=this._attributes[a];c&&c.bindFloatArrayBuffer(b)}},SceneJS._webgl.Program.prototype.bindTexture=function(a,b,c){if(!this.allocated)return!1;var d=this._samplers[a];return d?d.bindTexture(b,c):!1},SceneJS._webgl.Program.prototype.destroy=function(){if(this.allocated){this.gl.deleteProgram(this.handle);for(var a in this._shaders)this.gl.deleteShader(this._shaders[a].handle);this.handle=null,this._attributes=null,this._uniforms=null,this._samplers=null,this.allocated=!1}},SceneJS._webgl.Program.prototype.setUniform=function(a,b){if(this.allocated){var c=this._uniforms[a];c&&(this.uniformValues[c.index]===b&&c.numberValue||(c.setValue(b),this.uniformValues[c.index]=b))}},SceneJS._webgl.Sampler=function(a,b,c,d,e,f){this.bindTexture=function(b,c){return b.bind(c)?(a.uniform1i(f,c),!0):!1}},SceneJS._webgl.Shader=function(a,b,c){if(this.allocated=!1,this.handle=a.createShader(b),!this.handle)throw SceneJS_error.fatalError(SceneJS.errors.OUT_OF_VRAM,"Failed to create WebGL shader");if(a.shaderSource(this.handle,c),a.compileShader(this.handle),this.valid=0!=a.getShaderParameter(this.handle,a.COMPILE_STATUS),!this.valid&&!a.isContextLost()){SceneJS.log.error("Shader program failed to compile: "+a.getShaderInfoLog(this.handle)),SceneJS.log.error("Shader source:");for(var d=c.split("\n"),e=0;eb){var d=b/c,e=a.width*d,f=a.height*d,g=document.createElement("canvas");g.width=SceneJS._webgl.nextHighestPowerOfTwo(e),g.height=SceneJS._webgl.nextHighestPowerOfTwo(f);var h=g.getContext("2d");h.drawImage(a,0,0,a.width,a.height,0,0,g.width,g.height),a=g}return a},SceneJS._webgl.ensureImageSizePowerOfTwo=function(a){if(!SceneJS._webgl.isPowerOfTwo(a.width)||!SceneJS._webgl.isPowerOfTwo(a.height)){var b=document.createElement("canvas");b.width=SceneJS._webgl.nextHighestPowerOfTwo(a.width),b.height=SceneJS._webgl.nextHighestPowerOfTwo(a.height);var c=b.getContext("2d");c.drawImage(a,0,0,a.width,a.height,0,0,b.width,b.height),a=b}return a},SceneJS._webgl.isPowerOfTwo=function(a){return 0==(a&a-1)},SceneJS._webgl.nextHighestPowerOfTwo=function(a){--a;for(var b=1;32>b;b<<=1)a|=a>>b;return a+1},SceneJS._webgl.Uniform=function(a,b,c,d,e,f,g,h){var i=null;if(this.numberValue=!1,d==a.BOOL)this.numberValue=!0,i=function(b){a.uniform1i(f,b)};else if(d==a.BOOL_VEC2)i=function(b){a.uniform2iv(f,b)};else if(d==a.BOOL_VEC3)i=function(b){a.uniform3iv(f,b)};else if(d==a.BOOL_VEC4)i=function(b){a.uniform4iv(f,b)};else if(d==a.INT)this.numberValue=!0,i=function(b){a.uniform1iv(f,b)};else if(d==a.INT_VEC2)i=function(b){a.uniform2iv(f,b)};else if(d==a.INT_VEC3)i=function(b){a.uniform3iv(f,b)};else if(d==a.INT_VEC4)i=function(b){a.uniform4iv(f,b)};else if(d==a.FLOAT)this.numberValue=!0,i=function(b){a.uniform1f(f,b)};else if(d==a.FLOAT_VEC2)i=function(b){a.uniform2fv(f,b)};else if(d==a.FLOAT_VEC3)i=function(b){a.uniform3fv(f,b)};else if(d==a.FLOAT_VEC4)i=function(b){a.uniform4fv(f,b)};else if(d==a.FLOAT_MAT2)i=function(b){a.uniformMatrix2fv(f,a.FALSE,b)};else if(d==a.FLOAT_MAT3)i=function(b){a.uniformMatrix3fv(f,a.FALSE,b)};else{if(d!=a.FLOAT_MAT4)throw"Unsupported shader uniform type: "+d;i=function(b){a.uniformMatrix4fv(f,a.FALSE,b)}}this.setValue=i,this.getValue=function(){return a.getUniform(b,f)},this.getLocation=function(){return f},this.index=g};var SceneJS_nodeEventsModule=new function(){var a,b=[],c=[],d=0,e={type:"listeners",stateId:SceneJS._baseStateId++,empty:!0,listeners:[]};SceneJS_events.addListener(SceneJS_events.SCENE_COMPILING,function(){d=0,a=!0}),SceneJS_events.addListener(SceneJS_events.OBJECT_COMPILING,function(f){if(a){if(d>0){var g={type:"listeners",stateId:b[d-1],listeners:c.slice(0,d)};f.display.renderListeners=g}else f.display.renderListeners=e;a=!1}}),this.preVisitNode=function(e){var f=e._topicSubs.rendered,g=e._topicSubs.worldPos,h=e._topicSubs.viewPos,i=e._topicSubs.cameraPos,j=e._topicSubs.projPos,k=e._topicSubs.canvasPos;(f||g||h||i||j||k)&&(b[d]=e.id,c[d]=function(a){f&&e.publish("rendered",a,!0),g&&e.publish("worldPos",a.getWorldPos()),h&&e.publish("viewPos",a.getViewPos()),i&&e.publish("cameraPos",a.getCameraPos()),j&&e.publish("projPos",a.getProjPos()),k&&e.publish("canvasPos",a.getCanvasPos())},d++,a=!0)},this.postVisitNode=function(c){c.id==b[d-1]&&(d--,a=!0)}},SceneJS_Core=function(a){this.type=a,this.coreId=null,this.stateId=null,this.useCount=0},SceneJS_CoreFactory=function(){this._stateMap=new SceneJS_Map(null,SceneJS._baseStateId),this._cores={}};SceneJS_CoreFactory.coreTypes={},SceneJS_CoreFactory.createCoreType=function(a,b){},SceneJS_CoreFactory.addCoreBuilder=function(a,b){},SceneJS_CoreFactory.coreAliases={rotate:"xform",translate:"xform",scale:"xform",matrix:"xform",xform:"xform"},SceneJS_CoreFactory.prototype.getCore=function(a,b){var c=SceneJS_CoreFactory.coreAliases[a];c&&(a=c);var d=this._cores[a];d||(d=this._cores[a]={});var e;return b&&(e=d[b])?(e.useCount++,e):(e=new SceneJS_Core(a),e.useCount=1,e.stateId=this._stateMap.addItem(e),e.coreId=void 0!=b&&null!=b?b:e.stateId,d[e.coreId]=e,e)},SceneJS_CoreFactory.prototype.hasCore=function(a,b){var c=SceneJS_CoreFactory.coreAliases[a];c&&(a=c);var d=this._cores[a];return d&&d[b]},SceneJS_CoreFactory.prototype.putCore=function(a){if(0!=a.useCount&&--a.useCount<=0){var b=this._cores[a.type];delete b[a.coreId],this._stateMap.removeItem(a.stateId)}},SceneJS_CoreFactory.prototype.webglRestored=function(){var a,b;for(var c in this._cores)if(this._cores.hasOwnProperty(c)&&(a=this._cores[c]))for(var d in a)a.hasOwnProperty(d)&&(b=a[d],b&&b.webglRestored&&b.webglRestored())},SceneJS.Node=function(){},SceneJS.Node.prototype.constructor=SceneJS.Node,SceneJS.Node.prototype._construct=function(a,b,c,d){this._engine=a,this._core=b,this.coreId=b.coreId,this.id=c.id||c.nodeId||d,this.type=c.type||"node",this.data=c.data,this.parent=null,this.nodes=[],this._handleMap=new SceneJS_Map,this._topicSubs={},this._handleTopics={},this._topicPubs={},this._listeners={},this._numListeners=0,this.dirty=!1,this.branchDirty=!1,this._init&&this._init(c)},SceneJS.Node.prototype.taskStarted=function(a){return SceneJS_sceneStatusModule.taskStarted(this,a||"Task")},SceneJS.Node.prototype.taskFinished=function(a){return SceneJS_sceneStatusModule.taskFinished(a)},SceneJS.Node.prototype.taskFailed=function(a){return SceneJS_sceneStatusModule.taskFailed(a)},SceneJS.Node.prototype.log=function(){var a,b;switch(1==arguments.length?(a="info",b=arguments[0]):2==arguments.length&&(a=arguments[0],b=arguments[1]),a){case"warn":b="WARN; [SceneJS.Node type="+this.type+", id="+this.id+"] : "+b;break;case"error":b="ERROR; [SceneJS.Node type="+this.type+", id="+this.id+"] : "+b;break;default:b="INFO; [SceneJS.Node type="+this.type+", id="+this.id+"] : "+b}console[a]?console[a](b):console.log(b)},SceneJS.Node.prototype.publish=function(a,b,c){if(c||(this._topicPubs[a]=b),this._topicSubs[a]){var d=this._topicSubs[a];for(var e in d)d.hasOwnProperty(e)&&d[e].call(this,b)}},SceneJS.Node.prototype.unpublish=function(a){var b=this._topicSubs[a];if(b)for(var c in b)b.hasOwnProperty(c)&&b[c].call(this,null);delete this._topicPubs[a]},SceneJS.Node.prototype.on=function(a,b){var c=this._topicSubs[a];c||(c={},this._topicSubs[a]=c);var d=this._handleMap.addItem();c[d]=b,this._handleTopics[d]=a;var e=this._topicPubs[a];return e&&b.call(this,e),"rendered"==a&&this._engine.branchDirty(this),d},SceneJS.Node.prototype.off=function(a){var b=this._handleTopics[a];if(b){delete this._handleTopics[a];var c=this._topicSubs[b];c&&delete c[a],this._handleMap.removeItem(a),"rendered"==b&&this._engine.branchDirty(this)}},SceneJS.Node.prototype.once=function(a,b){var c=this,d=this.on(a,function(a){c.off(d),b(a)})},SceneJS.Node.prototype.getScene=function(){return this._engine.scene},SceneJS.Node.prototype.getCoreId=function(){return this._core.coreId},SceneJS.Node.prototype.getID=function(){return this.id},SceneJS.Node.prototype.getId=function(){return this.id},SceneJS.Node.prototype.getNodeId=function(){return this.id},SceneJS.Node.prototype.getType=function(){return this.type},SceneJS.Node.prototype.getData=function(){return this.data},SceneJS.Node.prototype.setData=function(a){return this.data=a,this},SceneJS.Node.prototype.getNumNodes=function(){return this.nodes.length},SceneJS.Node.prototype.getNodes=function(){return this.nodes.slice(0)},SceneJS.Node.prototype.getNodeAt=function(a){return 0>a||a>=this.nodes.length?null:this.nodes[a]},SceneJS.Node.prototype.getFirstNode=function(){return 0==this.nodes.length?null:this.nodes[0]},SceneJS.Node.prototype.getLastNode=function(){return 0==this.nodes.length?null:this.nodes[this.nodes.length-1]},SceneJS.Node.prototype.getNode=function(a){for(var b=0;b0?(b[0].parent=null,this._engine.display.objectListDirty=!0,b[0]):null},SceneJS.Node.prototype.disconnect=function(){if(this.parent){for(var a=0;ab;b++)this.nodes[b].parent=null;var c=this.nodes;return this.nodes=[],this._engine.display.objectListDirty=!0,c},SceneJS.Node.prototype.removeNodes=function(){for(var a=this.disconnectNodes(),b=0;ba;a++)d[a].parent=this.parent;for(a=0,b=c.nodes.length;b>a;a++)if(c.nodes[a]===this)return c.nodes.splice.apply(c.nodes,[a,1].concat(d)),this.nodes=[],this.parent=null,this.destroy(),this._engine.branchDirty(c),c},SceneJS.Node.prototype.addNodes=function(a,b){if(!a)throw SceneJS_error.fatalError(SceneJS.errors.ILLEGAL_NODE_CONFIG,"Node#addNodes - nodes argument is undefined");for(var c,d=[],e=a.length,f=a.length-1;f>=0;f--){var g=a[f];if("node"==g.type||this._engine.hasNodeType(g.type)){if(c=this.addNode(g),d[f]=c,0==--e)return b&&b(a),a}else{var h=this;!function(){var c=f;h.addNode(g,function(f){d[c]=f,0==--e&&b&&b(a)})}()}}return null},SceneJS.Node.prototype.addNode=function(a,b){if(a=a||{},a._compile){if(null!=a.parent)throw SceneJS_error.fatalError(SceneJS.errors.ILLEGAL_NODE_CONFIG,"Node#addNode - node argument is still attached to another parent");return this.nodes.push(a),a.parent=this,this._engine.branchDirty(a),b&&b(a),a}if("string"==typeof a){var c=this._engine.findNode(a);if(!c)throw SceneJS_error.fatalError(SceneJS.errors.ILLEGAL_NODE_CONFIG,"Node#addNode - node not found: '"+a+"'");if(a=c,null!=a.parent)throw SceneJS_error.fatalError(SceneJS.errors.ILLEGAL_NODE_CONFIG,"Node#addNode - node argument is still attached to another parent");return this.nodes.push(a),a.parent=this,this._engine.branchDirty(a),b&&b(a),a}if(a.type=a.type||"node","node"==a.type||this._engine.hasNodeType(a.type))return a=this._engine.createNode(a),this.nodes.push(a),a.parent=this,this._engine.branchDirty(a),b&&b(a),a;var d=this;return this._engine.createNode(a,function(a){d.nodes.push(a),a.parent=d,d._engine.branchDirty(a),b&&b(a)}),null},SceneJS.Node.prototype.insertNode=function(a,b){if(!a)throw SceneJS_error.fatalError(SceneJS.errors.ILLEGAL_NODE_CONFIG,"SceneJS.Node#insertNode - node argument is undefined");if(a._compile||(a=this._engine.createNode(a)),!a._compile)throw SceneJS_error.fatalError(SceneJS.errors.ILLEGAL_NODE_CONFIG,"SceneJS.Node#insertNode - node argument is not a SceneJS.Node");if(null!=a.parent)throw SceneJS_error.fatalError(SceneJS.errors.ILLEGAL_NODE_CONFIG,"SceneJS.Node#insertNode - node argument is still attached to another parent");if(void 0===b||null===b)a.addNodes(this.disconnectNodes()),this.addNode(a);else{if(0>b)throw SceneJS_error.fatalError(SceneJS.errors.ILLEGAL_NODE_CONFIG,"SceneJS.Node#insertNode - node index out of range: -1");b>=this.nodes.length?this.nodes.push(a):this.nodes.splice(b,0,a)}return a.parent=this,a},SceneJS.Node.prototype.mapNodes=function(a){if(a(this))return this;for(var b,c=0;cg;g++)e=d[g],e.options.scope?e.fn.call(e.options.scope,f):e.fn.call(this,f)}},SceneJS.Node.prototype.removeListener=function(a,b){var c=this._listeners[a];if(!c)return null;for(var d=0;d0},SceneJS.Node.prototype.removeListeners=function(){return this._listeners={},this._numListeners=0,this},SceneJS.Node.prototype.getParent=function(a){return this.parent},SceneJS.Node.prototype.getParentOfType=function(a){for(var b=this.parent;b&&b.type!=a;)b=b.parent;return b},SceneJS.Node.prototype.eachParent=function(a){if(!a)throw"SceneJS.Node.eachParent param 'fn' is null or undefined";for(var b=0,c=this;c.parent;){if(a.call(c.parent,b++)===!0)return c.parent;c=c.parent}return null},SceneJS.Node.prototype.hasNode=function(a){if(null===a||void 0===a)throw"SceneJS.Node.hasNode param 'node' is null or undefined";var b,c=typeof a;if("number"==c)b=this.getNodeAt(a);else{if("string"!=c)throw"SceneJS.Node.hasNode param 'node' should be either an index number or an ID string";b=this.getNode(a)}return void 0!=b&&null!=b},SceneJS.Node.prototype.node=function(a){if(null===a||void 0===a)throw"SceneJS.Node.node param 'node' is null or undefined";var b,c=typeof a;if("number"==c)b=this.getNodeAt(a);else{if("string"!=c)throw"SceneJS.Node.node param 'node' should be either an index number or an ID string";b=this.getNode(a)}if(!b)throw"SceneJS.Node.node - node not found: '"+a+"'";return b},SceneJS.Node.prototype.eachNode=function(a,b){if(!a)throw"SceneJS.Node.eachNode param 'fn' is null or undefined";if("function"!=typeof a)throw"SceneJS.Node.eachNode param 'fn' should be a function";var c;b=b||{};var d=0;return b.andSelf&&a.call(this,d++)===!0?this:(b.depthFirst||b.breadthFirst?b.depthFirst&&(c=this._iterateEachNodeDepthFirst(a,this,d,!1)):c=this._iterateEachNode(a,this,d),c?c:void 0)},SceneJS.Node.prototype.numNodes=function(){return this.nodes.length},SceneJS.Node.prototype._iterateEachNode=function(a,b,c){for(var d,e=b.nodes.length,f=0;e>f;f++)if(d=b.nodes[f],a.call(d,c++)===!0)return d;return null},SceneJS.Node.prototype._iterateEachNodeDepthFirst=function(a,b,c,d){if(d&&a.call(b,c++)===!0)return b;d=!0;for(var e,f=b.nodes.length,g=0;f>g;g++)if(e=this._iterateEachNodeDepthFirst(a,b.nodes[g],c,d))return e;return null},SceneJS.Node.prototype.findNodesByType=function(a,b){return this._findNodesByType(a,[],b)},SceneJS.Node.prototype._findNodesByType=function(a,b,c){var d;for(d=0;dd;d++)c=this.nodes[d],c.branchDirty=c.branchDirty||this.branchDirty,(c.dirty||c.branchDirty||this._engine.sceneDirty)&&(c._compile(a),c.dirty=!1,c.branchDirty=!1);b&&SceneJS_nodeEventsModule.postVisitNode(this)},SceneJS.Node.prototype.destroy=function(){if(!this.destroyed){if(this.parent)for(var a=0;aa;a++)this.nodes[a]._destroyTree()},SceneJS.Node.prototype._doDestroy=function(){return this._destroy&&this._destroy(),this},SceneJS_PubSubProxy=function(a,b){this.scene=a,this.proxy=b};var SceneJS_NodeFactory=function(){this.nodes=new SceneJS_Map({})};SceneJS_NodeFactory.nodeTypes={},SceneJS_NodeFactory._subs={},SceneJS_NodeFactory.createNodeType=function(a,b,c){if(SceneJS_NodeFactory.nodeTypes[a])throw"Node type already defined: "+a;var d=function(){SceneJS.Node.apply(this,arguments),this.type=a};d.prototype=new SceneJS.Node,d.prototype.constructor=d,SceneJS_NodeFactory.nodeTypes[a]=d;var e=SceneJS_NodeFactory.nodeTypes[a];if(!e)throw"Node type plugin did not install itself correctly";c&&c(d);var f=SceneJS_NodeFactory._subs[a];if(f){for(;f.length>0;)f.pop()(e);delete f[a]}return d},SceneJS_NodeFactory.prototype.getNode=function(a,b,c,d){b.type=b.type||"node";var e;if(e="node"==b.type?SceneJS.Node:SceneJS_NodeFactory.nodeTypes[b.type])return this._createNode(e,a,b,c,d);var f=this;this._getType(a,b.type,function(e){f._createNode(e,a,b,c,d)})},SceneJS_NodeFactory.prototype._createNode=function(a,b,c,d,e){var f=new a,g=c.id||c.nodeId;return g?this.nodes.addItem(g,f):g=this.nodes.addItem(f),f._construct(b,d,c,g),e&&e(f),f},SceneJS_NodeFactory.prototype._getType=function(a,b,c){var d=SceneJS_NodeFactory.nodeTypes[b];if(d)return void c(d);var e=SceneJS_NodeFactory._subs[b]||(SceneJS_NodeFactory._subs[b]=[]);if(e.push(c),!(e.length>1)){var f=SceneJS_sceneStatusModule.taskStarted(a.scene,"Loading plugin");e.push(function(){SceneJS_sceneStatusModule.taskFinished(f)});var g=SceneJS_configsModule.configs.pluginPath;if(!g)throw"no typePath config";this._loadScript(g+"/node/"+b+".js",function(){SceneJS_sceneStatusModule.taskFailed(f)})}},SceneJS_NodeFactory.prototype._loadScript=function(a,b){var c=document.createElement("script");c.type="text/javascript",c.src=a,c.onerror=b,document.getElementsByTagName("head")[0].appendChild(c)},SceneJS_NodeFactory.prototype.putNode=function(a){this.nodes.removeItem(a.id)},function(){function a(a){var b=a.optics; -if("ortho"==b.type?a.matrix=SceneJS_math_orthoMat4c(b.left,b.right,b.bottom,b.top,b.near,b.far):"frustum"==b.type?a.matrix=SceneJS_math_frustumMatrix4(b.left,b.right,b.bottom,b.top,b.near,b.far):"perspective"==b.type&&(a.matrix=SceneJS_math_perspectiveMatrix4(b.fovy*Math.PI/180,b.aspect,b.near,b.far)),a.pan){var c=a.pan,d=SceneJS_math_translationMat4v([c.x||0,c.y||0,c.z||0]);a.matrix=SceneJS_math_mulMat4(d,a.matrix,[])}a.mat?a.mat.set(a.matrix):a.mat=new Float32Array(a.matrix)}var b=SceneJS_math_perspectiveMatrix4(45,1,.1,1e4),c=new Float32Array(b),d={type:"camera",stateId:SceneJS._baseStateId++,matrix:b,mat:c,optics:{type:"perspective",fovy:45,aspect:1,near:.1,far:1e4},checkAspect:function(b,c){b.optics.aspect!=c&&(b.optics.aspect=c,a(this))}},e=[],f=0;SceneJS_events.addListener(SceneJS_events.SCENE_COMPILING,function(a){a.engine.display.projTransform=d,f=0}),SceneJS.Camera=SceneJS_NodeFactory.createNodeType("camera"),SceneJS.Camera.prototype._init=function(b){if(1==this._core.useCount){b.optics=b.optics||{};var c=this.getScene().getCanvas();b.optics.aspect=c.width/c.height,this.setOptics(b.optics),b.pan&&this.setPan(b.pan);var d=this;this._canvasSizeSub=this.getScene().on("canvasSize",function(b){d._core.optics.aspect=b.aspect,a(d._core),d._engine.display.imageDirty=!0})}},SceneJS.Camera.getDefaultMatrix=function(){return c},SceneJS.Camera.prototype.setOptics=function(b){var c=this._core;if(b){var d=b.type||c.optics.type||"perspective";if("ortho"==d)c.optics=SceneJS._applyIf(SceneJS_math_ORTHO_OBJ,{type:d,left:b.left,bottom:b.bottom,near:b.near,right:b.right,top:b.top,far:b.far});else if("frustum"==d)c.optics={type:d,left:b.left||-1,bottom:b.bottom||-1,near:b.near||.1,right:b.right||1,top:b.top||1,far:b.far||1e4};else{if("perspective"!=d)throw b.type?SceneJS_error.fatalError(SceneJS.errors.ILLEGAL_NODE_CONFIG,"SceneJS.Camera configuration invalid: optics type not supported - supported types are 'perspective', 'frustum' and 'ortho'"):SceneJS_error.fatalError(SceneJS.errors.ILLEGAL_NODE_CONFIG,"SceneJS.Camera configuration invalid: optics type not specified - supported types are 'perspective', 'frustum' and 'ortho'");c.optics={type:d,fovy:b.fovy||60,aspect:void 0==b.aspect?1:b.aspect,near:b.near||.1,far:b.far||1e4}}}else c.optics={type:"perspective",fovy:60,aspect:1,near:.1,far:1e4};this._core.optics.pan=b.pan,a(this._core),this.publish("matrix",this._core.matrix),this._engine.display.imageDirty=!0},SceneJS.Camera.prototype.setPan=function(b){this._core.pan=b,a(this._core),this.publish("matrix",this._core.matrix),this._engine.display.imageDirty=!0},SceneJS.Camera.prototype.getOptics=function(){var a={};for(var b in this._core.optics)this._core.optics.hasOwnProperty(b)&&(a[b]=this._core.optics[b]);return a},SceneJS.Camera.prototype.getMatrix=function(){return this._core.matrix.slice(0)},SceneJS.Camera.prototype._compile=function(a){this._engine.display.projTransform=e[f++]=this._core,this._compileNodes(a),this._engine.display.projTransform=--f>0?e[f-1]:d},SceneJS.Camera.prototype._destroy=function(){this.getScene().off(this._canvasSizeSub)}}(),function(){var a={type:"clips",stateId:SceneJS._baseStateId++,empty:!0,hash:"",clips:[]},b=[],c=0;SceneJS_events.addListener(SceneJS_events.SCENE_COMPILING,function(b){b.engine.display.clips=a,c=0}),SceneJS.Clips=SceneJS_NodeFactory.createNodeType("clips"),SceneJS.Clips.prototype._init=function(a){if(1==this._core.useCount){var b=a.clips;if(!b)throw SceneJS_error.fatalError(SceneJS.errors.NODE_CONFIG_EXPECTED,"clips node attribute missing : 'clips'");this._core.clips=this._core.clips||[];for(var c=0,d=b.length;d>c;c++)this._setClip(c,b[c])}},SceneJS.Clips.prototype.setClips=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.clips.length)throw SceneJS_error.fatalError(SceneJS.errors.ILLEGAL_NODE_CONFIG,"Invalid argument to set 'clips': index out of range ("+this._core.clips.length+" clips defined)");this._setClip(b,a[c]||{})}this._engine.display.imageDirty=!0},SceneJS.Clips.prototype._setClip=function(a,b){var c=this._core.clips[a]||(this._core.clips[a]={});c.normalAndDist=[b.x||0,b.y||0,b.z||0,b.dist||0];var d=b.mode||c.mode||"disabled";if("inside"!=d&&"outside"!=d&&"disabled"!=d)throw SceneJS_error.fatalError(SceneJS.errors.ILLEGAL_NODE_CONFIG,"clips node invalid value for property 'mode': should be 'inside' or 'outside' or 'disabled'");c.mode=d,this._core.hash=null},SceneJS.Clips.prototype._compile=function(d){this._core.hash||(this._core.hash=this._core.clips.length),this._engine.display.clips=b[c++]=this._core,this._compileNodes(d),this._engine.display.clips=--c>0?b[c-1]:a}}(),function(){var a={stateId:SceneJS._baseStateId++,type:"enable",enabled:!0},b=[],c=0;SceneJS_events.addListener(SceneJS_events.SCENE_COMPILING,function(b){b.engine.display.enable=a,c=0}),SceneJS.Enable=SceneJS_NodeFactory.createNodeType("enable"),SceneJS.Enable.prototype._init=function(a){1==this._core.useCount&&(this._core.enabled=!0,void 0!=a.enabled&&this.setEnabled(a.enabled))},SceneJS.Enable.prototype.setEnabled=function(a){return a!==this._core.enabled&&(this._core.enabled=a,this._engine.display.drawListDirty=!0,this.publish("enabled",a)),this},SceneJS.Enable.prototype.getEnabled=function(){return this._core.enabled},SceneJS.Enable.prototype._compile=function(d){this._engine.display.enable=b[c++]=this._core,this._compileNodes(d),this._engine.display.enable=--c>0?b[c-1]:a}}(),function(){var a={stateId:SceneJS._baseStateId++,type:"flags",picking:!0,clipping:!0,enabled:!0,transparent:!1,backfaces:!0,frontface:"ccw",reflective:!0,hash:"refl"},b=[],c=0;SceneJS_events.addListener(SceneJS_events.SCENE_COMPILING,function(b){b.engine.display.flags=a,c=0}),SceneJS.Flags=SceneJS_NodeFactory.createNodeType("flags"),SceneJS.Flags.prototype._init=function(a){1==this._core.useCount&&(this._core.picking=!0,this._core.clipping=!0,this._core.enabled=!0,this._core.transparent=!1,this._core.backfaces=!0,this._core.frontface="ccw",this._core.reflective=!0,a.flags&&this.setFlags(a.flags))},SceneJS.Flags.prototype.setFlags=function(a){var b=this._core;return void 0!=a.picking&&(b.picking=!!a.picking,this._engine.display.drawListDirty=!0),void 0!=a.clipping&&(b.clipping=!!a.clipping,this._engine.display.imageDirty=!0),void 0!=a.enabled&&(b.enabled=!!a.enabled,this._engine.display.drawListDirty=!0),void 0!=a.transparent&&(b.transparent=!!a.transparent,this._engine.display.stateSortDirty=!0),void 0!=a.backfaces&&(b.backfaces=!!a.backfaces,this._engine.display.imageDirty=!0),void 0!=a.frontface&&(b.frontface=a.frontface,this._engine.display.imageDirty=!0),void 0!=a.reflective&&(b.reflective=a.reflective,b.hash=b.reflective?"refl":"",this._engine.branchDirty(this),this._engine.display.imageDirty=!0),this},SceneJS.Flags.prototype.addFlags=function(a){return this.setFlags(a)},SceneJS.Flags.prototype.getFlags=function(){var a=this._core;return{picking:a.picking,clipping:a.clipping,enabled:a.enabled,transparent:a.transparent,backfaces:a.backfaces,frontface:a.frontface,reflective:a.reflective}},SceneJS.Flags.prototype.setPicking=function(a){return a=!!a,this._core.picking!=a&&(this._core.picking=a,this._engine.display.drawListDirty=!0),this},SceneJS.Flags.prototype.getPicking=function(){return this._core.picking},SceneJS.Flags.prototype.setClipping=function(a){return a=!!a,this._core.clipping!=a&&(this._core.clipping=a,this._engine.display.imageDirty=!0),this},SceneJS.Flags.prototype.getClipping=function(){return this._core.clipping},SceneJS.Flags.prototype.setEnabled=function(a){return a=!!a,this._core.enabled!=a&&(this._core.enabled=a,this._engine.display.drawListDirty=!0),this},SceneJS.Flags.prototype.getEnabled=function(){return this._core.enabled},SceneJS.Flags.prototype.setTransparent=function(a){return a=!!a,this._core.transparent!=a&&(this._core.transparent=a,this._engine.display.stateOrderDirty=!0),this},SceneJS.Flags.prototype.getTransparent=function(){return this._core.transparent},SceneJS.Flags.prototype.setBackfaces=function(a){return a=!!a,this._core.backfaces!=a&&(this._core.backfaces=a,this._engine.display.imageDirty=!0),this},SceneJS.Flags.prototype.getBackfaces=function(){return this._core.backfaces},SceneJS.Flags.prototype.setFrontface=function(a){return this._core.frontface!=a&&(this._core.frontface=a,this._engine.display.imageDirty=!0),this},SceneJS.Flags.prototype.getFrontface=function(){return this._core.frontface},SceneJS.Flags.prototype.setReflective=function(a){return a=!!a,this._core.reflective!=a&&(this._core.reflective=a,this._core.hash=a?"refl":"",this._engine.branchDirty(this),this._engine.display.imageDirty=!0),this},SceneJS.Flags.prototype.getReflective=function(){return this._core.reflective},SceneJS.Flags.prototype._compile=function(d){this._engine.display.flags=b[c++]=this._core,this._compileNodes(d),this._engine.display.flags=--c>0?b[c-1]:a}}(),new function(){var a={type:"renderTarget",stateId:SceneJS._baseStateId++,targets:null},b={},c=[],d=0;SceneJS_events.addListener(SceneJS_events.SCENE_COMPILING,function(b){b.engine.display.renderTarget=a,d=0}),SceneJS_events.addListener(SceneJS_events.WEBGL_CONTEXT_RESTORED,function(){for(var a in b)b.hasOwnProperty(a)&&b[a]._core.renderBuf.webglRestored()}),SceneJS.ColorTarget=SceneJS_NodeFactory.createNodeType("colorTarget"),SceneJS.ColorTarget.prototype._init=function(a){b[this._core.coreId]=this,this._core.bufType="color",this._core.renderBuf=new SceneJS._webgl.RenderBuffer({canvas:this._engine.canvas})},SceneJS.ColorTarget.prototype._compile=function(b){this.__core||(this.__core=this._engine._coreFactory.getCore("renderTarget"));var e=this._engine.display.renderTarget;this._core.empty||(this.__core.targets=e&&e.targets?e.targets.concat([this._core]):[this._core]),c[d++]=this.__core,this._engine.display.renderTarget=this.__core,this._compileNodes(b),this._engine.display.renderTarget=--d>0?c[d-1]:a},SceneJS.ColorTarget.prototype._destroy=function(){this._core&&(this._core.renderBuf&&this._core.renderBuf.destroy(),delete b[this._core.coreId])}},new function(){var a={type:"renderTarget",stateId:SceneJS._baseStateId++,targets:null},b={},c=[],d=0;SceneJS_events.addListener(SceneJS_events.SCENE_COMPILING,function(b){b.engine.display.renderTarget=a,d=0}),SceneJS_events.addListener(SceneJS_events.WEBGL_CONTEXT_RESTORED,function(){for(var a in b)b.hasOwnProperty(a)&&b[a]._buildNodeCore()}),SceneJS.DepthTarget=SceneJS_NodeFactory.createNodeType("depthTarget"),SceneJS.DepthTarget.prototype._init=function(a){b[this._core.coreId]=this,this._core.bufType="depth",this._core.renderBuf=new SceneJS._webgl.RenderBuffer({canvas:this._engine.canvas})},SceneJS.DepthTarget.prototype._compile=function(b){this.__core||(this.__core=this._engine._coreFactory.getCore("renderTarget"));var e=this._engine.display.renderTarget;this._core.empty||(this.__core.targets=e&&e.targets?e.targets.concat([this._core]):[this._core]),c[d++]=this.__core,this._engine.display.renderTarget=this.__core,this._compileNodes(b),this._engine.display.renderTarget=--d>0?c[d-1]:a},SceneJS.DepthTarget.prototype._destroy=function(){this._core&&(this._core.renderBuf&&this._core.renderBuf.destroy(),delete b[this._core.coreId])}},new function(){var a=[],b=0;SceneJS_events.addListener(SceneJS_events.SCENE_COMPILING,function(){b=0}),SceneJS.Geometry=SceneJS_NodeFactory.createNodeType("geometry"),SceneJS.Geometry.prototype._init=function(a){if(1==this._core.useCount){this._initNodeCore(a,{origin:a.origin,scale:a.scale,autoNormals:"auto"==a.normals}),this._buildNodeCore(this._engine.canvas.gl,this._core);var b=this;this._core.webglRestored=function(){b._buildNodeCore(b._engine.canvas.gl,b._core)}}},SceneJS.Geometry.prototype._initNodeCore=function(a,b){var c=this;b=b||{};var d=a.primitive||"triangles",e=this._core,f=this._engine.canvas.UINT_INDEX_ENABLED?Uint32Array:Uint16Array;e.primitive=this._getPrimitiveType(d),a.normals&&"triangles"==d&&("auto"===a.normals||a.normals===!0)&&a.positions&&a.indices&&this._buildNormals(a),e.arrays={positions:a.positions?new Float32Array(b.scale||b.origin?this._applyOptions(a.positions,b):a.positions):void 0,normals:a.normals?new Float32Array(a.normals):void 0,uv:a.uv?new Float32Array(a.uv):void 0,uv2:a.uv2?new Float32Array(a.uv2):void 0,colors:a.colors?new Float32Array(a.colors):void 0,indices:a.indices?new f(a.indices):void 0},delete a.positions,delete a.normals,delete a.uv,delete a.uv2,delete a.indices,delete a.colors,e.getTangentBuf=function(){if(e.tangentBuf)return e.tangentBuf;var a=e.arrays;if(a.positions&&a.indices&&a.uv){var b=c._engine.canvas.gl,d=new Float32Array(c._buildTangents(a));e.arrays.tangents=d;var f=b.STATIC_DRAW;return e.tangentBuf=new SceneJS._webgl.ArrayBuffer(b,b.ARRAY_BUFFER,d,d.length,3,f)}}},SceneJS.Geometry.prototype._getPrimitiveType=function(a){var b=this._engine.canvas.gl;switch(a){case"points":return b.POINTS;case"lines":return b.LINES;case"line-loop":return b.LINE_LOOP;case"line-strip":return b.LINE_STRIP;case"triangles":return b.TRIANGLES;case"triangle-strip":return b.TRIANGLE_STRIP;case"triangle-fan":return b.TRIANGLE_FAN;default:throw SceneJS_error.fatalError(SceneJS.errors.ILLEGAL_NODE_CONFIG,"geometry primitive unsupported: '"+a+"' - supported types are: 'points', 'lines', 'line-loop', 'line-strip', 'triangles', 'triangle-strip' and 'triangle-fan'")}},SceneJS.Geometry.prototype._applyOptions=function(a,b){var c=a.slice?a.slice(0):new Float32Array(a);if(b.scale)for(var d=void 0!=b.scale.x?b.scale.x:1,e=void 0!=b.scale.y?b.scale.y:1,f=void 0!=b.scale.z?b.scale.z:1,g=0,h=c.length;h>g;g+=3)c[g]*=d,c[g+1]*=e,c[g+2]*=f;if(b.origin)for(var i=void 0!=b.origin.x?b.origin.x:0,j=void 0!=b.origin.y?b.origin.y:0,k=void 0!=b.origin.z?b.origin.z:0,g=0,h=c.length;h>g;g+=3)c[g]-=i,c[g+1]-=j,c[g+2]-=k;return c};var c=function(a){a.vertexBuf&&(a.vertexBuf.destroy(),a.vertexBuf=null),a.normalBuf&&(a.normalBuf.destroy(),a.normalBuf=null),a.uvBuf&&(a.uvBuf.destroy(),a.uvBuf=null),a.uvBuf2&&(a.uvBuf2.destroy(),a.uvBuf2=null),a.colorBuf&&(a.colorBuf.destroy(),a.colorBuf=null),a.tangentBuf&&(a.tangentBuf.destroy(),a.tangentBuf=null),a.indexBuf&&(a.indexBuf.destroy(),a.indexBuf=null),a.interleavedBuf&&(a.interleavedBuf.destroy(),a.interleavedBuf=null)};SceneJS.Geometry.prototype._buildNodeCore=function(a,b){var d=a.STATIC_DRAW;try{var e=b.arrays,f=SceneJS.getConfigs("enableInterleaving")!==!1,g=0,h=0,i=[],j=[],k=function(a,b){return 0==g?g=a.length/b:a.length/b!=g&&(f=!1),i.push(a),j.push(b),h+=b,4*(h-b)};if(e.positions&&(f&&(b.interleavedPositionOffset=k(e.positions,3)),b.vertexBuf=new SceneJS._webgl.ArrayBuffer(a,a.ARRAY_BUFFER,e.positions,e.positions.length,3,d)),e.normals&&(f&&(b.interleavedNormalOffset=k(e.normals,3)),b.normalBuf=new SceneJS._webgl.ArrayBuffer(a,a.ARRAY_BUFFER,e.normals,e.normals.length,3,d)),e.uv&&(f&&(b.interleavedUVOffset=k(e.uv,2)),b.uvBuf=new SceneJS._webgl.ArrayBuffer(a,a.ARRAY_BUFFER,e.uv,e.uv.length,2,d)),e.uv2&&(f&&(b.interleavedUV2Offset=k(e.uv2,2)),b.uvBuf2=new SceneJS._webgl.ArrayBuffer(a,a.ARRAY_BUFFER,e.uv2,e.uv2.length,2,d)),e.colors&&(f&&(b.interleavedColorOffset=k(e.colors,4)),b.colorBuf=new SceneJS._webgl.ArrayBuffer(a,a.ARRAY_BUFFER,e.colors,e.colors.length,4,d)),e.indices&&(b.indexBuf=new SceneJS._webgl.ArrayBuffer(a,a.ELEMENT_ARRAY_BUFFER,e.indices,e.indices.length,1,d)),h>0&&f){for(var l=[],m=i.length,n=0;g>n;++n)for(var o=0;m>o;++o)for(var p=j[o],q=0;p>q;++q)l.push(i[o][n*p+q]);b.interleavedStride=4*h,b.interleavedBuf=new SceneJS._webgl.ArrayBuffer(a,a.ARRAY_BUFFER,new Float32Array(l),l.length,h,d),b.interleavedBuf.dirty=!1}}catch(r){throw c(b),SceneJS_error.fatalError(SceneJS.errors.ERROR,"Failed to allocate geometry: "+r)}},SceneJS.Geometry.prototype._updateArray=function(a,b,c){var d=a.length,e=b.length;e+c>d&&(e-=e+c-d);for(var f=c,g=0;e>g;f++,g++)a[f]=b[g]},SceneJS.Geometry.prototype._buildNormals=function(a){for(var b,c,d,e,f,g,h=a.positions,i=a.indices,j=new Array(h.length/3),k=0,l=i.length-3;l>k;k+=3){b=i[k+0],c=i[k+1],d=i[k+2],e=[h[3*b+0],h[3*b+1],h[3*b+2]],f=[h[3*c+0],h[3*c+1],h[3*c+2]],g=[h[3*d+0],h[3*d+1],h[3*d+2]],f=SceneJS_math_subVec4(f,e,[0,0,0,0]),g=SceneJS_math_subVec4(g,e,[0,0,0,0]);var m=SceneJS_math_normalizeVec4(SceneJS_math_cross3Vec4(f,g,[0,0,0,0]),[0,0,0,0]);j[b]||(j[b]=[]),j[c]||(j[c]=[]),j[d]||(j[d]=[]),j[b].push(m),j[c].push(m),j[d].push(m)}for(var n=new Array(h.length),k=0,l=j.length;l>k;k++){for(var o=j[k].length,p=0,q=0,r=0,s=0;o>s;s++)p+=j[k][s][0],q+=j[k][s][1],r+=j[k][s][2];n[3*k+0]=p/o,n[3*k+1]=q/o,n[3*k+2]=r/o}a.normals=n},SceneJS.Geometry.prototype._buildTangents=function(a){for(var b=a.positions,c=a.indices,d=a.uv,e=[],f=0;ft;t++){var u=c[f+t];"undefined"!=typeof e[u]?e[u]=SceneJS_math_addVec3(e[u],s,[]):e[u]=s}}for(var v=[],w=0;wf;f+=3)c=b[f],d=b[f+1],e=b[f+2],cthis._boundary.xmax&&(this._boundary.xmax=c),d>this._boundary.ymax&&(this._boundary.ymax=d),e>this._boundary.zmax&&(this._boundary.zmax=e);return this._boundary},SceneJS.Geometry.prototype._compile=function(c){if(this._core._loading)return void this._compileNodes(c);var d=this._core;d.vertexBuf||(d=this._inheritVBOs(d)),d.indexBuf?(d.hash=[d.normalBuf?"t":"f",d.arrays&&d.arrays.tangents?"t":"f",d.uvBuf?"t":"f",d.uvBuf2?"t":"f",d.colorBuf?"t":"f",d.primitive].join(""),d.stateId=this._core.stateId,d.type="geometry",this._engine.display.geometry=a[b++]=d,SceneJS_events.fireEvent(SceneJS_events.OBJECT_COMPILING,{display:this._engine.display}),this._engine.display.buildObject(this.id)):a[b++]=this._core,this._compileNodes(c),b--},SceneJS.Geometry.prototype._inheritVBOs=function(c){for(var d={primitive:c.primitive,boundary:c.boundary,normalBuf:c.normalBuf,uvBuf:c.uvBuf,uvBuf2:c.uvBuf2,colorBuf:c.colorBuf,interleavedBuf:c.interleavedBuf,indexBuf:c.indexBuf,interleavedStride:c.interleavedStride,interleavedPositionOffset:c.interleavedPositionOffset,interleavedNormalOffset:c.interleavedNormalOffset,interleavedUVOffset:c.interleavedUVOffset,interleavedUV2Offset:c.interleavedUV2Offset,interleavedColorOffset:c.interleavedColorOffset},e=b-1;e>=0;e--)if(a[e].vertexBuf)return d.vertexBuf=a[e].vertexBuf,d.boundary=a[e].boundary,d.normalBuf=a[e].normalBuf,d.uvBuf=a[e].uvBuf,d.uvBuf2=a[e].uvBuf2,d.colorBuf=a[e].colorBuf,d.interleavedBuf=a[e].interleavedBuf,d.interleavedStride=a[e].interleavedStride,d.interleavedPositionOffset=a[e].interleavedPositionOffset,d.interleavedNormalOffset=a[e].interleavedNormalOffset,d.interleavedUVOffset=a[e].interleavedUVOffset,d.interleavedUV2Offset=a[e].interleavedUV2Offset,d.interleavedColorOffset=a[e].interleavedColorOffset,d;return d},SceneJS.Geometry.prototype._destroy=function(){this._engine.display.removeObject(this.id),1==this._core.useCount&&(this._destroyNodeCore(),this._source&&this._source.destroy&&this._source.destroy())},SceneJS.Geometry.prototype._destroyNodeCore=function(){document.getElementById(this._engine.canvas.canvasId)&&c(this._core)}},function(){var a={type:"stage",stateId:SceneJS._baseStateId++,priority:0,pickable:!0,enabled:!0},b=[],c=0;SceneJS_events.addListener(SceneJS_events.SCENE_COMPILING,function(b){b.engine.display.stage=a,c=0}),SceneJS.Stage=SceneJS_NodeFactory.createNodeType("stage"),SceneJS.Stage.prototype._init=function(a){1==this._core.useCount&&(this._core.priority=a.priority||0,this._core.enabled=a.enabled!==!1,this._core.pickable=!!a.pickable)},SceneJS.Stage.prototype.setPriority=function(a){a=a||0,this._core.priority!=a&&(this._core.priority=a,this._engine.display.stateOrderDirty=!0)},SceneJS.Stage.prototype.getPriority=function(){return this._core.priority},SceneJS.Stage.prototype.setEnabled=function(a){a=!!a,this._core.enabled!=a&&(this._core.enabled=a,this._engine.display.drawListDirty=!0)},SceneJS.Stage.prototype.getEnabled=function(){return this._core.enabled},SceneJS.Stage.prototype.getEnabled=function(){return this._core.enabled},SceneJS.Stage.prototype._compile=function(d){this._engine.display.stage=b[c++]=this._core,this._compileNodes(d),this._engine.display.stage=--c>0?b[c-1]:a}}(),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}}(),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}}(),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},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],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.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.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}},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){if(this._sourceConfigs=a.source,this._source=null,a.source){if(!a.source.type)throw SceneJS_error.fatalError(SceneJS.errors.ILLEGAL_NODE_CONFIG,"morphGeometry config expected: source.type");var b=this;SceneJS.Plugins.getPlugin("morphGeometry",this._sourceConfigs.type,function(c){if(!c)throw SceneJS_error.fatalError(SceneJS.errors.PLUGIN_INVALID,"morphGeometry: no support for source type '"+b._sourceConfigs.type+"' - need to include plugin for self source type, or install a custom source service with SceneJS.Plugins.addPlugin(SceneJS.Plugins.MORPH_GEO_SOURCE_PLUGIN, '"+b._sourceConfigs.type+"', ).");if(!c.getSource)throw SceneJS_error.fatalError(SceneJS.errors.PLUGIN_INVALID,"morphGeometry: 'getSource' method not found on MorphGeoFactoryService (SceneJS.Plugins.MORPH_GEO_SOURCE_PLUGIN)");if(b._source=c.getSource(),!b._source.subscribe)throw SceneJS_error.fatalError(SceneJS.errors.PLUGIN_INVALID,"morphGeometry: 'subscribe' method not found on source provided by plugin type '"+a.source.type+"'");var d=!1;b._source.subscribe(function(a){if(d){if(a.targets)for(var c,e,f,g=a.targets,h=b._core.targets,i=0,j=g.length;j>i;i++)c=g[i],e=c.targetIndex,f=h[e],c.positions&&f.vertexBuf&&(f.vertexBuf.bind(),f.vertexBuf.setData(c.positions,0));b._display.imageDirty=!0}else b._buildNodeCore(a),b._core._loading=!1,b._fireEvent("loaded"),b._engine.branchDirty(b),d=!0}),b._core._loading=!0,b._fireEvent("loading"),b._source.configure(b._sourceConfigs)})}else a.create instanceof Function?this._buildNodeCore(a.create()):this._buildNodeCore(a);this._core.webglRestored=function(){},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="Float32Array"==typeof o?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="Float32Array"==typeof o?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="Float32Array"==typeof o?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="Float32Array"==typeof o?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)}},SceneJS.MorphGeometry.prototype.setSource=function(a){this._sourceConfigs=a;var b=this._source;b&&b.configure(a)},SceneJS.MorphGeometry.prototype.getSource=function(){return this._sourceConfigs},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},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){if(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.normalBuf&&a.normalBuf.destroy(),a.uvBuf&&a.uvBuf.destroy(),a.uvBuf2&&a.uvBuf2.destroy();this._source&&this._source.destroy&&this._source.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}}(),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}},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}}(),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,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}}(),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.setSSAAMultiplier=function(a){return this._engine.canvas.setSSAAMultiplier(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.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){return this._engine.readPixels(a,b)},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}}(),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}}(),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=SceneJS_sceneStatusModule.taskStarted(this,"Loading texture"),g=new Image;g.onload=function(){var d=a.createTexture();a.bindTexture(a.TEXTURE_2D,d);var e=SceneJS_configsModule.configs.maxTextureSize;e&&(g=SceneJS._webgl.clampImageSize(g,e)),a.texImage2D(a.TEXTURE_2D,0,a.RGBA,a.RGBA,a.UNSIGNED_BYTE,c._ensureImageSizePowerOfTwo(g)),c._setLayerTexture(a,b,d),SceneJS_sceneStatusModule.taskFinished(f),c._engine.display.imageDirty=!0},g.onerror=function(){SceneJS_sceneStatusModule.taskFailed(f)},0==e.indexOf("data")?g.src=e:(g.crossOrigin="Anonymous",g.src=e)}},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},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){if(b.applyFrom&&"uv"!=b.applyFrom&&"uv2"!=b.applyFrom&&"normal"!=b.applyFrom&&"geometry"!=b.applyFrom)throw SceneJS_error.fatalError(SceneJS.errors.NODE_CONFIG_EXPECTED,"texture applyFrom value is unsupported - should be either 'uv', 'uv2', 'normal' or 'geometry'");if(b.applyTo&&"baseColor"!=b.applyTo&&"color"!=b.applyTo&&"specular"!=b.applyTo&&"emit"!=b.applyTo&&"alpha"!=b.applyTo&&"normals"!=b.applyTo&&"shine"!=b.applyTo)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,applyFrom:b.applyFrom?b.applyFrom:"uv",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._core.src=b.src,this._loadTexture(b.src)):b.image?(this._core.image=b.image,this._initTexture(b.image)):b.target&&this.getScene().getNode(b.target,function(a){c.setTarget(a)}),this._core.webglRestored=function(){c._core.image?c._initTexture(c._core.image):c._core.src?c._loadTexture(c._core.src):c._core.target}}},SceneJS.TextureMap.prototype._loadTexture=function(a){var b=this,c=SceneJS_sceneStatusModule.taskStarted(this,"Loading texture"),d=new Image;d.onload=function(){b._initTexture(d),SceneJS_sceneStatusModule.taskFinished(c),b._engine.display.imageDirty=!0},d.onerror=function(){SceneJS_sceneStatusModule.taskFailed(c)},0==a.indexOf("data")?d.src=a:(d.crossOrigin="Anonymous",d.src=a)},SceneJS.TextureMap.prototype._initTexture=function(a){var b=this._engine.canvas.gl,c=b.createTexture();b.bindTexture(b.TEXTURE_2D,c);var d=SceneJS_configsModule.configs.maxTextureSize;d&&(a=SceneJS._webgl.clampImageSize(a,d)),b.texImage2D(b.TEXTURE_2D,0,b.RGBA,b.RGBA,b.UNSIGNED_BYTE,SceneJS._webgl.ensureImageSizePowerOfTwo(a)),this._core.image=a,this._core.texture=new SceneJS._webgl.Texture2D(b,{texture:c,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._initTexture(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},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)}},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},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)}}(),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,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.cubemap=null,this.modelTransform=null,this.viewTransform=null,this.projTransform=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._drawList=[],this._drawListLen=0,this._pickDrawList=[],this._pickDrawListLen=0,this._targetList=[],this._targetListLen=0,this._frameCtx={pickNames:[],canvas:this._canvas,VAO:null},this._frameCtx.renderListenerCtx=new SceneJS.RenderContext(this._frameCtx), -this.objectListDirty=!0,this.stateOrderDirty=!0,this.stateSortDirty=!0,this.drawListDirty=!0,this.imageDirty=!0,this.pickBufDirty=!0,this.rayPickBufDirty=!0};SceneJS_Display.prototype.webglRestored=function(){this._programFactory.webglRestored(),this._chunkFactory.webglRestored();var a=this._canvas.gl;this.pickBuf&&this.pickBuf.webglRestored(a),this.rayPickBuf&&this.rayPickBuf.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.stage=this.stage,b.layer=this.layer,b.renderTarget=this.renderTarget,b.texture=this.texture,b.cubemap=this.cubemap,b.geometry=this.geometry,b.enable=this.enable,b.flags=this.flags,b.tag=this.tag;var c=[this.geometry.hash,this.shader.hash,this.clips.hash,this.morphGeometry.hash,this.texture.hash,this.cubemap.hash,this.lights.hash,this.flags.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,"name",this.name),this._setChunk(b,12,"lights",this.lights),this._setChunk(b,13,"material",this.material),this._setChunk(b,14,"texture",this.texture),this._setChunk(b,15,"cubemap",this.cubemap),this._setChunk(b,16,"clips",this.clips),this._setChunk(b,17,"renderer",this.renderer),this._setChunk(b,18,"geometry",this.morphGeometry,this.geometry),this._setChunk(b,19,"listeners",this.renderListeners),this._setChunk(b,20,"draw",this.geometry)},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];b&&(this._programFactory.putProgram(b.program),b.program=null,b.hash=null,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)&&(this._doDrawList({clear:a.clear!==!1}),this.imageDirty=!1,this.pickBufDirty=!0)},SceneJS_Display.prototype._buildObjectList=function(){this._objectListLen=0;for(var a in this._objects)this._objects.hasOwnProperty(a)&&(this._objectList[this._objectListLen++]=this._objects[a])},SceneJS_Display.prototype._makeStateSortKeys=function(){for(var a,b=0,c=this._objectListLen;c>b;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||[];for(var a=0;23>a;a++)this._lastStateId[a]=null,this._lastPickStateId[a]=null;this._drawListLen=0,this._pickDrawListLen=0;var b,c,d,e,f,g={},h=[],i=[];this._tagSelector&&(c=this._tagSelector.mask,d=this._tagSelector.regex),this._objectDrawList=this._objectDrawList||[],this._objectDrawListLen=0;for(var a=0,j=this._objectListLen;j>a;a++)if(b=this._objectList[a],b.enable.enabled!==!1&&(f=b.flags,f.enabled!==!1&&b.layer.enabled&&(!c||(e=b.tag,!e.tag||(e.mask!=c&&(e.mask=c,e.matches=d.test(e.tag)),e.matches)))))if(b.renderTarget.targets)for(var k,l,m,n=b.renderTarget.targets,o=0,p=n.length;p>o;o++)k=n[o],l=k.coreId,m=g[l],m||(m=[],g[l]=m,h.push(m),i.push(this._chunkFactory.getChunk(k.stateId,"renderTarget",b.program,k))),m.push(b);else this._objectDrawList[this._objectDrawListLen++]=b;for(var m,k,b,q,a=0,j=h.length;j>a;a++){m=h[a],k=i[a],this._appendRenderTargetChunk(k);for(var o=0,p=m.length;p>o;o++)b=m[o],q=b.stage&&b.stage.pickable,this._appendObjectToDrawLists(b,q)}b&&this._appendRenderTargetChunk(this._chunkFactory.getChunk(-1,"renderTarget",b.program,{}));for(var a=0,j=this._objectDrawListLen;j>a;a++)b=this._objectDrawList[a],q=!b.stage||b.stage&&b.stage.pickable,this._appendObjectToDrawLists(b,q);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=a.flags.picking,f=0,g=d.length;g>f;f++)c=d[f],c&&(c.draw&&(c.unique||this._lastStateId[f]!=c.id)&&(this._drawList[this._drawListLen++]=c,this._lastStateId[f]=c.id),c.pick&&b!==!1&&e&&(c.unique||this._lastPickStateId[f]!=c.id)&&(this._pickDrawList[this._pickDrawListLen++]=c,this._lastPickStateId[f]=c.id))},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("--------------------------------------------------------------------------------------------------")},SceneJS_Display.prototype.pick=function(a){var b=this._canvas.canvas,c=this._canvas.ssaaMultiplier,d=null,e=a.canvasX*c,f=a.canvasY*c,g=this.pickBuf;g||(g=this.pickBuf=new SceneJS._webgl.RenderBuffer({canvas:this._canvas}),this.pickBufDirty=!0),this.render(),g.bind(),this.pickBufDirty&&(g.clear(),this._doDrawList({pick:!0,clear:!0}),this._canvas.gl.finish(),this.pickBufDirty=!1,this.rayPickBufDirty=!0);var h=g.read(e,f),i=h[0]+256*h[1]+65536*h[2],j=i>=1?i-1:-1;g.unbind();var k=this._frameCtx.pickNames[j];if(k&&(d={name:k.name,path:k.path,nodeId:k.nodeId,canvasPos:[e,f]},a.rayPick)){var l=this.rayPickBuf;l||(l=this.rayPickBuf=new SceneJS._webgl.RenderBuffer({canvas:this._canvas}),this.rayPickBufDirty=!0),l.bind(),this.rayPickBufDirty&&(l.clear(),this._doDrawList({pick:!0,rayPick:!0,clear:!0}),this.rayPickBufDirty=!1),h=l.read(e,f),l.unbind();var m=this._unpackDepth(h),n=b.width,o=b.height,p=(e-n/2)/(n/2),q=-(f-o/2)/(o/2),r=this._frameCtx.cameraMat,s=this._frameCtx.viewMat,t=SceneJS_math_mulMat4(r,s,[]),u=SceneJS_math_inverseMat4(t,[]),v=SceneJS_math_transformVector4(u,[p,q,-1,1]);v=SceneJS_math_mulVec4Scalar(v,1/v[3]);var w=SceneJS_math_transformVector4(u,[p,q,1,1]);w=SceneJS_math_mulVec4Scalar(w,1/w[3]);var x=SceneJS_math_subVec3(w,v,[]),y=SceneJS_math_addVec3(v,SceneJS_math_mulVec4Scalar(x,m,[]),[]);d.worldPos=y}return d},SceneJS_Display.prototype.readPixels=function(a,b){this._readPixelBuf||(this._readPixelBuf=new SceneJS._webgl.RenderBuffer({canvas:this._canvas})),this._readPixelBuf.bind(),this._readPixelBuf.clear(),this.render({force:!0});for(var c,d,e=0;b>e;e++)c=a[e]||(a[e]={}),d=this._readPixelBuf.read(c.x,c.y),c.r=d[0],c.g=d[1],c.b=d[2],c.a=d[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._doDrawList=function(a){var b=this._canvas.gl,c=this._frameCtx;c.renderTarget=null,c.targetIndex=0,c.renderBuf=null,c.viewMat=null,c.modelMat=null,c.cameraMat=null,c.renderer=null,c.depthbufEnabled=null,c.clearDepth=null,c.depthFunc=b.LESS,c.scissorTestEnabled=!1,c.blendEnabled=!1,c.backfaces=!0,c.frontface="ccw",c.pick=!!a.pick,c.rayPick=!!a.rayPick,c.pickIndex=0,c.textureUnit=0,c.lineWidth=1,c.transparent=!1,c.ambientColor=this._ambientColor,c.aspect=this._canvas.canvas.width/this._canvas.canvas.height,this._canvas.UINT_INDEX_ENABLED&&b.getExtension("OES_element_index_uint");var d=b.getExtension("OES_vertex_array_object");if(c.VAO=d?d:null,c.VAO=null,b.viewport(0,0,b.drawingBufferWidth,b.drawingBufferHeight),this.transparent?b.clearColor(0,0,0,0):b.clearColor(this._ambientColor[0],this._ambientColor[1],this._ambientColor[2],1),a.clear&&b.clear(b.COLOR_BUFFER_BIT|b.DEPTH_BUFFER_BIT|b.STENCIL_BUFFER_BIT),b.frontFace(b.CCW),b.disable(b.CULL_FACE),b.disable(b.BLEND),a.pick)for(var e=0,f=this._pickDrawListLen;f>e;e++)this._pickDrawList[e].pick(c);else for(var e=0,f=this._drawListLen;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.destroy=function(){this._programFactory.destroy()};var SceneJS_ProgramSourceFactory=new function(){function a(a){if(a.renderTarget&&a.renderTarget.targets)for(var b=a.renderTarget.targets,c=0,d=b.length;d>c;c++)if("depth"===b[c].bufType)return!0;return!1}this._sourceCache={},this.getSource=function(a,b){var c=this._sourceCache[a];return c?(c.useCount++,c):this._sourceCache[a]=new SceneJS_ProgramSource(a,this._composePickingVertexShader(b),this._composePickingFragmentShader(b),this._composeRenderingVertexShader(b),this._composeRenderingFragmentShader(b))},this.putSource=function(a){var b=this._sourceCache[a];b&&0==--b.useCount&&(this._sourceCache[b.hash]=null)},this._composePickingVertexShader=function(a){var b=!!a.morphGeometry.targets,c=["precision mediump float;","attribute vec3 SCENEJS_aVertex;","uniform mat4 SCENEJS_uMMatrix;","uniform mat4 SCENEJS_uVMatrix;","uniform mat4 SCENEJS_uVNMatrix;","uniform mat4 SCENEJS_uPMatrix;"];return c.push("varying vec4 SCENEJS_vWorldVertex;"),c.push("varying vec4 SCENEJS_vViewVertex;"),b&&(c.push("uniform float SCENEJS_uMorphFactor;"),a.morphGeometry.targets[0].vertexBuf&&c.push("attribute vec3 SCENEJS_aMorphVertex;")),c.push("void main(void) {"),c.push(" vec4 tmpVertex=vec4(SCENEJS_aVertex, 1.0); "),b&&a.morphGeometry.targets[0].vertexBuf&&c.push(" tmpVertex = vec4(mix(tmpVertex.xyz, SCENEJS_aMorphVertex, SCENEJS_uMorphFactor), 1.0); "),c.push(" SCENEJS_vWorldVertex = SCENEJS_uMMatrix * tmpVertex; "),c.push(" SCENEJS_vViewVertex = SCENEJS_uVMatrix * SCENEJS_vWorldVertex;"),c.push(" gl_Position = SCENEJS_uPMatrix * SCENEJS_vViewVertex;"),c.push("}"),c},this._composePickingFragmentShader=function(a){var b=a.clips.clips.length>0,c=["precision mediump float;"];if(c.push("varying vec4 SCENEJS_vWorldVertex;"),c.push("varying vec4 SCENEJS_vViewVertex;"),c.push("uniform bool SCENEJS_uRayPickMode;"),c.push("uniform vec3 SCENEJS_uPickColor;"),c.push("uniform float SCENEJS_uZNear;"),c.push("uniform float SCENEJS_uZFar;"),c.push("uniform bool SCENEJS_uClipping;"),b)for(var d=0;d 0.0) { discard; }"),c.push("}")}return c.push(" if (SCENEJS_uRayPickMode) {"),c.push(" float zNormalizedDepth = abs((SCENEJS_uZNear + SCENEJS_vViewVertex.z) / (SCENEJS_uZFar - SCENEJS_uZNear));"),c.push(" gl_FragColor = packDepth(zNormalizedDepth); "),c.push(" } else {"),c.push(" gl_FragColor = vec4(SCENEJS_uPickColor.rgb, 1.0); "),c.push(" }"),c.push("}"),c},this._isTexturing=function(a){if(a.texture.layers&&a.texture.layers.length>0){if(a.geometry.uvBuf||a.geometry.uvBuf2)return!0;if(a.morphGeometry.targets&&(a.morphGeometry.targets[0].uvBuf||a.morphGeometry.targets[0].uvBuf2))return!0}return!1},this._isCubeMapping=function(a){return a.flags.reflective&&a.cubemap.layers&&a.cubemap.layers.length>0&&a.geometry.normalBuf},this._hasNormals=function(a){return a.geometry.normalBuf?!0:a.morphGeometry.targets&&a.morphGeometry.targets[0].normalBuf?!0:!1},this._hasTangents=function(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},this._composeRenderingVertexShader=function(a){var b=a.shader.shaders||{};if(b.vertex&&b.vertex.code&&""!=b.vertex.code&&SceneJS._isEmpty(b.vertex.hooks))return[b.vertex.code];var c=b.vertex||{},d=c.hooks||{},e=b.fragment||{},f=e.hooks||{},g=this._isTexturing(a),h=this._hasNormals(a),i=this._hasTangents(a),j=a.clips.clips.length>0,k=!!a.morphGeometry.targets,l=["precision mediump float;"];if(l.push("uniform mat4 SCENEJS_uMMatrix;"),l.push("uniform mat4 SCENEJS_uVMatrix;"),l.push("uniform mat4 SCENEJS_uPMatrix;"),l.push("attribute vec3 SCENEJS_aVertex;"),l.push("uniform vec3 SCENEJS_uWorldEye;"),l.push("varying vec3 SCENEJS_vViewEyeVec;"),h){l.push("attribute vec3 SCENEJS_aNormal;"),l.push("uniform mat4 SCENEJS_uMNMatrix;"),l.push("uniform mat4 SCENEJS_uVNMatrix;"),l.push("varying vec3 SCENEJS_vViewNormal;"),i&&l.push("attribute vec4 SCENEJS_aTangent;");for(var m=0;m0,k=["\n"];if(k.push("precision mediump float;"),j&&k.push("varying vec4 SCENEJS_vWorldVertex;"),k.push("varying vec4 SCENEJS_vViewVertex;"),k.push("uniform float SCENEJS_uZNear;"),k.push("uniform float SCENEJS_uZFar;"),j)for(var l=0;ll;l++)m=b.texture.layers[l],k.push("uniform sampler2D SCENEJS_uSampler"+l+";"),m.matrix&&k.push("uniform mat4 SCENEJS_uLayer"+l+"Matrix;"),k.push("uniform float SCENEJS_uLayer"+l+"BlendFactor;")}if(h&&g)for(var m,l=0,n=b.cubemap.layers.length;n>l;l++)m=b.cubemap.layers[l],k.push("uniform samplerCube SCENEJS_uCubeMapSampler"+l+";"),k.push("uniform float SCENEJS_uCubeMapIntensity"+l+";");if(k.push("uniform bool SCENEJS_uClipping;"),k.push("uniform bool SCENEJS_uDepthMode;"),k.push("uniform bool SCENEJS_uTransparent;"),b.geometry.colorBuf&&k.push("varying vec4 SCENEJS_vColor;"),k.push("uniform vec3 SCENEJS_uAmbientColor;"),k.push("uniform vec3 SCENEJS_uMaterialColor;"),k.push("uniform float SCENEJS_uMaterialAlpha;"),k.push("uniform float SCENEJS_uMaterialEmit;"),k.push("uniform vec3 SCENEJS_uMaterialSpecularColor;"),k.push("uniform float SCENEJS_uMaterialSpecular;"),k.push("uniform float SCENEJS_uMaterialShine;"),k.push("varying vec3 SCENEJS_vViewEyeVec;"),h){k.push("varying vec3 SCENEJS_vViewNormal;");for(var o,l=0;l 0.0) { discard; }"),k.push("}")}k.push(" vec3 ambient= SCENEJS_uAmbientColor;"),f&&b.geometry.uvBuf&&e.texturePos&&k.push(e.texturePos+"(SCENEJS_vUVCoord);"),e.viewPos&&k.push(e.viewPos+"(SCENEJS_vViewVertex);"),h&&e.viewNormal&&k.push(e.viewNormal+"(SCENEJS_vViewNormal);"),b.geometry.colorBuf?k.push(" vec3 color = SCENEJS_vColor.rgb;"):k.push(" vec3 color = SCENEJS_uMaterialColor;"),k.push(" float alpha = SCENEJS_uMaterialAlpha;"),k.push(" float emit = SCENEJS_uMaterialEmit;"),k.push(" float specular = SCENEJS_uMaterialSpecular;"),k.push(" vec3 specularColor = SCENEJS_uMaterialSpecularColor;"),k.push(" float shine = SCENEJS_uMaterialShine;"),e.materialBaseColor&&k.push("color="+e.materialBaseColor+"(color);"),e.materialAlpha&&k.push("alpha="+e.materialAlpha+"(alpha);"),e.materialEmit&&k.push("emit="+e.materialEmit+"(emit);"),e.materialSpecular&&k.push("specular="+e.materialSpecular+"(specular);"),e.materialSpecularColor&&k.push("specularColor="+e.materialSpecularColor+"(specularColor);"),e.materialShine&&k.push("shine="+e.materialShine+"(shine);"),h&&(k.push(" float attenuation = 1.0;"),i?k.push(" vec3 viewNormalVec = vec3(0.0, 1.0, 0.0);"):k.push(" vec3 viewNormalVec = normalize(SCENEJS_vViewNormal);"));var m;if(f){k.push(" vec4 texturePos;"),k.push(" vec2 textureCoord=vec2(0.0,0.0);");for(var l=0,n=b.texture.layers.length;n>l;l++){if(m=b.texture.layers[l],"normal"==m.applyFrom&&h){if(!b.geometry.normalBuf){SceneJS.log.warn("Texture layer applyFrom='normal' but geo has no normal vectors");continue}k.push("texturePos=vec4(viewNormalVec.xyz, 1.0);")}if("uv"==m.applyFrom){if(!b.geometry.uvBuf){SceneJS.log.warn("Texture layer applyTo='uv' but geometry has no UV coordinates");continue}k.push("texturePos = vec4(SCENEJS_vUVCoord.s, SCENEJS_vUVCoord.t, 1.0, 1.0);")}if("uv2"==m.applyFrom){if(!b.geometry.uvBuf2){SceneJS.log.warn("Texture layer applyTo='uv2' but geometry has no UV2 coordinates");continue}k.push("texturePos = vec4(SCENEJS_vUVCoord2.s, SCENEJS_vUVCoord2.t, 1.0, 1.0);")}m.matrix?k.push("textureCoord=(SCENEJS_uLayer"+l+"Matrix * texturePos).xy;"):k.push("textureCoord=texturePos.xy;"),"alpha"==m.applyTo&&("multiply"==m.blendMode?k.push("alpha = alpha * (SCENEJS_uLayer"+l+"BlendFactor * texture2D(SCENEJS_uSampler"+l+", vec2(textureCoord.x, 1.0 - textureCoord.y)).b);"):"add"==m.blendMode&&k.push("alpha = ((1.0 - SCENEJS_uLayer"+l+"BlendFactor) * alpha) + (SCENEJS_uLayer"+l+"BlendFactor * texture2D(SCENEJS_uSampler"+l+", vec2(textureCoord.x, 1.0 - textureCoord.y)).b);")),"baseColor"==m.applyTo&&("multiply"==m.blendMode?k.push("color = color * (SCENEJS_uLayer"+l+"BlendFactor * texture2D(SCENEJS_uSampler"+l+", vec2(textureCoord.x, 1.0 - textureCoord.y)).rgb);"):k.push("color = ((1.0 - SCENEJS_uLayer"+l+"BlendFactor) * color) + (SCENEJS_uLayer"+l+"BlendFactor * texture2D(SCENEJS_uSampler"+l+", vec2(textureCoord.x, 1.0 - textureCoord.y)).rgb);")),"emit"==m.applyTo&&("multiply"==m.blendMode?k.push("emit = emit * (SCENEJS_uLayer"+l+"BlendFactor * texture2D(SCENEJS_uSampler"+l+", vec2(textureCoord.x, 1.0 - textureCoord.y)).r);"):k.push("emit = ((1.0 - SCENEJS_uLayer"+l+"BlendFactor) * emit) + (SCENEJS_uLayer"+l+"BlendFactor * texture2D(SCENEJS_uSampler"+l+", vec2(textureCoord.x, 1.0 - textureCoord.y)).r);")),"specular"==m.applyTo&&h&&("multiply"==m.blendMode?k.push("specular = specular * (SCENEJS_uLayer"+l+"BlendFactor * texture2D(SCENEJS_uSampler"+l+", vec2(textureCoord.x, 1.0 - textureCoord.y)).r);"):k.push("specular = ((1.0 - SCENEJS_uLayer"+l+"BlendFactor) * specular) + (SCENEJS_uLayer"+l+"BlendFactor * texture2D(SCENEJS_uSampler"+l+", vec2(textureCoord.x, 1.0 - textureCoord.y)).r);")),"shine"==m.applyTo&&("multiply"==m.blendMode?k.push("shine = shine * (SCENEJS_uLayer"+l+"BlendFactor * texture2D(SCENEJS_uSampler"+l+", vec2(textureCoord.x, 1.0 - textureCoord.y)).r);"):k.push("shine = ((1.0 - SCENEJS_uLayer"+l+"BlendFactor) * shine) + (SCENEJS_uLayer"+l+"BlendFactor * texture2D(SCENEJS_uSampler"+l+", vec2(textureCoord.x, 1.0 - textureCoord.y)).r);")),"normals"==m.applyTo&&h&&k.push("viewNormalVec = normalize(texture2D(SCENEJS_uSampler"+l+", vec2(textureCoord.x, -textureCoord.y)).xyz * 2.0 - 1.0);")}}if(h&&g){k.push("vec3 envLookup = reflect(SCENEJS_vViewEyeVec, viewNormalVec);"),k.push("envLookup.y = envLookup.y * -1.0;"),k.push("vec4 envColor;");for(var l=0,n=b.cubemap.layers.length;n>l;l++)m=b.cubemap.layers[l],k.push("envColor = textureCube(SCENEJS_uCubeMapSampler"+l+", envLookup);"),k.push("color = mix(color, envColor.rgb, specular * SCENEJS_uCubeMapIntensity"+l+");")}if(k.push(" vec4 fragColor;"),h){k.push(" vec3 lightValue = vec3(0.0, 0.0, 0.0);"),k.push(" vec3 specularValue = vec3(0.0, 0.0, 0.0);"),k.push(" vec3 viewLightVec;"),k.push(" float dotN;"),k.push(" float lightDist;");for(var o,l=0,n=b.lights.lights.length;n>l;l++)o=b.lights.lights[l],"ambient"!=o.mode&&(k.push("viewLightVec = SCENEJS_vViewLightVecAndDist"+l+".xyz;"),"point"==o.mode&&(k.push("dotN = max(dot(normalize(viewNormalVec), normalize(viewLightVec)), 0.0);"),k.push("lightDist = SCENEJS_vViewLightVecAndDist"+l+".w;"),k.push("attenuation = 1.0 - ( SCENEJS_uLightAttenuation"+l+"[0] + SCENEJS_uLightAttenuation"+l+"[1] * lightDist + SCENEJS_uLightAttenuation"+l+"[2] * lightDist * lightDist);"),o.diffuse&&k.push(" lightValue += dotN * SCENEJS_uLightColor"+l+" * attenuation;"),o.specular&&k.push(" specularValue += specularColor * SCENEJS_uLightColor"+l+" * specular * pow(max(dot(reflect(normalize(-viewLightVec), normalize(-viewNormalVec)), normalize(-SCENEJS_vViewVertex.xyz)), 0.0), shine) * attenuation;")),"dir"==o.mode&&(k.push("dotN = max(dot(normalize(viewNormalVec), normalize(viewLightVec)), 0.0);"),o.diffuse&&k.push(" lightValue += dotN * SCENEJS_uLightColor"+l+";"),o.specular&&k.push("specularValue += specularColor * SCENEJS_uLightColor"+l+" * specular * pow(max(dot(reflect(normalize(-viewLightVec), normalize(-viewNormalVec)), normalize(-SCENEJS_vViewVertex.xyz)), 0.0), shine);")));k.push(" fragColor = vec4((specularValue.rgb + color.rgb * (lightValue.rgb + ambient.rgb)) + (emit * color.rgb), alpha);")}else k.push("fragColor = vec4((color.rgb + (emit * color.rgb)) * (vec3(1.0, 1.0, 1.0) + ambient.rgb), alpha);");return e.pixelColor&&k.push("fragColor="+e.pixelColor+"(fragColor);"),a(b)?(k.push(" if (SCENEJS_uDepthMode) {"),k.push(" float depth = length(SCENEJS_vViewVertex) / (SCENEJS_uZFar - SCENEJS_uZNear);"),k.push(" const vec4 bias = vec4(1.0 / 255.0,"),k.push(" 1.0 / 255.0,"),k.push(" 1.0 / 255.0,"),k.push(" 0.0);"),k.push(" float r = depth;"),k.push(" float g = fract(r * 255.0);"),k.push(" float b = fract(g * 255.0);"),k.push(" float a = fract(b * 255.0);"),k.push(" vec4 colour = vec4(r, g, b, a);"),k.push(" gl_FragColor = colour - (colour.yzww * bias);"),k.push(" } else {"),k.push(" gl_FragColor = fragColor;"),k.push(" };")):k.push(" gl_FragColor = fragColor;"),k.push("}"),k}},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.UINT_INDEX_ENABLED=!!d.getExtension("OES_element_index_uint"),this.draw=null,this.pick=null,this.useCount=0,this.build(d)};SceneJS_Program.prototype.build=function(a){this.drawUniformFlags=0,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){this._freeObjects[this._numFreeObjects++]=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.ssaaMultiplier,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];if(g)return g.useCount++,g;var h=SceneJS_ChunkFactory._freeChunks[b];return h.chunksLen>0&&(g=h.chunks[--h.chunksLen]),g?g.init(a,c,d,e):g=new f(a,c,d,e),g.type=b,g.useCount=1,this._chunks[a]=g,g},SceneJS_ChunkFactory.prototype.putChunk=function(a){if(0!=a.useCount&&--a.useCount<=0){a.recycle&&a.recycle(),delete this._chunks[a.id];var b=SceneJS_ChunkFactory._freeChunks[a.type];b.chunks[b.chunksLen++]=a}},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.getUniformLocation("SCENEJS_uPMatrix"),this._uZNearDraw=this.program.draw.getUniformLocation("SCENEJS_uZNear"),this._uZFarDraw=this.program.draw.getUniformLocation("SCENEJS_uZFar"),this._uPMatrixPick=this.program.pick.getUniformLocation("SCENEJS_uPMatrix"),this._uZNearPick=this.program.pick.getUniformLocation("SCENEJS_uZNear"),this._uZFarPick=this.program.pick.getUniformLocation("SCENEJS_uZFar")},draw:function(a){this.core.checkAspect&&this.core.checkAspect(this.core,a.aspect);var b=this.program.gl;this._uPMatrixDraw&&b.uniformMatrix4fv(this._uPMatrixDraw,b.FALSE,this.core.mat),this._uZNearDraw&&b.uniform1f(this._uZNearDraw,this.core.optics.near),this._uZFarDraw&&b.uniform1f(this._uZFarDraw,this.core.optics.far),a.cameraMat=this.core.mat},pick:function(a){this.core.checkAspect&&this.core.checkAspect(this.core,a.aspect);var b=this.program.gl;this._uPMatrixPick&&b.uniformMatrix4fv(this._uPMatrixPick,b.FALSE,this.core.mat),a.rayPick&&(this._uZNearPick&&b.uniform1f(this._uZNearPick,this.core.optics.near),this._uZFarPick&&b.uniform1f(this._uZFarPick,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.getUniformLocation("SCENEJS_uClipMode"+b),uClipNormalAndDist:a.getUniformLocation("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.getUniformLocation("SCENEJS_uClipMode"+b),uClipNormalAndDist:d.getUniformLocation("SCENEJS_uClipNormalAndDist"+b)}},drawAndPick:function(a){for(var b,c,d,e=a.pick?this._pick:this._draw,f=this.core.clips,g=this.program.gl,h=0,i=f.length;i>h;h++)a.pick?(b=e[h].uClipMode,c=e[h].uClipNormalAndDist):(b=e[h].uClipMode,c=e[h].uClipNormalAndDist),b&&c&&(d=f[h],"inside"==d.mode?(g.uniform1f(b,2),g.uniform4fv(c,d.normalAndDist)):"outside"==d.mode?(g.uniform1f(b,1),g.uniform4fv(c,d.normalAndDist)):g.uniform1f(b,0))}}),SceneJS_ChunkFactory.createChunkType({type:"draw",unique:!0,build:function(){this._depthModeDraw=this.program.draw.getUniformLocation("SCENEJS_uDepthMode"),this._depthModePick=this.program.pick.getUniformLocation("SCENEJS_uDepthMode")},drawAndPick:function(a){var b=this.program.gl,c=this.program.UINT_INDEX_ENABLED?b.UNSIGNED_INT:b.UNSIGNED_SHORT;b.uniform1i(a.pick?this._depthModePick:this._depthModeDraw,a.depthMode),b.drawElements(this.core.primitive,this.core.indexBuf.numItems,c,0)}}),SceneJS_ChunkFactory.createChunkType({type:"flags",build:function(){var a=this.program.draw;this._uClippingDraw=a.getUniformLocation("SCENEJS_uClipping");var b=this.program.pick;this._uClippingPick=b.getUniformLocation("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=this.core.transparent;if(a.transparent!=e&&(a.pick||(e?(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=e),a.pick)b.uniform1i(this._uClippingPick,this.core.clipping);else{var f=this.core.clipping?1:0;this.program.drawUniformFlags!=f&&(b.uniform1i(this._uClippingDraw,this.core.clipping),this.program.drawUniformFlags=f)}}}),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._aVertexDraw=a.getAttribute("SCENEJS_aVertex"),this._aNormalDraw=a.getAttribute("SCENEJS_aNormal"),this._aUVDraw=a.getAttribute("SCENEJS_aUVCoord"),this._aUV2Draw=a.getAttribute("SCENEJS_aUVCoord2"),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._uMorphFactorDraw=a.getUniformLocation("SCENEJS_uMorphFactor");var b=this.program.pick;this._aVertexPick=b.getAttribute("SCENEJS_aVertex"),this._aMorphVertexPick=b.getAttribute("SCENEJS_aMorphVertex"),this._uMorphFactorPick=b.getUniformLocation("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(){this.VAOMorphKey1=this.core.key1,this.VAOMorphKey2=this.core.key2;var a=this.core.targets[this.core.key1],b=this.core.targets[this.core.key2];this._aMorphVertexDraw?(this._aVertexDraw.bindFloatArrayBuffer(a.vertexBuf),this._aMorphVertexDraw.bindFloatArrayBuffer(b.vertexBuf)):this._aVertexDraw&&this._aVertexDraw.bindFloatArrayBuffer(this.core2.vertexBuf),this._aMorphNormalDraw?(this._aNormalDraw.bindFloatArrayBuffer(a.normalBuf),this._aMorphNormalDraw.bindFloatArrayBuffer(b.normalBuf)):this._aNormalDraw&&this._aNormalDraw.bindFloatArrayBuffer(this.core2.normalBuf),this._aUVDraw&&this._aUVDraw.bindFloatArrayBuffer(this.core2.uvBuf),this._aUV2Draw&&this._aUV2Draw.bindFloatArrayBuffer(this.core2.uvBuf2),this._aColorDraw&&this._aColorDraw.bindFloatArrayBuffer(this.core2.colorBuf),this.setDrawMorphFactor()},setDrawMorphFactor:function(){this._uMorphFactorDraw&&this.program.gl.uniform1f(this._uMorphFactorDraw,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){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 if(a.VAO){a.VAO.bindVertexArrayOES(null),this.VAO=a.VAO.createVertexArrayOES(),a.VAO.bindVertexArrayOES(this.VAO);this.program.gl}b?this.morphDraw():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),this._aUVDraw&&this._aUVDraw.bindInterleavedFloatArrayBuffer(2,this.core2.interleavedStride,this.core2.interleavedUVOffset),this._aUV2Draw&&this._aUV2Draw.bindInterleavedFloatArrayBuffer(2,this.core2.interleavedStride,this.core2.interleavedUV2Offset),this._aColorDraw&&this._aColorDraw.bindInterleavedFloatArrayBuffer(4,this.core2.interleavedStride,this.core2.interleavedColorOffset),this._aTangentDraw&&this._aTangentDraw.bindFloatArrayBuffer(this.core2.tangentBuf||this.core2.getTangentBuf())):(this.VAOHasInterleavedBuf=!1,this._aVertexDraw&&this._aVertexDraw.bindFloatArrayBuffer(this.core2.vertexBuf),this._aNormalDraw&&this._aNormalDraw.bindFloatArrayBuffer(this.core2.normalBuf),this._aUVDraw&&this._aUVDraw.bindFloatArrayBuffer(this.core2.uvBuf),this._aUV2Draw&&this._aUV2Draw.bindFloatArrayBuffer(this.core2.uvBuf2),this._aColorDraw&&this._aColorDraw.bindFloatArrayBuffer(this.core2.colorBuf),this._aTangentDraw&&this._aTangentDraw.bindFloatArrayBuffer(this.core2.tangentBuf||this.core2.getTangentBuf())),this.core2.indexBuf.bind()},morphPick:function(){var a=this.core.targets[this.core.key1],b=this.core.targets[this.core.key2];this._aMorphVertexPick?(this._aVertexPick.bindFloatArrayBuffer(a.vertexBuf),this._aMorphVertexPick.bindFloatArrayBuffer(b.vertexBuf)):this._aVertexPick&&this._aVertexPick.bindFloatArrayBuffer(this.core2.vertexBuf),this._uMorphFactorPick&&this.program.gl.uniform1f(this._uMorphFactorPick,this.core.factor)},pick:function(a){this.core.targets&&this.core.targets.length?this.morphPick():this._aVertexPick&&this._aVertexPick.bindFloatArrayBuffer(this.core2.vertexBuf),this.core2.indexBuf.bind()}}),SceneJS_ChunkFactory.createChunkType({type:"lights",build:function(){this._uAmbientColor=this._uAmbientColor||[],this._uLightColor=this._uLightColor||[],this._uLightDir=this._uLightDir||[],this._uLightPos=this._uLightPos||[],this._uLightCutOff=this._uLightCutOff||[],this._uLightSpotExp=this._uLightSpotExp||[],this._uLightAttenuation=this._uLightAttenuation||[];for(var a=this.core.lights,b=this.program,c=0,d=a.length;d>c;c++)switch(a[c].mode){case"ambient":this._uAmbientColor[c]=b.draw.getUniformLocation("SCENEJS_uAmbientColor");break;case"dir":this._uLightColor[c]=b.draw.getUniformLocation("SCENEJS_uLightColor"+c),this._uLightPos[c]=null,this._uLightDir[c]=b.draw.getUniformLocation("SCENEJS_uLightDir"+c);break;case"point":this._uLightColor[c]=b.draw.getUniformLocation("SCENEJS_uLightColor"+c),this._uLightPos[c]=b.draw.getUniformLocation("SCENEJS_uLightPos"+c),this._uLightDir[c]=null,this._uLightAttenuation[c]=b.draw.getUniformLocation("SCENEJS_uLightAttenuation"+c)}},draw:function(a){a.dirty&&this.build();for(var b,c=this.core.lights,d=this.program.gl,e=0,f=c.length;f>e;e++)b=c[e],this._uAmbientColor[e]?d.uniform3fv(this._uAmbientColor[e],b.color):(this._uLightColor[e]&&d.uniform3fv(this._uLightColor[e],b.color),this._uLightPos[e]&&(d.uniform3fv(this._uLightPos[e],b.pos),this._uLightAttenuation[e]&&d.uniform3fv(this._uLightAttenuation[e],b.attenuation)),this._uLightDir[e]&&d.uniform3fv(this._uLightDir[e],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.getUniformLocation("SCENEJS_uVMatrix"),this._uVNMatrixDraw=this.program.draw.getUniformLocation("SCENEJS_uVNMatrix"),this._uWorldEyeDraw=this.program.draw.getUniformLocation("SCENEJS_uWorldEye"),this._uvMatrixPick=this.program.pick.getUniformLocation("SCENEJS_uVMatrix")},draw:function(a){this.core.dirty&&this.core.rebuild();var b=this.program.gl;this._uvMatrixDraw&&b.uniformMatrix4fv(this._uvMatrixDraw,b.FALSE,this.core.mat),this._uVNMatrixDraw&&b.uniformMatrix4fv(this._uVNMatrixDraw,b.FALSE,this.core.normalMat),this._uWorldEyeDraw&&b.uniform3fv(this._uWorldEyeDraw,this.core.lookAt.eye),a.viewMat=this.core.mat},pick:function(a){var b=this.program.gl;this._uvMatrixPick&&b.uniformMatrix4fv(this._uvMatrixPick,b.FALSE,this.core.mat),a.viewMat=this.core.mat}}),SceneJS_ChunkFactory.createChunkType({type:"material",build:function(){var a=this.program.draw;this._uMaterialBaseColor=a.getUniformLocation("SCENEJS_uMaterialColor"),this._uMaterialSpecularColor=a.getUniformLocation("SCENEJS_uMaterialSpecularColor"),this._uMaterialSpecular=a.getUniformLocation("SCENEJS_uMaterialSpecular"),this._uMaterialShine=a.getUniformLocation("SCENEJS_uMaterialShine"),this._uMaterialEmit=a.getUniformLocation("SCENEJS_uMaterialEmit"),this._uMaterialAlpha=a.getUniformLocation("SCENEJS_uMaterialAlpha")},draw:function(){var a=this.program.gl,b=this.program.draw.materialSettings;this._uMaterialBaseColor&&a.uniform3fv(this._uMaterialBaseColor,this.core.baseColor),!this._uMaterialSpecularColor||b.specularColor[0]==this.core.specularColor[0]&&b.specularColor[1]==this.core.specularColor[1]&&b.specularColor[2]==this.core.specularColor[2]||(a.uniform3fv(this._uMaterialSpecularColor,this.core.specularColor),b.specularColor[0]=this.core.specularColor[0],b.specularColor[1]=this.core.specularColor[1],b.specularColor[2]=this.core.specularColor[2]),this._uMaterialSpecular&&b.specular!=this.core.specular&&(a.uniform1f(this._uMaterialSpecular,this.core.specular),b.specular=this.core.specular),this._uMaterialShine&&b.shine!=this.core.shine&&(a.uniform1f(this._uMaterialShine,this.core.shine),b.shine=this.core.shine),this._uMaterialEmit&&b.emit!=this.core.emit&&(a.uniform1f(this._uMaterialEmit,this.core.emit),b.emit=this.core.emit),this._uMaterialAlpha&&b.alpha!=this.core.alpha&&(a.uniform1f(this._uMaterialAlpha,this.core.alpha),b.alpha=this.core.alpha)}}),SceneJS_ChunkFactory.createChunkType({type:"name",build:function(){this._uPickColor=this.program.pick.getUniformLocation("SCENEJS_uPickColor")},pick:function(a){if(this._uPickColor&&this.core.name){a.pickNames[a.pickIndex++]=this.core;var b=a.pickIndex>>16&255,c=a.pickIndex>>8&255,d=255&a.pickIndex;this.program.gl.uniform3fv(this._uPickColor,[d/255,c/255,b/255])}}}),SceneJS_ChunkFactory.createChunkType({type:"program",build:function(){this._depthModeDraw=this.program.draw.getUniformLocation("SCENEJS_uDepthMode"),this._depthModePick=this.program.pick.getUniformLocation("SCENEJS_uDepthMode"),this._rayPickMode=this.program.pick.getUniformLocation("SCENEJS_uRayPickMode")},draw:function(a){var b=this.program.draw;b.bind(),a.textureUnit=0;var c=this.program.gl;if(c.uniform1i(this._depthModeDraw,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;c.uniform1i(this._rayPickMode,a.rayPick),c.uniform1i(this._depthModePick,a.depthMode),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:"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.pick?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.pick?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;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++),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));a.textureUnit>10&&(a.textureUnit=0)}}),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++),this._uCubeMapIntensity[e]&&this._uCubeMapIntensity[e].setValue(c.intensity));a.textureUnit>10&&(a.textureUnit=0)}}),SceneJS_ChunkFactory.createChunkType({type:"xform",build:function(){var a=this.program.draw;this._uMatLocationDraw=a.getUniformLocation("SCENEJS_uMMatrix"),this._uNormalMatLocationDraw=a.getUniformLocation("SCENEJS_uMNMatrix");var b=this.program.pick;this._uMatLocationPick=b.getUniformLocation("SCENEJS_uMMatrix")},draw:function(a){(SceneJS_configsModule.configs.forceXFormCoreRebuild===!0||this.core.dirty&&this.core.build)&&this.core.build();var b=this.program.gl;this._uMatLocationDraw&&b.uniformMatrix4fv(this._uMatLocationDraw,b.FALSE,this.core.mat),this._uNormalMatLocationDraw&&b.uniformMatrix4fv(this._uNormalMatLocationDraw,b.FALSE,this.core.normalMat),a.modelMat=this.core.mat},pick:function(a){this.core.dirty&&this.core.build();var b=this.program.gl;this._uMatLocationPick&&b.uniformMatrix4fv(this._uMatLocationPick,b.FALSE,this.core.mat),a.modelMat=this.core.mat}}); \ No newline at end of file +this.numItems=d,this.itemSize=e,this.usage=f,this._allocate(c,d)},SceneJS._webgl.ArrayBuffer.prototype._allocate=function(a,b){if(this.allocated=!1,this.handle=this.gl.createBuffer(),!this.handle)throw SceneJS_error.fatalError(SceneJS.errors.OUT_OF_VRAM,"Failed to allocate WebGL ArrayBuffer");this.handle&&(this.gl.bindBuffer(this.type,this.handle),this.gl.bufferData(this.type,a,this.usage),this.gl.bindBuffer(this.type,null),this.numItems=b,this.length=a.length,this.allocated=!0)},SceneJS._webgl.ArrayBuffer.prototype.setData=function(a,b){this.allocated&&(a.length>this.length?(this.destroy(),this._allocate(a,a.length)):b||0===b?this.gl.bufferSubData(this.type,b,a):this.gl.bufferData(this.type,a))},SceneJS._webgl.ArrayBuffer.prototype.unbind=function(){this.allocated&&this.gl.bindBuffer(this.type,null)},SceneJS._webgl.ArrayBuffer.prototype.destroy=function(){this.allocated&&(this.gl.deleteBuffer(this.handle),this.handle=null,this.allocated=!1)},SceneJS._webgl.ArrayBuffer.prototype.bind=function(){this.allocated&&this.gl.bindBuffer(this.type,this.handle)},SceneJS._webgl.Attribute=function(a,b,c,d,e,f){this.gl=a,this.location=f,this.bindFloatArrayBuffer=function(b){b&&(b.bind(),a.enableVertexAttribArray(f),a.vertexAttribPointer(f,b.itemSize,a.FLOAT,!1,0,0))}},SceneJS._webgl.Attribute.prototype.bindInterleavedFloatArrayBuffer=function(a,b,c){this.gl.enableVertexAttribArray(this.location),this.gl.vertexAttribPointer(this.location,a,this.gl.FLOAT,!1,b,c)},SceneJS._webgl.enumMap={funcAdd:"FUNC_ADD",funcSubtract:"FUNC_SUBTRACT",funcReverseSubtract:"FUNC_REVERSE_SUBTRACT",zero:"ZERO",one:"ONE",srcColor:"SRC_COLOR",oneMinusSrcColor:"ONE_MINUS_SRC_COLOR",dstColor:"DST_COLOR",oneMinusDstColor:"ONE_MINUS_DST_COLOR",srcAlpha:"SRC_ALPHA",oneMinusSrcAlpha:"ONE_MINUS_SRC_ALPHA",dstAlpha:"DST_ALPHA",oneMinusDstAlpha:"ONE_MINUS_DST_ALPHA",contantColor:"CONSTANT_COLOR",oneMinusConstantColor:"ONE_MINUS_CONSTANT_COLOR",constantAlpha:"CONSTANT_ALPHA",oneMinusConstantAlpha:"ONE_MINUS_CONSTANT_ALPHA",srcAlphaSaturate:"SRC_ALPHA_SATURATE",front:"FRONT",back:"BACK",frontAndBack:"FRONT_AND_BACK",never:"NEVER",less:"LESS",equal:"EQUAL",lequal:"LEQUAL",greater:"GREATER",notequal:"NOTEQUAL",gequal:"GEQUAL",always:"ALWAYS",cw:"CW",ccw:"CCW",linear:"LINEAR",nearest:"NEAREST",linearMipMapNearest:"LINEAR_MIPMAP_NEAREST",nearestMipMapNearest:"NEAREST_MIPMAP_NEAREST",nearestMipMapLinear:"NEAREST_MIPMAP_LINEAR",linearMipMapLinear:"LINEAR_MIPMAP_LINEAR",repeat:"REPEAT",clampToEdge:"CLAMP_TO_EDGE",mirroredRepeat:"MIRRORED_REPEAT",alpha:"ALPHA",rgb:"RGB",rgba:"RGBA",luminance:"LUMINANCE",luminanceAlpha:"LUMINANCE_ALPHA",textureBinding2D:"TEXTURE_BINDING_2D",textureBindingCubeMap:"TEXTURE_BINDING_CUBE_MAP",compareRToTexture:"COMPARE_R_TO_TEXTURE",unsignedByte:"UNSIGNED_BYTE"},SceneJS._webgl.RenderBuffer=function(a){this.allocated=!1,this.canvas=a.canvas,this.gl=a.canvas.gl,this.buf=null,this.bound=!1},SceneJS._webgl.RenderBuffer.prototype.webglRestored=function(a){this.gl=a,this.buf=null,this.allocated=!1,this.bound=!1},SceneJS._webgl.RenderBuffer.prototype.bind=function(){this._touch(),this.bound||(this.gl.bindFramebuffer(this.gl.FRAMEBUFFER,this.buf.framebuf),this.bound=!0)},SceneJS._webgl.RenderBuffer.prototype._touch=function(){var a=this.canvas.canvas.width,b=this.canvas.canvas.height;if(this.buf){if(this.buf.width==a&&this.buf.height==b)return;this.gl.deleteTexture(this.buf.texture),this.gl.deleteFramebuffer(this.buf.framebuf),this.gl.deleteRenderbuffer(this.buf.renderbuf)}this.buf={framebuf:this.gl.createFramebuffer(),renderbuf:this.gl.createRenderbuffer(),texture:this.gl.createTexture(),width:a,height:b},this.gl.bindFramebuffer(this.gl.FRAMEBUFFER,this.buf.framebuf),this.gl.bindTexture(this.gl.TEXTURE_2D,this.buf.texture),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_MAG_FILTER,this.gl.NEAREST),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_MIN_FILTER,this.gl.NEAREST),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_WRAP_S,this.gl.CLAMP_TO_EDGE),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_WRAP_T,this.gl.CLAMP_TO_EDGE);try{this.gl.texImage2D(this.gl.TEXTURE_2D,0,this.gl.RGBA,a,b,0,this.gl.RGBA,this.gl.UNSIGNED_BYTE,null)}catch(c){var d=new WebGLUnsignedByteArray(a*b*3);this.gl.texImage2D(this.gl.TEXTURE_2D,0,this.gl.RGBA,a,b,0,this.gl.RGBA,this.gl.UNSIGNED_BYTE,d)}if(this.gl.bindRenderbuffer(this.gl.RENDERBUFFER,this.buf.renderbuf),this.gl.renderbufferStorage(this.gl.RENDERBUFFER,this.gl.DEPTH_COMPONENT16,a,b),this.gl.framebufferTexture2D(this.gl.FRAMEBUFFER,this.gl.COLOR_ATTACHMENT0,this.gl.TEXTURE_2D,this.buf.texture,0),this.gl.framebufferRenderbuffer(this.gl.FRAMEBUFFER,this.gl.DEPTH_ATTACHMENT,this.gl.RENDERBUFFER,this.buf.renderbuf),this.gl.bindTexture(this.gl.TEXTURE_2D,null),this.gl.bindRenderbuffer(this.gl.RENDERBUFFER,null),this.gl.bindFramebuffer(this.gl.FRAMEBUFFER,null),this.gl.bindFramebuffer(this.gl.FRAMEBUFFER,this.buf.framebuf),!this.gl.isFramebuffer(this.buf.framebuf))throw SceneJS_error.fatalError(SceneJS.errors.INVALID_FRAMEBUFFER,"Invalid framebuffer");var e=this.gl.checkFramebufferStatus(this.gl.FRAMEBUFFER);switch(e){case this.gl.FRAMEBUFFER_COMPLETE:break;case this.gl.FRAMEBUFFER_INCOMPLETE_ATTACHMENT:throw SceneJS_error.fatalError(SceneJS.errors.ERROR,"Incomplete framebuffer: FRAMEBUFFER_INCOMPLETE_ATTACHMENT");case this.gl.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:throw SceneJS_error.fatalError(SceneJS.errors.ERROR,"Incomplete framebuffer: FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT");case this.gl.FRAMEBUFFER_INCOMPLETE_DIMENSIONS:throw SceneJS_error.fatalError(SceneJS.errors.ERROR,"Incomplete framebuffer: FRAMEBUFFER_INCOMPLETE_DIMENSIONS");case this.gl.FRAMEBUFFER_UNSUPPORTED:throw SceneJS_error.fatalError(SceneJS.errors.ERROR,"Incomplete framebuffer: FRAMEBUFFER_UNSUPPORTED");default:throw SceneJS_error.fatalError(SceneJS.errors.ERROR,"Incomplete framebuffer: "+e)}this.bound=!1},SceneJS._webgl.RenderBuffer.prototype.clear=function(){if(!this.bound)throw"Render buffer not bound";this.gl.clear(this.gl.COLOR_BUFFER_BIT|this.gl.DEPTH_BUFFER_BIT),this.gl.disable(this.gl.BLEND)},SceneJS._webgl.RenderBuffer.prototype.read=function(a,b){var c=a,d=this.canvas.canvas.height-b,e=new Uint8Array(4);return this.gl.readPixels(c,d,1,1,this.gl.RGBA,this.gl.UNSIGNED_BYTE,e),e},SceneJS._webgl.RenderBuffer.prototype.unbind=function(){this.gl.bindFramebuffer(this.gl.FRAMEBUFFER,null),this.bound=!1},SceneJS._webgl.RenderBuffer.prototype.getTexture=function(){var a=this;return{bind:function(b){return a.buf&&a.buf.texture?(a.gl.activeTexture(a.gl["TEXTURE"+b]),a.gl.bindTexture(a.gl.TEXTURE_2D,a.buf.texture),!0):!1},unbind:function(b){a.buf&&a.buf.texture&&(a.gl.activeTexture(a.gl["TEXTURE"+b]),a.gl.bindTexture(a.gl.TEXTURE_2D,null))}}},SceneJS._webgl.RenderBuffer.prototype.destroy=function(){this.buf&&(this.gl.deleteTexture(this.buf.texture),this.gl.deleteFramebuffer(this.buf.framebuf),this.gl.deleteRenderbuffer(this.buf.renderbuf),this.buf=null,this.bound=!1)},SceneJS._webgl.Program=function(a,b,c){this.allocated=!1,this.gl=a,this._uniforms={},this._samplers={},this._attributes={},this.uniformValues=[],this.materialSettings={specularColor:[0,0,0],specular:0,shine:0,emit:0,alpha:0},this._shaders=[];var d,e,f,g,h,i;for(e=0;ee;++e)f=a.getActiveUniform(this.handle,e),f&&(g=f.name,"\x00"==g[g.length-1]&&(g=g.substr(0,g.length-1)),h=a.getUniformLocation(this.handle,g),f.type==a.SAMPLER_2D||f.type==a.SAMPLER_CUBE||35682==f.type?this._samplers[g]=new SceneJS._webgl.Sampler(a,this.handle,g,f.type,f.size,h):(this._uniforms[g]=new SceneJS._webgl.Uniform(a,this.handle,g,f.type,f.size,h,k),this.uniformValues[k]=null,++k));var l=a.getProgramParameter(this.handle,a.ACTIVE_ATTRIBUTES);for(e=0;l>e;e++)d=a.getActiveAttrib(this.handle,e),d&&(h=a.getAttribLocation(this.handle,d.name),this._attributes[d.name]=new SceneJS._webgl.Attribute(a,this.handle,d.name,d.type,d.size,h));this.allocated=!0}},SceneJS._webgl.Program.prototype.bind=function(){this.allocated&&this.gl.useProgram(this.handle)},SceneJS._webgl.Program.prototype.getUniformLocation=function(a){if(this.allocated){var b=this._uniforms[a];return b?b.getLocation():void 0}},SceneJS._webgl.Program.prototype.getUniform=function(a){if(this.allocated){var b=this._uniforms[a];return b?b:void 0}},SceneJS._webgl.Program.prototype.getAttribute=function(a){if(this.allocated){var b=this._attributes[a];return b?b:void 0}},SceneJS._webgl.Program.prototype.bindFloatArrayBuffer=function(a,b){if(this.allocated){var c=this._attributes[a];c&&c.bindFloatArrayBuffer(b)}},SceneJS._webgl.Program.prototype.bindTexture=function(a,b,c){if(!this.allocated)return!1;var d=this._samplers[a];return d?d.bindTexture(b,c):!1},SceneJS._webgl.Program.prototype.destroy=function(){if(this.allocated){this.gl.deleteProgram(this.handle);for(var a in this._shaders)this.gl.deleteShader(this._shaders[a].handle);this.handle=null,this._attributes=null,this._uniforms=null,this._samplers=null,this.allocated=!1}},SceneJS._webgl.Program.prototype.setUniform=function(a,b){if(this.allocated){var c=this._uniforms[a];c&&(this.uniformValues[c.index]===b&&c.numberValue||(c.setValue(b),this.uniformValues[c.index]=b))}},SceneJS._webgl.Sampler=function(a,b,c,d,e,f){this.bindTexture=function(b,c){return b.bind(c)?(a.uniform1i(f,c),!0):!1}},SceneJS._webgl.Shader=function(a,b,c){if(this.allocated=!1,this.handle=a.createShader(b),!this.handle)throw SceneJS_error.fatalError(SceneJS.errors.OUT_OF_VRAM,"Failed to create WebGL shader");if(a.shaderSource(this.handle,c),a.compileShader(this.handle),this.valid=0!=a.getShaderParameter(this.handle,a.COMPILE_STATUS),!this.valid&&!a.isContextLost()){SceneJS.log.error("Shader program failed to compile: "+a.getShaderInfoLog(this.handle)),SceneJS.log.error("Shader source:");for(var d=c.split("\n"),e=0;eb){var d=b/c,e=a.width*d,f=a.height*d,g=document.createElement("canvas");g.width=SceneJS._webgl.nextHighestPowerOfTwo(e),g.height=SceneJS._webgl.nextHighestPowerOfTwo(f);var h=g.getContext("2d");h.drawImage(a,0,0,a.width,a.height,0,0,g.width,g.height),a=g}return a},SceneJS._webgl.ensureImageSizePowerOfTwo=function(a){if(!SceneJS._webgl.isPowerOfTwo(a.width)||!SceneJS._webgl.isPowerOfTwo(a.height)){var b=document.createElement("canvas");b.width=SceneJS._webgl.nextHighestPowerOfTwo(a.width),b.height=SceneJS._webgl.nextHighestPowerOfTwo(a.height);var c=b.getContext("2d");c.drawImage(a,0,0,a.width,a.height,0,0,b.width,b.height),a=b}return a},SceneJS._webgl.isPowerOfTwo=function(a){return 0==(a&a-1)},SceneJS._webgl.nextHighestPowerOfTwo=function(a){--a;for(var b=1;32>b;b<<=1)a|=a>>b;return a+1},SceneJS._webgl.Uniform=function(a,b,c,d,e,f,g,h){var i=null,j=null;if(d===a.BOOL)i=function(b){j!==b&&(j=b,a.uniform1i(f,b))};else if(d===a.BOOL_VEC2)i=function(b){(null===j||j[0]!==b[0]||j[1]!==b[1])&&(j=b,a.uniform2iv(f,b))};else if(d===a.BOOL_VEC3)i=function(b){(null===j||j[0]!==b[0]||j[1]!==b[1]||j[2]!==b[2])&&(j=b,a.uniform3iv(f,b))};else if(d===a.BOOL_VEC4)i=function(b){(null===j||j[0]!==b[0]||j[1]!==b[1]||j[2]!==b[2]||j[3]!==b[3])&&(j=b,a.uniform4iv(f,b))};else if(d===a.INT)i=function(b){j!==b&&(j=b,a.uniform1iv(f,b))};else if(d===a.INT_VEC2)i=function(b){(null===j||j[0]!==b[0]||j[1]!==b[1])&&(j=b,a.uniform2iv(f,b))};else if(d===a.INT_VEC3)i=function(b){(null===j||j[0]!==b[0]||j[1]!==b[1]||j[2]!==b[2])&&(j=b,a.uniform3iv(f,b))};else if(d===a.INT_VEC4)i=function(b){(null===j||j[0]!==b[0]||j[1]!==b[1]||j[2]!==b[2]||j[3]!==b[3])&&(j=b,a.uniform4iv(f,b))};else if(d===a.FLOAT)i=function(b){j!==b&&(j=b,a.uniform1f(f,b))};else if(d===a.FLOAT_VEC2)i=function(b){(null===j||j[0]!==b[0]||j[1]!==b[1])&&(j=b,a.uniform2fv(f,b))};else if(d===a.FLOAT_VEC3)i=function(b){(null===j||j[0]!==b[0]||j[1]!==b[1]||j[2]!==b[2])&&(j=b,a.uniform3fv(f,b))};else if(d===a.FLOAT_VEC4)i=function(b){(null===j||j[0]!==b[0]||j[1]!==b[1]||j[2]!==b[2]||j[3]!==b[3])&&(j=b,a.uniform4fv(f,b))};else if(d===a.FLOAT_MAT2)i=function(b){a.uniformMatrix2fv(f,a.FALSE,b)};else if(d===a.FLOAT_MAT3)i=function(b){a.uniformMatrix3fv(f,a.FALSE,b)};else{if(d!==a.FLOAT_MAT4)throw"Unsupported shader uniform type: "+d;i=function(b){a.uniformMatrix4fv(f,a.FALSE,b)}}this.setValue=i,this.getLocation=function(){return f},this.index=g};var SceneJS_nodeEventsModule=new function(){var a,b=[],c=[],d=0,e={type:"listeners",stateId:SceneJS._baseStateId++,empty:!0,listeners:[]};SceneJS_events.addListener(SceneJS_events.SCENE_COMPILING,function(){d=0,a=!0}),SceneJS_events.addListener(SceneJS_events.OBJECT_COMPILING,function(f){if(a){if(d>0){var g={type:"listeners",stateId:b[d-1],listeners:c.slice(0,d)};f.display.renderListeners=g}else f.display.renderListeners=e;a=!1}}),this.preVisitNode=function(e){var f=e._topicSubs.rendered,g=e._topicSubs.worldPos,h=e._topicSubs.viewPos,i=e._topicSubs.cameraPos,j=e._topicSubs.projPos,k=e._topicSubs.canvasPos;(f||g||h||i||j||k)&&(b[d]=e.id,c[d]=function(a){f&&e.publish("rendered",a,!0),g&&e.publish("worldPos",a.getWorldPos()),h&&e.publish("viewPos",a.getViewPos()),i&&e.publish("cameraPos",a.getCameraPos()),j&&e.publish("projPos",a.getProjPos()),k&&e.publish("canvasPos",a.getCanvasPos())},d++,a=!0)},this.postVisitNode=function(c){c.id==b[d-1]&&(d--,a=!0)}},SceneJS_Core=function(a){this.type=a,this.coreId=null,this.stateId=null,this.useCount=0},SceneJS_CoreFactory=function(){this._stateMap=new SceneJS_Map(null,SceneJS._baseStateId),this._cores={}};SceneJS_CoreFactory.coreTypes={},SceneJS_CoreFactory.createCoreType=function(a,b){},SceneJS_CoreFactory.addCoreBuilder=function(a,b){},SceneJS_CoreFactory.coreAliases={rotate:"xform",translate:"xform",scale:"xform",matrix:"xform",xform:"xform"},SceneJS_CoreFactory.prototype.getCore=function(a,b){var c=SceneJS_CoreFactory.coreAliases[a];c&&(a=c);var d=this._cores[a];d||(d=this._cores[a]={});var e;return b&&(e=d[b])?(e.useCount++,e):(e=new SceneJS_Core(a),e.useCount=1,e.stateId=this._stateMap.addItem(e),e.coreId=void 0!=b&&null!=b?b:e.stateId,d[e.coreId]=e,e)},SceneJS_CoreFactory.prototype.hasCore=function(a,b){var c=SceneJS_CoreFactory.coreAliases[a];c&&(a=c);var d=this._cores[a];return d&&d[b]},SceneJS_CoreFactory.prototype.putCore=function(a){if(0!=a.useCount&&--a.useCount<=0){var b=this._cores[a.type];delete b[a.coreId],this._stateMap.removeItem(a.stateId)}},SceneJS_CoreFactory.prototype.webglRestored=function(){var a,b;for(var c in this._cores)if(this._cores.hasOwnProperty(c)&&(a=this._cores[c]))for(var d in a)a.hasOwnProperty(d)&&(b=a[d],b&&b.webglRestored&&b.webglRestored())},SceneJS.Node=function(){},SceneJS.Node.prototype.constructor=SceneJS.Node,SceneJS.Node.prototype._construct=function(a,b,c,d){this._engine=a,this._core=b,this.coreId=b.coreId,this.id=c.id||c.nodeId||d,this.type=c.type||"node",this.data=c.data,this.parent=null,this.nodes=[],this._handleMap=new SceneJS_Map,this._topicSubs={},this._handleTopics={},this._topicPubs={},this._listeners={},this._numListeners=0,this.dirty=!1,this.branchDirty=!1,this._init&&this._init(c)},SceneJS.Node.prototype.taskStarted=function(a){return SceneJS_sceneStatusModule.taskStarted(this,a||"Task")},SceneJS.Node.prototype.taskFinished=function(a){return SceneJS_sceneStatusModule.taskFinished(a)},SceneJS.Node.prototype.taskFailed=function(a){return SceneJS_sceneStatusModule.taskFailed(a)},SceneJS.Node.prototype.log=function(){var a,b;switch(1==arguments.length?(a="info",b=arguments[0]):2==arguments.length&&(a=arguments[0],b=arguments[1]),a){case"warn":b="WARN; [SceneJS.Node type="+this.type+", id="+this.id+"] : "+b;break;case"error":b="ERROR; [SceneJS.Node type="+this.type+", id="+this.id+"] : "+b;break;default:b="INFO; [SceneJS.Node type="+this.type+", id="+this.id+"] : "+b}console[a]?console[a](b):console.log(b)},SceneJS.Node.prototype.publish=function(a,b,c){if(c||(this._topicPubs[a]=b),this._topicSubs[a]){var d=this._topicSubs[a];for(var e in d)d.hasOwnProperty(e)&&d[e].call(this,b)}},SceneJS.Node.prototype.unpublish=function(a){var b=this._topicSubs[a];if(b)for(var c in b)b.hasOwnProperty(c)&&b[c].call(this,null);delete this._topicPubs[a]},SceneJS.Node.prototype.on=function(a,b){var c=this._topicSubs[a];c||(c={},this._topicSubs[a]=c);var d=this._handleMap.addItem();c[d]=b,this._handleTopics[d]=a;var e=this._topicPubs[a];return e&&b.call(this,e),"rendered"==a&&this._engine.branchDirty(this),d},SceneJS.Node.prototype.off=function(a){var b=this._handleTopics[a];if(b){delete this._handleTopics[a];var c=this._topicSubs[b];c&&delete c[a],this._handleMap.removeItem(a),"rendered"==b&&this._engine.branchDirty(this)}},SceneJS.Node.prototype.once=function(a,b){var c=this,d=this.on(a,function(a){c.off(d),b(a)})},SceneJS.Node.prototype.getScene=function(){return this._engine.scene},SceneJS.Node.prototype.getCoreId=function(){return this._core.coreId},SceneJS.Node.prototype.getID=function(){return this.id},SceneJS.Node.prototype.getId=function(){return this.id},SceneJS.Node.prototype.getNodeId=function(){return this.id},SceneJS.Node.prototype.getType=function(){return this.type},SceneJS.Node.prototype.getData=function(){return this.data},SceneJS.Node.prototype.setData=function(a){return this.data=a,this},SceneJS.Node.prototype.getNumNodes=function(){return this.nodes.length},SceneJS.Node.prototype.getNodes=function(){return this.nodes.slice(0)},SceneJS.Node.prototype.getNodeAt=function(a){return 0>a||a>=this.nodes.length?null:this.nodes[a]},SceneJS.Node.prototype.getFirstNode=function(){return 0==this.nodes.length?null:this.nodes[0]},SceneJS.Node.prototype.getLastNode=function(){return 0==this.nodes.length?null:this.nodes[this.nodes.length-1]},SceneJS.Node.prototype.getNode=function(a){for(var b=0;b0?(b[0].parent=null,this._engine.display.objectListDirty=!0,b[0]):null},SceneJS.Node.prototype.disconnect=function(){if(this.parent){for(var a=0;ab;b++)this.nodes[b].parent=null;var c=this.nodes;return this.nodes=[],this._engine.display.objectListDirty=!0,c},SceneJS.Node.prototype.removeNodes=function(){for(var a=this.disconnectNodes(),b=0;ba;a++)d[a].parent=this.parent;for(a=0,b=c.nodes.length;b>a;a++)if(c.nodes[a]===this)return c.nodes.splice.apply(c.nodes,[a,1].concat(d)),this.nodes=[],this.parent=null,this.destroy(),this._engine.branchDirty(c),c},SceneJS.Node.prototype.addNodes=function(a,b){if(!a)throw SceneJS_error.fatalError(SceneJS.errors.ILLEGAL_NODE_CONFIG,"Node#addNodes - nodes argument is undefined");for(var c,d=[],e=a.length,f=a.length-1;f>=0;f--){var g=a[f];if("node"==g.type||this._engine.hasNodeType(g.type)){if(c=this.addNode(g),d[f]=c,0==--e)return b&&b(a),a}else{var h=this;!function(){var c=f;h.addNode(g,function(f){d[c]=f,0==--e&&b&&b(a)})}()}}return null},SceneJS.Node.prototype.addNode=function(a,b){if(a=a||{},a._compile){if(null!=a.parent)throw SceneJS_error.fatalError(SceneJS.errors.ILLEGAL_NODE_CONFIG,"Node#addNode - node argument is still attached to another parent");return this.nodes.push(a),a.parent=this,this._engine.branchDirty(a),b&&b(a),a}if("string"==typeof a){var c=this._engine.findNode(a);if(!c)throw SceneJS_error.fatalError(SceneJS.errors.ILLEGAL_NODE_CONFIG,"Node#addNode - node not found: '"+a+"'");if(a=c,null!=a.parent)throw SceneJS_error.fatalError(SceneJS.errors.ILLEGAL_NODE_CONFIG,"Node#addNode - node argument is still attached to another parent");return this.nodes.push(a),a.parent=this,this._engine.branchDirty(a),b&&b(a),a}if(a.type=a.type||"node","node"==a.type||this._engine.hasNodeType(a.type))return a=this._engine.createNode(a),this.nodes.push(a),a.parent=this,this._engine.branchDirty(a),b&&b(a),a;var d=this;return this._engine.createNode(a,function(a){d.nodes.push(a),a.parent=d,d._engine.branchDirty(a),b&&b(a)}),null},SceneJS.Node.prototype.insertNode=function(a,b){if(!a)throw SceneJS_error.fatalError(SceneJS.errors.ILLEGAL_NODE_CONFIG,"SceneJS.Node#insertNode - node argument is undefined");if(a._compile||(a=this._engine.createNode(a)),!a._compile)throw SceneJS_error.fatalError(SceneJS.errors.ILLEGAL_NODE_CONFIG,"SceneJS.Node#insertNode - node argument is not a SceneJS.Node");if(null!=a.parent)throw SceneJS_error.fatalError(SceneJS.errors.ILLEGAL_NODE_CONFIG,"SceneJS.Node#insertNode - node argument is still attached to another parent");if(void 0===b||null===b)a.addNodes(this.disconnectNodes()),this.addNode(a);else{if(0>b)throw SceneJS_error.fatalError(SceneJS.errors.ILLEGAL_NODE_CONFIG,"SceneJS.Node#insertNode - node index out of range: -1");b>=this.nodes.length?this.nodes.push(a):this.nodes.splice(b,0,a)}return a.parent=this,a},SceneJS.Node.prototype.mapNodes=function(a){if(a(this))return this;for(var b,c=0;cg;g++)e=d[g],e.options.scope?e.fn.call(e.options.scope,f):e.fn.call(this,f)}},SceneJS.Node.prototype.removeListener=function(a,b){var c=this._listeners[a];if(!c)return null;for(var d=0;d0},SceneJS.Node.prototype.removeListeners=function(){return this._listeners={},this._numListeners=0,this},SceneJS.Node.prototype.getParent=function(a){return this.parent},SceneJS.Node.prototype.getParentOfType=function(a){for(var b=this.parent;b&&b.type!=a;)b=b.parent;return b},SceneJS.Node.prototype.eachParent=function(a){if(!a)throw"SceneJS.Node.eachParent param 'fn' is null or undefined";for(var b=0,c=this;c.parent;){if(a.call(c.parent,b++)===!0)return c.parent;c=c.parent}return null},SceneJS.Node.prototype.hasNode=function(a){if(null===a||void 0===a)throw"SceneJS.Node.hasNode param 'node' is null or undefined";var b,c=typeof a;if("number"==c)b=this.getNodeAt(a);else{if("string"!=c)throw"SceneJS.Node.hasNode param 'node' should be either an index number or an ID string";b=this.getNode(a)}return void 0!=b&&null!=b},SceneJS.Node.prototype.node=function(a){if(null===a||void 0===a)throw"SceneJS.Node.node param 'node' is null or undefined";var b,c=typeof a;if("number"==c)b=this.getNodeAt(a);else{if("string"!=c)throw"SceneJS.Node.node param 'node' should be either an index number or an ID string";b=this.getNode(a)}if(!b)throw"SceneJS.Node.node - node not found: '"+a+"'";return b},SceneJS.Node.prototype.eachNode=function(a,b){if(!a)throw"SceneJS.Node.eachNode param 'fn' is null or undefined";if("function"!=typeof a)throw"SceneJS.Node.eachNode param 'fn' should be a function";var c;b=b||{};var d=0;return b.andSelf&&a.call(this,d++)===!0?this:(b.depthFirst||b.breadthFirst?b.depthFirst&&(c=this._iterateEachNodeDepthFirst(a,this,d,!1)):c=this._iterateEachNode(a,this,d),c?c:void 0)},SceneJS.Node.prototype.numNodes=function(){return this.nodes.length},SceneJS.Node.prototype._iterateEachNode=function(a,b,c){for(var d,e=b.nodes.length,f=0;e>f;f++)if(d=b.nodes[f],a.call(d,c++)===!0)return d;return null},SceneJS.Node.prototype._iterateEachNodeDepthFirst=function(a,b,c,d){if(d&&a.call(b,c++)===!0)return b;d=!0;for(var e,f=b.nodes.length,g=0;f>g;g++)if(e=this._iterateEachNodeDepthFirst(a,b.nodes[g],c,d))return e;return null},SceneJS.Node.prototype.findNodesByType=function(a,b){return this._findNodesByType(a,[],b)},SceneJS.Node.prototype._findNodesByType=function(a,b,c){var d;for(d=0;dd;d++)c=this.nodes[d],c.branchDirty=c.branchDirty||this.branchDirty,(c.dirty||c.branchDirty||this._engine.sceneDirty)&&(c._compile(a),c.dirty=!1,c.branchDirty=!1);b&&SceneJS_nodeEventsModule.postVisitNode(this)},SceneJS.Node.prototype.destroy=function(){if(!this.destroyed){if(this.parent)for(var a=0;aa;a++)this.nodes[a]._destroyTree()},SceneJS.Node.prototype._doDestroy=function(){return this._destroy&&this._destroy(),this},SceneJS_PubSubProxy=function(a,b){this.scene=a,this.proxy=b};var SceneJS_NodeFactory=function(){this.nodes=new SceneJS_Map({})};SceneJS_NodeFactory.nodeTypes={},SceneJS_NodeFactory._subs={},SceneJS_NodeFactory.createNodeType=function(a,b,c){if(SceneJS_NodeFactory.nodeTypes[a])throw"Node type already defined: "+a;var d=function(){SceneJS.Node.apply(this,arguments),this.type=a};d.prototype=new SceneJS.Node,d.prototype.constructor=d,SceneJS_NodeFactory.nodeTypes[a]=d;var e=SceneJS_NodeFactory.nodeTypes[a];if(!e)throw"Node type plugin did not install itself correctly";c&&c(d);var f=SceneJS_NodeFactory._subs[a];if(f){for(;f.length>0;)f.pop()(e);delete f[a]}return d},SceneJS_NodeFactory.prototype.getNode=function(a,b,c,d){b.type=b.type||"node";var e;if(e="node"==b.type?SceneJS.Node:SceneJS_NodeFactory.nodeTypes[b.type])return this._createNode(e,a,b,c,d);var f=this;this._getType(a,b.type,function(e){f._createNode(e,a,b,c,d)})},SceneJS_NodeFactory.prototype._createNode=function(a,b,c,d,e){var f=new a,g=c.id||c.nodeId;return g?this.nodes.addItem(g,f):g=this.nodes.addItem(f),f._construct(b,d,c,g),e&&e(f),f},SceneJS_NodeFactory.prototype._getType=function(a,b,c){var d=SceneJS_NodeFactory.nodeTypes[b];if(d)return void c(d);var e=SceneJS_NodeFactory._subs[b]||(SceneJS_NodeFactory._subs[b]=[]);if(e.push(c),!(e.length>1)){var f=SceneJS_sceneStatusModule.taskStarted(a.scene,"Loading plugin");e.push(function(){SceneJS_sceneStatusModule.taskFinished(f)});var g=SceneJS_configsModule.configs.pluginPath; +if(!g)throw"no typePath config";this._loadScript(g+"/node/"+b+".js",function(){SceneJS_sceneStatusModule.taskFailed(f)})}},SceneJS_NodeFactory.prototype._loadScript=function(a,b){var c=document.createElement("script");c.type="text/javascript",c.src=a,c.onerror=b,document.getElementsByTagName("head")[0].appendChild(c)},SceneJS_NodeFactory.prototype.putNode=function(a){this.nodes.removeItem(a.id)},function(){function a(a){var b=a.optics;if("ortho"==b.type?a.matrix=SceneJS_math_orthoMat4c(b.left,b.right,b.bottom,b.top,b.near,b.far):"frustum"==b.type?a.matrix=SceneJS_math_frustumMatrix4(b.left,b.right,b.bottom,b.top,b.near,b.far):"perspective"==b.type&&(a.matrix=SceneJS_math_perspectiveMatrix4(b.fovy*Math.PI/180,b.aspect,b.near,b.far)),a.pan){var c=a.pan,d=SceneJS_math_translationMat4v([c.x||0,c.y||0,c.z||0]);a.matrix=SceneJS_math_mulMat4(d,a.matrix,[])}a.mat?a.mat.set(a.matrix):a.mat=new Float32Array(a.matrix)}var b=SceneJS_math_perspectiveMatrix4(45,1,.1,1e4),c=new Float32Array(b),d={type:"camera",stateId:SceneJS._baseStateId++,matrix:b,mat:c,optics:{type:"perspective",fovy:45,aspect:1,near:.1,far:1e4},checkAspect:function(b,c){b.optics.aspect!=c&&(b.optics.aspect=c,a(this))}},e=[],f=0;SceneJS_events.addListener(SceneJS_events.SCENE_COMPILING,function(a){a.engine.display.projTransform=d,f=0}),SceneJS.Camera=SceneJS_NodeFactory.createNodeType("camera"),SceneJS.Camera.prototype._init=function(b){if(1==this._core.useCount){b.optics=b.optics||{};var c=this.getScene().getCanvas();b.optics.aspect=c.width/c.height,this.setOptics(b.optics),b.pan&&this.setPan(b.pan);var d=this;this._canvasSizeSub=this.getScene().on("canvasSize",function(b){d._core.optics.aspect=b.aspect,a(d._core),d._engine.display.imageDirty=!0})}},SceneJS.Camera.getDefaultMatrix=function(){return c},SceneJS.Camera.prototype.setOptics=function(b){var c=this._core;if(b){var d=b.type||c.optics.type||"perspective";if("ortho"==d)c.optics=SceneJS._applyIf(SceneJS_math_ORTHO_OBJ,{type:d,left:b.left,bottom:b.bottom,near:b.near,right:b.right,top:b.top,far:b.far});else if("frustum"==d)c.optics={type:d,left:b.left||-1,bottom:b.bottom||-1,near:b.near||.1,right:b.right||1,top:b.top||1,far:b.far||1e4};else{if("perspective"!=d)throw b.type?SceneJS_error.fatalError(SceneJS.errors.ILLEGAL_NODE_CONFIG,"SceneJS.Camera configuration invalid: optics type not supported - supported types are 'perspective', 'frustum' and 'ortho'"):SceneJS_error.fatalError(SceneJS.errors.ILLEGAL_NODE_CONFIG,"SceneJS.Camera configuration invalid: optics type not specified - supported types are 'perspective', 'frustum' and 'ortho'");c.optics={type:d,fovy:b.fovy||60,aspect:void 0==b.aspect?1:b.aspect,near:b.near||.1,far:b.far||1e4}}}else c.optics={type:"perspective",fovy:60,aspect:1,near:.1,far:1e4};this._core.optics.pan=b.pan,a(this._core),this.publish("matrix",this._core.matrix),this._engine.display.imageDirty=!0},SceneJS.Camera.prototype.setPan=function(b){this._core.pan=b,a(this._core),this.publish("matrix",this._core.matrix),this._engine.display.imageDirty=!0},SceneJS.Camera.prototype.getOptics=function(){var a={};for(var b in this._core.optics)this._core.optics.hasOwnProperty(b)&&(a[b]=this._core.optics[b]);return a},SceneJS.Camera.prototype.getMatrix=function(){return this._core.matrix.slice(0)},SceneJS.Camera.prototype._compile=function(a){this._engine.display.projTransform=e[f++]=this._core,this._compileNodes(a),this._engine.display.projTransform=--f>0?e[f-1]:d},SceneJS.Camera.prototype._destroy=function(){this.getScene().off(this._canvasSizeSub)}}(),function(){var a={type:"clips",stateId:SceneJS._baseStateId++,empty:!0,hash:"",clips:[]},b=[],c=0;SceneJS_events.addListener(SceneJS_events.SCENE_COMPILING,function(b){b.engine.display.clips=a,c=0}),SceneJS.Clips=SceneJS_NodeFactory.createNodeType("clips"),SceneJS.Clips.prototype._init=function(a){if(1==this._core.useCount){var b=a.clips;if(!b)throw SceneJS_error.fatalError(SceneJS.errors.NODE_CONFIG_EXPECTED,"clips node attribute missing : 'clips'");this._core.clips=this._core.clips||[];for(var c=0,d=b.length;d>c;c++)this._setClip(c,b[c])}},SceneJS.Clips.prototype.setClips=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.clips.length)throw SceneJS_error.fatalError(SceneJS.errors.ILLEGAL_NODE_CONFIG,"Invalid argument to set 'clips': index out of range ("+this._core.clips.length+" clips defined)");this._setClip(b,a[c]||{})}this._engine.display.imageDirty=!0},SceneJS.Clips.prototype._setClip=function(a,b){var c=this._core.clips[a]||(this._core.clips[a]={});c.normalAndDist=[b.x||0,b.y||0,b.z||0,b.dist||0];var d=b.mode||c.mode||"disabled";if("inside"!=d&&"outside"!=d&&"disabled"!=d)throw SceneJS_error.fatalError(SceneJS.errors.ILLEGAL_NODE_CONFIG,"clips node invalid value for property 'mode': should be 'inside' or 'outside' or 'disabled'");c.mode=d,this._core.hash=null},SceneJS.Clips.prototype._compile=function(d){this._core.hash||(this._core.hash=this._core.clips.length),this._engine.display.clips=b[c++]=this._core,this._compileNodes(d),this._engine.display.clips=--c>0?b[c-1]:a}}(),function(){var a={stateId:SceneJS._baseStateId++,type:"enable",enabled:!0},b=[],c=0;SceneJS_events.addListener(SceneJS_events.SCENE_COMPILING,function(b){b.engine.display.enable=a,c=0}),SceneJS.Enable=SceneJS_NodeFactory.createNodeType("enable"),SceneJS.Enable.prototype._init=function(a){1==this._core.useCount&&(this._core.enabled=!0,void 0!=a.enabled&&this.setEnabled(a.enabled))},SceneJS.Enable.prototype.setEnabled=function(a){return a!==this._core.enabled&&(this._core.enabled=a,this._engine.display.drawListDirty=!0,this.publish("enabled",a)),this},SceneJS.Enable.prototype.getEnabled=function(){return this._core.enabled},SceneJS.Enable.prototype._compile=function(d){this._engine.display.enable=b[c++]=this._core,this._compileNodes(d),this._engine.display.enable=--c>0?b[c-1]:a}}(),function(){var a={stateId:SceneJS._baseStateId++,type:"flags",picking:!0,clipping:!0,enabled:!0,transparent:!1,backfaces:!0,frontface:"ccw",reflective:!0,solid:!1,hash:"refl;;"},b=[],c=0;SceneJS_events.addListener(SceneJS_events.SCENE_COMPILING,function(b){b.engine.display.flags=a,c=0}),SceneJS.Flags=SceneJS_NodeFactory.createNodeType("flags"),SceneJS.Flags.prototype._init=function(a){1==this._core.useCount&&(this._core.picking=!0,this._core.clipping=!0,this._core.enabled=!0,this._core.transparent=!1,this._core.backfaces=!0,this._core.frontface="ccw",this._core.reflective=!0,this._core.solid=!1,a.flags&&this.setFlags(a.flags))},SceneJS.Flags.prototype.setFlags=function(a){var b=this._core;return void 0!=a.picking&&(b.picking=!!a.picking,this._engine.display.drawListDirty=!0),void 0!=a.clipping&&(b.clipping=!!a.clipping,this._engine.display.imageDirty=!0),void 0!=a.enabled&&(b.enabled=!!a.enabled,this._engine.display.drawListDirty=!0),void 0!=a.transparent&&(b.transparent=!!a.transparent,this._engine.display.stateSortDirty=!0),void 0!=a.backfaces&&(b.backfaces=!!a.backfaces,this._engine.display.imageDirty=!0),void 0!=a.frontface&&(b.frontface=a.frontface,this._engine.display.imageDirty=!0),void 0!=a.reflective&&(b.reflective=a.reflective,b.hash=b.reflective?"refl":"",this._engine.branchDirty(this),this._engine.display.imageDirty=!0),void 0!=a.solid&&(b.solid=a.solid,b.hash=b.reflective?"refl":"",this._engine.branchDirty(this),this._engine.display.imageDirty=!0),this},SceneJS.Flags.prototype.addFlags=function(a){return this.setFlags(a)},SceneJS.Flags.prototype.getFlags=function(){var a=this._core;return{picking:a.picking,clipping:a.clipping,enabled:a.enabled,transparent:a.transparent,backfaces:a.backfaces,frontface:a.frontface,reflective:a.reflective,solid:a.solid}},SceneJS.Flags.prototype.setPicking=function(a){return a=!!a,this._core.picking!=a&&(this._core.picking=a,this._engine.display.drawListDirty=!0),this},SceneJS.Flags.prototype.getPicking=function(){return this._core.picking},SceneJS.Flags.prototype.setClipping=function(a){return a=!!a,this._core.clipping!=a&&(this._core.clipping=a,this._engine.display.imageDirty=!0),this},SceneJS.Flags.prototype.getClipping=function(){return this._core.clipping},SceneJS.Flags.prototype.setEnabled=function(a){return a=!!a,this._core.enabled!=a&&(this._core.enabled=a,this._engine.display.drawListDirty=!0),this},SceneJS.Flags.prototype.getEnabled=function(){return this._core.enabled},SceneJS.Flags.prototype.setTransparent=function(a){return a=!!a,this._core.transparent!=a&&(this._core.transparent=a,this._engine.display.stateOrderDirty=!0),this},SceneJS.Flags.prototype.getTransparent=function(){return this._core.transparent},SceneJS.Flags.prototype.setBackfaces=function(a){return a=!!a,this._core.backfaces!=a&&(this._core.backfaces=a,this._engine.display.imageDirty=!0),this},SceneJS.Flags.prototype.getBackfaces=function(){return this._core.backfaces},SceneJS.Flags.prototype.setFrontface=function(a){return this._core.frontface!=a&&(this._core.frontface=a,this._engine.display.imageDirty=!0),this},SceneJS.Flags.prototype.getFrontface=function(){return this._core.frontface},SceneJS.Flags.prototype.setReflective=function(a){return a=!!a,this._core.reflective!=a&&(this._core.reflective=a,this._core.hash=(a?"refl":"")+this._core.solid?";s":";;",this._engine.branchDirty(this),this._engine.display.imageDirty=!0),this},SceneJS.Flags.prototype.getReflective=function(){return this._core.reflective},SceneJS.Flags.prototype.setSolid=function(a){return a=!!a,this._core.solid!=a&&(this._core.solid=a,this._core.hash=(this._core.reflective?"refl":"")+a?";s;":";;",this._engine.branchDirty(this),this._engine.display.imageDirty=!0),this},SceneJS.Flags.prototype.getSolid=function(){return this._core.solid},SceneJS.Flags.prototype._compile=function(d){this._engine.display.flags=b[c++]=this._core,this._compileNodes(d),this._engine.display.flags=--c>0?b[c-1]:a}}(),new function(){var a={type:"renderTarget",stateId:SceneJS._baseStateId++,targets:null},b={},c=[],d=0;SceneJS_events.addListener(SceneJS_events.SCENE_COMPILING,function(b){b.engine.display.renderTarget=a,d=0}),SceneJS_events.addListener(SceneJS_events.WEBGL_CONTEXT_RESTORED,function(){for(var a in b)b.hasOwnProperty(a)&&b[a]._core.renderBuf.webglRestored()}),SceneJS.ColorTarget=SceneJS_NodeFactory.createNodeType("colorTarget"),SceneJS.ColorTarget.prototype._init=function(a){b[this._core.coreId]=this,this._core.bufType="color",this._core.renderBuf=new SceneJS._webgl.RenderBuffer({canvas:this._engine.canvas})},SceneJS.ColorTarget.prototype._compile=function(b){this.__core||(this.__core=this._engine._coreFactory.getCore("renderTarget"));var e=this._engine.display.renderTarget;this._core.empty||(this.__core.targets=e&&e.targets?e.targets.concat([this._core]):[this._core]),c[d++]=this.__core,this._engine.display.renderTarget=this.__core,this._compileNodes(b),this._engine.display.renderTarget=--d>0?c[d-1]:a},SceneJS.ColorTarget.prototype._destroy=function(){this._core&&(this._core.renderBuf&&this._core.renderBuf.destroy(),delete b[this._core.coreId])}},new function(){var a={type:"renderTarget",stateId:SceneJS._baseStateId++,targets:null},b={},c=[],d=0;SceneJS_events.addListener(SceneJS_events.SCENE_COMPILING,function(b){b.engine.display.renderTarget=a,d=0}),SceneJS_events.addListener(SceneJS_events.WEBGL_CONTEXT_RESTORED,function(){for(var a in b)b.hasOwnProperty(a)&&b[a]._buildNodeCore()}),SceneJS.DepthTarget=SceneJS_NodeFactory.createNodeType("depthTarget"),SceneJS.DepthTarget.prototype._init=function(a){b[this._core.coreId]=this,this._core.bufType="depth",this._core.renderBuf=new SceneJS._webgl.RenderBuffer({canvas:this._engine.canvas})},SceneJS.DepthTarget.prototype._compile=function(b){this.__core||(this.__core=this._engine._coreFactory.getCore("renderTarget"));var e=this._engine.display.renderTarget;this._core.empty||(this.__core.targets=e&&e.targets?e.targets.concat([this._core]):[this._core]),c[d++]=this.__core,this._engine.display.renderTarget=this.__core,this._compileNodes(b),this._engine.display.renderTarget=--d>0?c[d-1]:a},SceneJS.DepthTarget.prototype._destroy=function(){this._core&&(this._core.renderBuf&&this._core.renderBuf.destroy(),delete b[this._core.coreId])}},new function(){var a=[],b=0;SceneJS_events.addListener(SceneJS_events.SCENE_COMPILING,function(){b=0}),SceneJS.Geometry=SceneJS_NodeFactory.createNodeType("geometry"),SceneJS.Geometry.prototype._init=function(a){if(1==this._core.useCount){this._initNodeCore(a,{origin:a.origin,scale:a.scale,autoNormals:"auto"==a.normals}),this._buildNodeCore(this._engine.canvas.gl,this._core);var b=this;this._core.webglRestored=function(){b._buildNodeCore(b._engine.canvas.gl,b._core)}}},SceneJS.Geometry.prototype._initNodeCore=function(a,b){var c=this;b=b||{};var d=a.primitive||"triangles",e=this._core,f=this._engine.canvas.UINT_INDEX_ENABLED?Uint32Array:Uint16Array;e.primitive=this._getPrimitiveType(d),a.normals&&"triangles"==d&&("auto"===a.normals||a.normals===!0)&&a.positions&&a.indices&&this._buildNormals(a),e.arrays={positions:a.positions?new Float32Array(b.scale||b.origin?this._applyOptions(a.positions,b):a.positions):void 0,normals:a.normals?new Float32Array(a.normals):void 0,uv:a.uv?new Float32Array(a.uv):void 0,uv2:a.uv2?new Float32Array(a.uv2):void 0,colors:a.colors?new Float32Array(a.colors):void 0,indices:a.indices?new f(a.indices):void 0},delete a.positions,delete a.normals,delete a.uv,delete a.uv2,delete a.indices,delete a.colors,e.getTangentBuf=function(){if(e.tangentBuf)return e.tangentBuf;var a=e.arrays;if(a.positions&&a.indices&&a.uv){var b=c._engine.canvas.gl,d=new Float32Array(c._buildTangents(a));e.arrays.tangents=d;var f=b.STATIC_DRAW;return e.tangentBuf=new SceneJS._webgl.ArrayBuffer(b,b.ARRAY_BUFFER,d,d.length,3,f)}}},SceneJS.Geometry.prototype._getPrimitiveType=function(a){var b=this._engine.canvas.gl;switch(a){case"points":return b.POINTS;case"lines":return b.LINES;case"line-loop":return b.LINE_LOOP;case"line-strip":return b.LINE_STRIP;case"triangles":return b.TRIANGLES;case"triangle-strip":return b.TRIANGLE_STRIP;case"triangle-fan":return b.TRIANGLE_FAN;default:throw SceneJS_error.fatalError(SceneJS.errors.ILLEGAL_NODE_CONFIG,"geometry primitive unsupported: '"+a+"' - supported types are: 'points', 'lines', 'line-loop', 'line-strip', 'triangles', 'triangle-strip' and 'triangle-fan'")}},SceneJS.Geometry.prototype._applyOptions=function(a,b){var c=a.slice?a.slice(0):new Float32Array(a);if(b.scale)for(var d=void 0!=b.scale.x?b.scale.x:1,e=void 0!=b.scale.y?b.scale.y:1,f=void 0!=b.scale.z?b.scale.z:1,g=0,h=c.length;h>g;g+=3)c[g]*=d,c[g+1]*=e,c[g+2]*=f;if(b.origin)for(var i=void 0!=b.origin.x?b.origin.x:0,j=void 0!=b.origin.y?b.origin.y:0,k=void 0!=b.origin.z?b.origin.z:0,g=0,h=c.length;h>g;g+=3)c[g]-=i,c[g+1]-=j,c[g+2]-=k;return c};var c=function(a){a.vertexBuf&&(a.vertexBuf.destroy(),a.vertexBuf=null),a.normalBuf&&(a.normalBuf.destroy(),a.normalBuf=null),a.uvBuf&&(a.uvBuf.destroy(),a.uvBuf=null),a.uvBuf2&&(a.uvBuf2.destroy(),a.uvBuf2=null),a.colorBuf&&(a.colorBuf.destroy(),a.colorBuf=null),a.tangentBuf&&(a.tangentBuf.destroy(),a.tangentBuf=null),a.indexBuf&&(a.indexBuf.destroy(),a.indexBuf=null),a.interleavedBuf&&(a.interleavedBuf.destroy(),a.interleavedBuf=null)};SceneJS.Geometry.prototype._buildNodeCore=function(a,b){var d=a.STATIC_DRAW;try{var e=b.arrays,f=SceneJS.getConfigs("enableInterleaving")!==!1,g=0,h=0,i=[],j=[],k=function(a,b){return 0==g?g=a.length/b:a.length/b!=g&&(f=!1),i.push(a),j.push(b),h+=b,4*(h-b)};if(e.positions&&(f&&(b.interleavedPositionOffset=k(e.positions,3)),b.vertexBuf=new SceneJS._webgl.ArrayBuffer(a,a.ARRAY_BUFFER,e.positions,e.positions.length,3,d)),e.normals&&(f&&(b.interleavedNormalOffset=k(e.normals,3)),b.normalBuf=new SceneJS._webgl.ArrayBuffer(a,a.ARRAY_BUFFER,e.normals,e.normals.length,3,d)),e.uv&&(f&&(b.interleavedUVOffset=k(e.uv,2)),b.uvBuf=new SceneJS._webgl.ArrayBuffer(a,a.ARRAY_BUFFER,e.uv,e.uv.length,2,d)),e.uv2&&(f&&(b.interleavedUV2Offset=k(e.uv2,2)),b.uvBuf2=new SceneJS._webgl.ArrayBuffer(a,a.ARRAY_BUFFER,e.uv2,e.uv2.length,2,d)),e.colors&&(f&&(b.interleavedColorOffset=k(e.colors,4)),b.colorBuf=new SceneJS._webgl.ArrayBuffer(a,a.ARRAY_BUFFER,e.colors,e.colors.length,4,d)),e.indices&&(b.indexBuf=new SceneJS._webgl.ArrayBuffer(a,a.ELEMENT_ARRAY_BUFFER,e.indices,e.indices.length,1,d)),h>0&&f){for(var l=[],m=i.length,n=0;g>n;++n)for(var o=0;m>o;++o)for(var p=j[o],q=0;p>q;++q)l.push(i[o][n*p+q]);b.interleavedStride=4*h,b.interleavedBuf=new SceneJS._webgl.ArrayBuffer(a,a.ARRAY_BUFFER,new Float32Array(l),l.length,h,d),b.interleavedBuf.dirty=!1}}catch(r){throw c(b),SceneJS_error.fatalError(SceneJS.errors.ERROR,"Failed to allocate geometry: "+r)}},SceneJS.Geometry.prototype._updateArray=function(a,b,c){var d=a.length,e=b.length;e+c>d&&(e-=e+c-d);for(var f=c,g=0;e>g;f++,g++)a[f]=b[g]},SceneJS.Geometry.prototype._buildNormals=function(a){for(var b,c,d,e,f,g,h=a.positions,i=a.indices,j=new Array(h.length/3),k=0,l=i.length-3;l>k;k+=3){b=i[k+0],c=i[k+1],d=i[k+2],e=[h[3*b+0],h[3*b+1],h[3*b+2]],f=[h[3*c+0],h[3*c+1],h[3*c+2]],g=[h[3*d+0],h[3*d+1],h[3*d+2]],f=SceneJS_math_subVec4(f,e,[0,0,0,0]),g=SceneJS_math_subVec4(g,e,[0,0,0,0]);var m=SceneJS_math_normalizeVec4(SceneJS_math_cross3Vec4(f,g,[0,0,0,0]),[0,0,0,0]);j[b]||(j[b]=[]),j[c]||(j[c]=[]),j[d]||(j[d]=[]),j[b].push(m),j[c].push(m),j[d].push(m)}for(var n=new Array(h.length),k=0,l=j.length;l>k;k++){for(var o=j[k].length,p=0,q=0,r=0,s=0;o>s;s++)p+=j[k][s][0],q+=j[k][s][1],r+=j[k][s][2];n[3*k+0]=p/o,n[3*k+1]=q/o,n[3*k+2]=r/o}a.normals=n},SceneJS.Geometry.prototype._buildTangents=function(a){for(var b=a.positions,c=a.indices,d=a.uv,e=[],f=0;ft;t++){var u=c[f+t];"undefined"!=typeof e[u]?e[u]=SceneJS_math_addVec3(e[u],s,[]):e[u]=s}}for(var v=[],w=0;wf;f+=3)c=b[f],d=b[f+1],e=b[f+2],cthis._boundary.xmax&&(this._boundary.xmax=c),d>this._boundary.ymax&&(this._boundary.ymax=d),e>this._boundary.zmax&&(this._boundary.zmax=e);return this._boundary},SceneJS.Geometry.prototype._compile=function(c){if(this._core._loading)return void this._compileNodes(c);var d=this._core;d.vertexBuf||(d=this._inheritVBOs(d)),d.indexBuf?(d.hash=[d.normalBuf?"t":"f",d.arrays&&d.arrays.tangents?"t":"f",d.uvBuf?"t":"f",d.uvBuf2?"t":"f",d.colorBuf?"t":"f",d.primitive].join(""),d.stateId=this._core.stateId,d.type="geometry",this._engine.display.geometry=a[b++]=d,SceneJS_events.fireEvent(SceneJS_events.OBJECT_COMPILING,{display:this._engine.display}),this._engine.display.buildObject(this.id)):a[b++]=this._core,this._compileNodes(c),b--},SceneJS.Geometry.prototype._inheritVBOs=function(c){for(var d={primitive:c.primitive,boundary:c.boundary,normalBuf:c.normalBuf,uvBuf:c.uvBuf,uvBuf2:c.uvBuf2,colorBuf:c.colorBuf,interleavedBuf:c.interleavedBuf,indexBuf:c.indexBuf,interleavedStride:c.interleavedStride,interleavedPositionOffset:c.interleavedPositionOffset,interleavedNormalOffset:c.interleavedNormalOffset,interleavedUVOffset:c.interleavedUVOffset,interleavedUV2Offset:c.interleavedUV2Offset,interleavedColorOffset:c.interleavedColorOffset},e=b-1;e>=0;e--)if(a[e].vertexBuf)return d.vertexBuf=a[e].vertexBuf,d.boundary=a[e].boundary,d.normalBuf=a[e].normalBuf,d.uvBuf=a[e].uvBuf,d.uvBuf2=a[e].uvBuf2,d.colorBuf=a[e].colorBuf,d.interleavedBuf=a[e].interleavedBuf,d.interleavedStride=a[e].interleavedStride,d.interleavedPositionOffset=a[e].interleavedPositionOffset,d.interleavedNormalOffset=a[e].interleavedNormalOffset,d.interleavedUVOffset=a[e].interleavedUVOffset,d.interleavedUV2Offset=a[e].interleavedUV2Offset,d.interleavedColorOffset=a[e].interleavedColorOffset,d;return d},SceneJS.Geometry.prototype._destroy=function(){this._engine.display.removeObject(this.id),1==this._core.useCount&&(this._destroyNodeCore(),this._source&&this._source.destroy&&this._source.destroy())},SceneJS.Geometry.prototype._destroyNodeCore=function(){document.getElementById(this._engine.canvas.canvasId)&&c(this._core)}},function(){var a={type:"stage",stateId:SceneJS._baseStateId++,priority:0,pickable:!0,enabled:!0},b=[],c=0;SceneJS_events.addListener(SceneJS_events.SCENE_COMPILING,function(b){b.engine.display.stage=a,c=0}),SceneJS.Stage=SceneJS_NodeFactory.createNodeType("stage"),SceneJS.Stage.prototype._init=function(a){1==this._core.useCount&&(this._core.priority=a.priority||0,this._core.enabled=a.enabled!==!1,this._core.pickable=!!a.pickable)},SceneJS.Stage.prototype.setPriority=function(a){a=a||0,this._core.priority!=a&&(this._core.priority=a,this._engine.display.stateOrderDirty=!0)},SceneJS.Stage.prototype.getPriority=function(){return this._core.priority},SceneJS.Stage.prototype.setEnabled=function(a){a=!!a,this._core.enabled!=a&&(this._core.enabled=a,this._engine.display.drawListDirty=!0)},SceneJS.Stage.prototype.getEnabled=function(){return this._core.enabled},SceneJS.Stage.prototype.getEnabled=function(){return this._core.enabled},SceneJS.Stage.prototype._compile=function(d){this._engine.display.stage=b[c++]=this._core,this._compileNodes(d),this._engine.display.stage=--c>0?b[c-1]:a}}(),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}}(),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}}(),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},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],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.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.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}},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){if(this._sourceConfigs=a.source,this._source=null,a.source){if(!a.source.type)throw SceneJS_error.fatalError(SceneJS.errors.ILLEGAL_NODE_CONFIG,"morphGeometry config expected: source.type");var b=this;SceneJS.Plugins.getPlugin("morphGeometry",this._sourceConfigs.type,function(c){if(!c)throw SceneJS_error.fatalError(SceneJS.errors.PLUGIN_INVALID,"morphGeometry: no support for source type '"+b._sourceConfigs.type+"' - need to include plugin for self source type, or install a custom source service with SceneJS.Plugins.addPlugin(SceneJS.Plugins.MORPH_GEO_SOURCE_PLUGIN, '"+b._sourceConfigs.type+"', ).");if(!c.getSource)throw SceneJS_error.fatalError(SceneJS.errors.PLUGIN_INVALID,"morphGeometry: 'getSource' method not found on MorphGeoFactoryService (SceneJS.Plugins.MORPH_GEO_SOURCE_PLUGIN)");if(b._source=c.getSource(),!b._source.subscribe)throw SceneJS_error.fatalError(SceneJS.errors.PLUGIN_INVALID,"morphGeometry: 'subscribe' method not found on source provided by plugin type '"+a.source.type+"'");var d=!1;b._source.subscribe(function(a){if(d){if(a.targets)for(var c,e,f,g=a.targets,h=b._core.targets,i=0,j=g.length;j>i;i++)c=g[i],e=c.targetIndex,f=h[e],c.positions&&f.vertexBuf&&(f.vertexBuf.bind(),f.vertexBuf.setData(c.positions,0));b._display.imageDirty=!0}else b._buildNodeCore(a),b._core._loading=!1,b._fireEvent("loaded"),b._engine.branchDirty(b),d=!0}),b._core._loading=!0,b._fireEvent("loading"),b._source.configure(b._sourceConfigs)})}else a.create instanceof Function?this._buildNodeCore(a.create()):this._buildNodeCore(a);this._core.webglRestored=function(){},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="Float32Array"==typeof o?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="Float32Array"==typeof o?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="Float32Array"==typeof o?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="Float32Array"==typeof o?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)}},SceneJS.MorphGeometry.prototype.setSource=function(a){this._sourceConfigs=a;var b=this._source;b&&b.configure(a)},SceneJS.MorphGeometry.prototype.getSource=function(){return this._sourceConfigs},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},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){if(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.normalBuf&&a.normalBuf.destroy(),a.uvBuf&&a.uvBuf.destroy(),a.uvBuf2&&a.uvBuf2.destroy();this._source&&this._source.destroy&&this._source.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}}(),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}},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}}(),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,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}}(),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.setSSAAMultiplier=function(a){return this._engine.canvas.setSSAAMultiplier(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.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){return this._engine.readPixels(a,b)},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}}(),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}}(),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=SceneJS_sceneStatusModule.taskStarted(this,"Loading texture"),g=new Image;g.onload=function(){var d=a.createTexture();a.bindTexture(a.TEXTURE_2D,d);var e=SceneJS_configsModule.configs.maxTextureSize;e&&(g=SceneJS._webgl.clampImageSize(g,e)),a.texImage2D(a.TEXTURE_2D,0,a.RGBA,a.RGBA,a.UNSIGNED_BYTE,c._ensureImageSizePowerOfTwo(g)),c._setLayerTexture(a,b,d),SceneJS_sceneStatusModule.taskFinished(f),c._engine.display.imageDirty=!0},g.onerror=function(){SceneJS_sceneStatusModule.taskFailed(f)},0==e.indexOf("data")?g.src=e:(g.crossOrigin="Anonymous",g.src=e)}},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},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){if(b.applyFrom&&"uv"!=b.applyFrom&&"uv2"!=b.applyFrom&&"normal"!=b.applyFrom&&"geometry"!=b.applyFrom)throw SceneJS_error.fatalError(SceneJS.errors.NODE_CONFIG_EXPECTED,"texture applyFrom value is unsupported - should be either 'uv', 'uv2', 'normal' or 'geometry'");if(b.applyTo&&"baseColor"!=b.applyTo&&"color"!=b.applyTo&&"specular"!=b.applyTo&&"emit"!=b.applyTo&&"alpha"!=b.applyTo&&"normals"!=b.applyTo&&"shine"!=b.applyTo)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,applyFrom:b.applyFrom?b.applyFrom:"uv",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._core.src=b.src,this._loadTexture(b.src)):b.image?(this._core.image=b.image,this._initTexture(b.image)):b.target&&this.getScene().getNode(b.target,function(a){c.setTarget(a)}),this._core.webglRestored=function(){c._core.image?c._initTexture(c._core.image):c._core.src?c._loadTexture(c._core.src):c._core.target}}},SceneJS.TextureMap.prototype._loadTexture=function(a){var b=this,c=SceneJS_sceneStatusModule.taskStarted(this,"Loading texture"),d=new Image;d.onload=function(){b._initTexture(d),SceneJS_sceneStatusModule.taskFinished(c),b._engine.display.imageDirty=!0},d.onerror=function(){SceneJS_sceneStatusModule.taskFailed(c)},0==a.indexOf("data")?d.src=a:(d.crossOrigin="Anonymous",d.src=a)},SceneJS.TextureMap.prototype._initTexture=function(a){var b=this._engine.canvas.gl,c=b.createTexture();b.bindTexture(b.TEXTURE_2D,c);var d=SceneJS_configsModule.configs.maxTextureSize;d&&(a=SceneJS._webgl.clampImageSize(a,d)),b.texImage2D(b.TEXTURE_2D,0,b.RGBA,b.RGBA,b.UNSIGNED_BYTE,SceneJS._webgl.ensureImageSizePowerOfTwo(a)),this._core.image=a,this._core.texture=new SceneJS._webgl.Texture2D(b,{texture:c,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._initTexture(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},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)}},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},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)}}(),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,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.cubemap=null,this.modelTransform=null,this.viewTransform=null,this.projTransform=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._drawList=[],this._drawListLen=0,this._pickDrawList=[],this._pickDrawListLen=0,this._targetList=[],this._targetListLen=0,this._frameCtx={pickNames:[],canvas:this._canvas,VAO:null},this._frameCtx.renderListenerCtx=new SceneJS.RenderContext(this._frameCtx),this.objectListDirty=!0,this.stateOrderDirty=!0,this.stateSortDirty=!0,this.drawListDirty=!0,this.imageDirty=!0,this.pickBufDirty=!0,this.rayPickBufDirty=!0};SceneJS_Display.prototype.webglRestored=function(){this._programFactory.webglRestored(),this._chunkFactory.webglRestored();var a=this._canvas.gl;this.pickBuf&&this.pickBuf.webglRestored(a),this.rayPickBuf&&this.rayPickBuf.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.stage=this.stage,b.layer=this.layer,b.renderTarget=this.renderTarget,b.texture=this.texture,b.cubemap=this.cubemap,b.geometry=this.geometry,b.enable=this.enable,b.flags=this.flags,b.tag=this.tag;var c=[this.geometry.hash,this.shader.hash,this.clips.hash,this.morphGeometry.hash,this.texture.hash,this.cubemap.hash,this.lights.hash,this.flags.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,"name",this.name),this._setChunk(b,12,"lights",this.lights),this._setChunk(b,13,"material",this.material),this._setChunk(b,14,"texture",this.texture),this._setChunk(b,15,"cubemap",this.cubemap),this._setChunk(b,16,"clips",this.clips),this._setChunk(b,17,"renderer",this.renderer),this._setChunk(b,18,"geometry",this.morphGeometry,this.geometry),this._setChunk(b,19,"listeners",this.renderListeners),this._setChunk(b,20,"draw",this.geometry)},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];b&&(this._programFactory.putProgram(b.program),b.program=null,b.hash=null,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)&&(this._doDrawList({clear:a.clear!==!1}),this.imageDirty=!1,this.pickBufDirty=!0)},SceneJS_Display.prototype._buildObjectList=function(){this._objectListLen=0;for(var a in this._objects)this._objects.hasOwnProperty(a)&&(this._objectList[this._objectListLen++]=this._objects[a])},SceneJS_Display.prototype._makeStateSortKeys=function(){for(var a,b=0,c=this._objectListLen;c>b;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||[];for(var a=0;23>a;a++)this._lastStateId[a]=null,this._lastPickStateId[a]=null;this._drawListLen=0,this._pickDrawListLen=0;var b,c,d,e,f,g={},h=[],i=[];this._tagSelector&&(c=this._tagSelector.mask,d=this._tagSelector.regex),this._objectDrawList=this._objectDrawList||[],this._objectDrawListLen=0;for(var a=0,j=this._objectListLen;j>a;a++)if(b=this._objectList[a],b.enable.enabled!==!1&&(f=b.flags,f.enabled!==!1&&b.layer.enabled&&(!c||(e=b.tag,!e.tag||(e.mask!=c&&(e.mask=c,e.matches=d.test(e.tag)),e.matches)))))if(b.renderTarget.targets)for(var k,l,m,n=b.renderTarget.targets,o=0,p=n.length;p>o;o++)k=n[o],l=k.coreId,m=g[l],m||(m=[],g[l]=m,h.push(m),i.push(this._chunkFactory.getChunk(k.stateId,"renderTarget",b.program,k))),m.push(b);else this._objectDrawList[this._objectDrawListLen++]=b;for(var m,k,b,q,a=0,j=h.length;j>a;a++){m=h[a],k=i[a],this._appendRenderTargetChunk(k);for(var o=0,p=m.length;p>o;o++)b=m[o],q=b.stage&&b.stage.pickable,this._appendObjectToDrawLists(b,q)}b&&this._appendRenderTargetChunk(this._chunkFactory.getChunk(-1,"renderTarget",b.program,{}));for(var a=0,j=this._objectDrawListLen;j>a;a++)b=this._objectDrawList[a],q=!b.stage||b.stage&&b.stage.pickable,this._appendObjectToDrawLists(b,q);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=a.flags.picking,f=0,g=d.length;g>f;f++)c=d[f],c&&(c.draw&&(c.unique||this._lastStateId[f]!=c.id)&&(this._drawList[this._drawListLen++]=c,this._lastStateId[f]=c.id),c.pick&&b!==!1&&e&&(c.unique||this._lastPickStateId[f]!=c.id)&&(this._pickDrawList[this._pickDrawListLen++]=c,this._lastPickStateId[f]=c.id))},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("--------------------------------------------------------------------------------------------------")},SceneJS_Display.prototype.pick=function(a){var b=this._canvas.canvas,c=this._canvas.ssaaMultiplier,d=null,e=a.canvasX*c,f=a.canvasY*c,g=this.pickBuf;g||(g=this.pickBuf=new SceneJS._webgl.RenderBuffer({canvas:this._canvas}),this.pickBufDirty=!0),this.render(),g.bind(),this.pickBufDirty&&(g.clear(),this._doDrawList({pick:!0,clear:!0}),this._canvas.gl.finish(),this.pickBufDirty=!1,this.rayPickBufDirty=!0);var h=g.read(e,f),i=h[0]+256*h[1]+65536*h[2],j=i>=1?i-1:-1;g.unbind();var k=this._frameCtx.pickNames[j];if(k&&(d={name:k.name,path:k.path,nodeId:k.nodeId,canvasPos:[e,f]},a.rayPick)){var l=this.rayPickBuf;l||(l=this.rayPickBuf=new SceneJS._webgl.RenderBuffer({canvas:this._canvas}),this.rayPickBufDirty=!0),l.bind(),this.rayPickBufDirty&&(l.clear(),this._doDrawList({pick:!0,rayPick:!0,clear:!0}),this.rayPickBufDirty=!1),h=l.read(e,f),l.unbind();var m=this._unpackDepth(h),n=b.width,o=b.height,p=(e-n/2)/(n/2),q=-(f-o/2)/(o/2),r=this._frameCtx.cameraMat,s=this._frameCtx.viewMat,t=SceneJS_math_mulMat4(r,s,[]),u=SceneJS_math_inverseMat4(t,[]),v=SceneJS_math_transformVector4(u,[p,q,-1,1]);v=SceneJS_math_mulVec4Scalar(v,1/v[3]);var w=SceneJS_math_transformVector4(u,[p,q,1,1]);w=SceneJS_math_mulVec4Scalar(w,1/w[3]);var x=SceneJS_math_subVec3(w,v,[]),y=SceneJS_math_addVec3(v,SceneJS_math_mulVec4Scalar(x,m,[]),[]);d.worldPos=y}return d},SceneJS_Display.prototype.readPixels=function(a,b){this._readPixelBuf||(this._readPixelBuf=new SceneJS._webgl.RenderBuffer({canvas:this._canvas})),this._readPixelBuf.bind(),this._readPixelBuf.clear(),this.render({force:!0});for(var c,d,e=0;b>e;e++)c=a[e]||(a[e]={}),d=this._readPixelBuf.read(c.x,c.y),c.r=d[0],c.g=d[1],c.b=d[2],c.a=d[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._doDrawList=function(a){var b=this._canvas.gl,c=this._frameCtx;c.renderTarget=null,c.targetIndex=0,c.renderBuf=null,c.viewMat=null,c.modelMat=null,c.cameraMat=null,c.renderer=null,c.depthbufEnabled=null,c.clearDepth=null,c.depthFunc=b.LESS,c.scissorTestEnabled=!1,c.blendEnabled=!1,c.backfaces=!0,c.frontface="ccw",c.pick=!!a.pick,c.rayPick=!!a.rayPick,c.pickIndex=0,c.textureUnit=0,c.lineWidth=1,c.transparent=!1,c.ambientColor=this._ambientColor,c.aspect=this._canvas.canvas.width/this._canvas.canvas.height,this._canvas.UINT_INDEX_ENABLED&&b.getExtension("OES_element_index_uint");var d=b.getExtension("OES_vertex_array_object");if(c.VAO=d?d:null,b.viewport(0,0,b.drawingBufferWidth,b.drawingBufferHeight),this.transparent?b.clearColor(0,0,0,0):b.clearColor(this._ambientColor[0],this._ambientColor[1],this._ambientColor[2],1),a.clear&&b.clear(b.COLOR_BUFFER_BIT|b.DEPTH_BUFFER_BIT|b.STENCIL_BUFFER_BIT),b.frontFace(b.CCW),b.disable(b.CULL_FACE),b.disable(b.BLEND),a.pick)for(var e=0,f=this._pickDrawListLen;f>e;e++)this._pickDrawList[e].pick(c);else for(var e=0,f=this._drawListLen;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.destroy=function(){this._programFactory.destroy()};var SceneJS_ProgramSourceFactory=new function(){function a(a){if(a.renderTarget&&a.renderTarget.targets)for(var b=a.renderTarget.targets,c=0,d=b.length;d>c;c++)if("depth"===b[c].bufType)return!0;return!1}function b(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"}this._sourceCache={},this.getSource=function(a,b){var c=this._sourceCache[a];return c?(c.useCount++,c):this._sourceCache[a]=new SceneJS_ProgramSource(a,this._composePickingVertexShader(b),this._composePickingFragmentShader(b),this._composeRenderingVertexShader(b),this._composeRenderingFragmentShader(b))},this.putSource=function(a){var b=this._sourceCache[a];b&&0==--b.useCount&&(this._sourceCache[b.hash]=null)},this._composePickingVertexShader=function(a){var b=!!a.morphGeometry.targets,c=["attribute vec3 SCENEJS_aVertex;","uniform mat4 SCENEJS_uMMatrix;","uniform mat4 SCENEJS_uVMatrix;","uniform mat4 SCENEJS_uVNMatrix;","uniform mat4 SCENEJS_uPMatrix;"];return c.push("varying vec4 SCENEJS_vWorldVertex;"),c.push("varying vec4 SCENEJS_vViewVertex;"),b&&(c.push("uniform float SCENEJS_uMorphFactor;"),a.morphGeometry.targets[0].vertexBuf&&c.push("attribute vec3 SCENEJS_aMorphVertex;")),c.push("void main(void) {"),c.push(" vec4 tmpVertex=vec4(SCENEJS_aVertex, 1.0); "),b&&a.morphGeometry.targets[0].vertexBuf&&c.push(" tmpVertex = vec4(mix(tmpVertex.xyz, SCENEJS_aMorphVertex, SCENEJS_uMorphFactor), 1.0); "),c.push(" SCENEJS_vWorldVertex = SCENEJS_uMMatrix * tmpVertex; "),c.push(" SCENEJS_vViewVertex = SCENEJS_uVMatrix * SCENEJS_vWorldVertex;"),c.push(" gl_Position = SCENEJS_uPMatrix * SCENEJS_vViewVertex;"),c.push("}"),c},this._composePickingFragmentShader=function(a){var c=a.clips.clips.length>0,d=b(a._canvas.gl),e=["precision "+d+" float;"];if(e.push("varying vec4 SCENEJS_vWorldVertex;"),e.push("varying vec4 SCENEJS_vViewVertex;"),e.push("uniform bool SCENEJS_uRayPickMode;"),e.push("uniform vec3 SCENEJS_uPickColor;"),e.push("uniform float SCENEJS_uZNear;"),e.push("uniform float SCENEJS_uZFar;"),e.push("uniform bool SCENEJS_uClipping;"),c)for(var f=0;f 0.0) { discard; }"),e.push("}")}return e.push(" if (SCENEJS_uRayPickMode) {"),e.push(" float zNormalizedDepth = abs((SCENEJS_uZNear + SCENEJS_vViewVertex.z) / (SCENEJS_uZFar - SCENEJS_uZNear));"),e.push(" gl_FragColor = packDepth(zNormalizedDepth); "),e.push(" } else {"),e.push(" gl_FragColor = vec4(SCENEJS_uPickColor.rgb, 1.0); "),e.push(" }"),e.push("}"),e},this._isTexturing=function(a){if(a.texture.layers&&a.texture.layers.length>0){if(a.geometry.uvBuf||a.geometry.uvBuf2)return!0;if(a.morphGeometry.targets&&(a.morphGeometry.targets[0].uvBuf||a.morphGeometry.targets[0].uvBuf2))return!0}return!1},this._isCubeMapping=function(a){return a.flags.reflective&&a.cubemap.layers&&a.cubemap.layers.length>0&&a.geometry.normalBuf},this._hasNormals=function(a){return a.geometry.normalBuf?!0:a.morphGeometry.targets&&a.morphGeometry.targets[0].normalBuf?!0:!1},this._hasTangents=function(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},this._composeRenderingVertexShader=function(a){var b=a.shader.shaders||{};if(b.vertex&&b.vertex.code&&""!=b.vertex.code&&SceneJS._isEmpty(b.vertex.hooks))return[b.vertex.code];var c=b.vertex||{},d=c.hooks||{},e=b.fragment||{},f=e.hooks||{},g=this._isTexturing(a),h=this._hasNormals(a),i=this._hasTangents(a),j=a.clips.clips.length>0,k=!!a.morphGeometry.targets,l=[];if(l.push("uniform mat4 SCENEJS_uMMatrix;"),l.push("uniform mat4 SCENEJS_uVMatrix;"),l.push("uniform mat4 SCENEJS_uPMatrix;"),l.push("attribute vec3 SCENEJS_aVertex;"),l.push("uniform vec3 SCENEJS_uWorldEye;"),l.push("varying vec3 SCENEJS_vViewEyeVec;"),h){l.push("attribute vec3 SCENEJS_aNormal;"),l.push("uniform mat4 SCENEJS_uMNMatrix;"),l.push("uniform mat4 SCENEJS_uVNMatrix;"),l.push("varying vec3 SCENEJS_vViewNormal;"),i&&l.push("attribute vec4 SCENEJS_aTangent;");for(var m=0;m0,m=b(c._canvas.gl),n=["\n"];if(n.push("precision "+m+" float;"),l&&n.push("varying vec4 SCENEJS_vWorldVertex;"),n.push("varying vec4 SCENEJS_vViewVertex;"),n.push("uniform float SCENEJS_uZNear;"),n.push("uniform float SCENEJS_uZFar;"),l)for(var o=0;oo;o++)p=c.texture.layers[o],n.push("uniform sampler2D SCENEJS_uSampler"+o+";"),p.matrix&&n.push("uniform mat4 SCENEJS_uLayer"+o+"Matrix;"),n.push("uniform float SCENEJS_uLayer"+o+"BlendFactor;")}if(i&&h)for(var p,o=0,q=c.cubemap.layers.length;q>o;o++)p=c.cubemap.layers[o],n.push("uniform samplerCube SCENEJS_uCubeMapSampler"+o+";"),n.push("uniform float SCENEJS_uCubeMapIntensity"+o+";");if(n.push("uniform bool SCENEJS_uClipping;"),n.push("uniform bool SCENEJS_uSolid;"),n.push("uniform bool SCENEJS_uDepthMode;"),n.push("uniform bool SCENEJS_uTransparent;"),c.geometry.colorBuf&&n.push("varying vec4 SCENEJS_vColor;"),n.push("uniform vec3 SCENEJS_uAmbientColor;"),n.push("uniform vec3 SCENEJS_uMaterialColor;"),n.push("uniform float SCENEJS_uMaterialAlpha;"),n.push("uniform float SCENEJS_uMaterialEmit;"),n.push("uniform vec3 SCENEJS_uMaterialSpecularColor;"),n.push("uniform float SCENEJS_uMaterialSpecular;"),n.push("uniform float SCENEJS_uMaterialShine;"),n.push("varying vec3 SCENEJS_vViewEyeVec;"),i){n.push("varying vec3 SCENEJS_vViewNormal;");for(var r,o=0;o 0.0) { discard; }"),n.push("}")}i&&j&&(n.push(" float a = dot(normalize(SCENEJS_vViewNormal), normalize(SCENEJS_vViewEyeVec));"),n.push(" if (a < 0.0) {"),n.push(" gl_FragColor = vec4(0.4, 0.4, 1.0, 1.0);"),n.push(" return;"),n.push(" }")),n.push(" vec3 ambient= SCENEJS_uAmbientColor;"),g&&c.geometry.uvBuf&&f.texturePos&&n.push(f.texturePos+"(SCENEJS_vUVCoord);"),f.viewPos&&n.push(f.viewPos+"(SCENEJS_vViewVertex);"),i&&f.viewNormal&&n.push(f.viewNormal+"(SCENEJS_vViewNormal);"),c.geometry.colorBuf?n.push(" vec3 color = SCENEJS_vColor.rgb;"):n.push(" vec3 color = SCENEJS_uMaterialColor;"),n.push(" float alpha = SCENEJS_uMaterialAlpha;"),n.push(" float emit = SCENEJS_uMaterialEmit;"),n.push(" float specular = SCENEJS_uMaterialSpecular;"),n.push(" vec3 specularColor = SCENEJS_uMaterialSpecularColor;"),n.push(" float shine = SCENEJS_uMaterialShine;"),f.materialBaseColor&&n.push("color="+f.materialBaseColor+"(color);"),f.materialAlpha&&n.push("alpha="+f.materialAlpha+"(alpha);"),f.materialEmit&&n.push("emit="+f.materialEmit+"(emit);"),f.materialSpecular&&n.push("specular="+f.materialSpecular+"(specular);"),f.materialSpecularColor&&n.push("specularColor="+f.materialSpecularColor+"(specularColor);"),f.materialShine&&n.push("shine="+f.materialShine+"(shine);"),i&&(n.push(" float attenuation = 1.0;"),k?n.push(" vec3 viewNormalVec = vec3(0.0, 1.0, 0.0);"):n.push(" vec3 viewNormalVec = normalize(SCENEJS_vViewNormal);"));var p;if(g){n.push(" vec4 texturePos;"),n.push(" vec2 textureCoord=vec2(0.0,0.0);");for(var o=0,q=c.texture.layers.length;q>o;o++){if(p=c.texture.layers[o],"normal"==p.applyFrom&&i){if(!c.geometry.normalBuf){SceneJS.log.warn("Texture layer applyFrom='normal' but geo has no normal vectors");continue}n.push("texturePos=vec4(viewNormalVec.xyz, 1.0);")}if("uv"==p.applyFrom){if(!c.geometry.uvBuf){SceneJS.log.warn("Texture layer applyTo='uv' but geometry has no UV coordinates");continue}n.push("texturePos = vec4(SCENEJS_vUVCoord.s, SCENEJS_vUVCoord.t, 1.0, 1.0);")}if("uv2"==p.applyFrom){if(!c.geometry.uvBuf2){SceneJS.log.warn("Texture layer applyTo='uv2' but geometry has no UV2 coordinates");continue}n.push("texturePos = vec4(SCENEJS_vUVCoord2.s, SCENEJS_vUVCoord2.t, 1.0, 1.0);")}p.matrix?n.push("textureCoord=(SCENEJS_uLayer"+o+"Matrix * texturePos).xy;"):n.push("textureCoord=texturePos.xy;"),"alpha"==p.applyTo&&("multiply"==p.blendMode?n.push("alpha = alpha * (SCENEJS_uLayer"+o+"BlendFactor * texture2D(SCENEJS_uSampler"+o+", vec2(textureCoord.x, 1.0 - textureCoord.y)).b);"):"add"==p.blendMode&&n.push("alpha = ((1.0 - SCENEJS_uLayer"+o+"BlendFactor) * alpha) + (SCENEJS_uLayer"+o+"BlendFactor * texture2D(SCENEJS_uSampler"+o+", vec2(textureCoord.x, 1.0 - textureCoord.y)).b);")),"baseColor"==p.applyTo&&("multiply"==p.blendMode?n.push("color = color * (SCENEJS_uLayer"+o+"BlendFactor * texture2D(SCENEJS_uSampler"+o+", vec2(textureCoord.x, 1.0 - textureCoord.y)).rgb);"):n.push("color = ((1.0 - SCENEJS_uLayer"+o+"BlendFactor) * color) + (SCENEJS_uLayer"+o+"BlendFactor * texture2D(SCENEJS_uSampler"+o+", vec2(textureCoord.x, 1.0 - textureCoord.y)).rgb);")),"emit"==p.applyTo&&("multiply"==p.blendMode?n.push("emit = emit * (SCENEJS_uLayer"+o+"BlendFactor * texture2D(SCENEJS_uSampler"+o+", vec2(textureCoord.x, 1.0 - textureCoord.y)).r);"):n.push("emit = ((1.0 - SCENEJS_uLayer"+o+"BlendFactor) * emit) + (SCENEJS_uLayer"+o+"BlendFactor * texture2D(SCENEJS_uSampler"+o+", vec2(textureCoord.x, 1.0 - textureCoord.y)).r);")),"specular"==p.applyTo&&i&&("multiply"==p.blendMode?n.push("specular = specular * (SCENEJS_uLayer"+o+"BlendFactor * texture2D(SCENEJS_uSampler"+o+", vec2(textureCoord.x, 1.0 - textureCoord.y)).r);"):n.push("specular = ((1.0 - SCENEJS_uLayer"+o+"BlendFactor) * specular) + (SCENEJS_uLayer"+o+"BlendFactor * texture2D(SCENEJS_uSampler"+o+", vec2(textureCoord.x, 1.0 - textureCoord.y)).r);")),"shine"==p.applyTo&&("multiply"==p.blendMode?n.push("shine = shine * (SCENEJS_uLayer"+o+"BlendFactor * texture2D(SCENEJS_uSampler"+o+", vec2(textureCoord.x, 1.0 - textureCoord.y)).r);"):n.push("shine = ((1.0 - SCENEJS_uLayer"+o+"BlendFactor) * shine) + (SCENEJS_uLayer"+o+"BlendFactor * texture2D(SCENEJS_uSampler"+o+", vec2(textureCoord.x, 1.0 - textureCoord.y)).r);")),"normals"==p.applyTo&&i&&n.push("viewNormalVec = normalize(texture2D(SCENEJS_uSampler"+o+", vec2(textureCoord.x, -textureCoord.y)).xyz * 2.0 - 1.0);")}}if(i&&h){n.push("vec3 envLookup = reflect(SCENEJS_vViewEyeVec, viewNormalVec);"),n.push("envLookup.y = envLookup.y * -1.0;"),n.push("vec4 envColor;");for(var o=0,q=c.cubemap.layers.length;q>o;o++)p=c.cubemap.layers[o],n.push("envColor = textureCube(SCENEJS_uCubeMapSampler"+o+", envLookup);"),n.push("color = mix(color, envColor.rgb, specular * SCENEJS_uCubeMapIntensity"+o+");")}if(n.push(" vec4 fragColor;"),i){n.push(" vec3 lightValue = vec3(0.0, 0.0, 0.0);"),n.push(" vec3 specularValue = vec3(0.0, 0.0, 0.0);"),n.push(" vec3 viewLightVec;"),n.push(" float dotN;"),n.push(" float lightDist;");for(var r,o=0,q=c.lights.lights.length;q>o;o++)r=c.lights.lights[o],"ambient"!=r.mode&&(n.push("viewLightVec = SCENEJS_vViewLightVecAndDist"+o+".xyz;"),"point"==r.mode&&(n.push("dotN = max(dot(normalize(viewNormalVec), normalize(viewLightVec)), 0.0);"),n.push("lightDist = SCENEJS_vViewLightVecAndDist"+o+".w;"),n.push("attenuation = 1.0 - ( SCENEJS_uLightAttenuation"+o+"[0] + SCENEJS_uLightAttenuation"+o+"[1] * lightDist + SCENEJS_uLightAttenuation"+o+"[2] * lightDist * lightDist);"),r.diffuse&&n.push(" lightValue += dotN * SCENEJS_uLightColor"+o+" * attenuation;"),r.specular&&n.push(" specularValue += specularColor * SCENEJS_uLightColor"+o+" * specular * pow(max(dot(reflect(normalize(-viewLightVec), normalize(-viewNormalVec)), normalize(-SCENEJS_vViewVertex.xyz)), 0.0), shine) * attenuation;")),"dir"==r.mode&&(n.push("dotN = max(dot(normalize(viewNormalVec), normalize(viewLightVec)), 0.0);"),r.diffuse&&n.push(" lightValue += dotN * SCENEJS_uLightColor"+o+";"),r.specular&&n.push("specularValue += specularColor * SCENEJS_uLightColor"+o+" * specular * pow(max(dot(reflect(normalize(-viewLightVec), normalize(-viewNormalVec)), normalize(-SCENEJS_vViewVertex.xyz)), 0.0), shine);")));n.push(" fragColor = vec4((specularValue.rgb + color.rgb * (lightValue.rgb + ambient.rgb)) + (emit * color.rgb), alpha);")}else n.push("fragColor = vec4((color.rgb + (emit * color.rgb)) * (vec3(1.0, 1.0, 1.0) + ambient.rgb), alpha);");return f.pixelColor&&n.push("fragColor="+f.pixelColor+"(fragColor);"),a(c)?(n.push(" if (SCENEJS_uDepthMode) {"),n.push(" float depth = length(SCENEJS_vViewVertex) / (SCENEJS_uZFar - SCENEJS_uZNear);"),n.push(" const vec4 bias = vec4(1.0 / 255.0,"),n.push(" 1.0 / 255.0,"),n.push(" 1.0 / 255.0,"),n.push(" 0.0);"),n.push(" float r = depth;"),n.push(" float g = fract(r * 255.0);"),n.push(" float b = fract(g * 255.0);"),n.push(" float a = fract(b * 255.0);"),n.push(" vec4 colour = vec4(r, g, b, a);"),n.push(" gl_FragColor = colour - (colour.yzww * bias);"),n.push(" } else {"),n.push(" gl_FragColor = fragColor;"),n.push(" };")):n.push(" gl_FragColor = fragColor;"),n.push("}"),n}},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.UINT_INDEX_ENABLED=!!d.getExtension("OES_element_index_uint"),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){this._freeObjects[this._numFreeObjects++]=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.ssaaMultiplier,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];if(g)return g.useCount++,g;var h=SceneJS_ChunkFactory._freeChunks[b];return h.chunksLen>0&&(g=h.chunks[--h.chunksLen]),g?g.init(a,c,d,e):g=new f(a,c,d,e),g.type=b,g.useCount=1,this._chunks[a]=g,g},SceneJS_ChunkFactory.prototype.putChunk=function(a){if(0!=a.useCount&&--a.useCount<=0){a.recycle&&a.recycle(),delete this._chunks[a.id];var b=SceneJS_ChunkFactory._freeChunks[a.type];b.chunks[b.chunksLen++]=a}},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.pick?this._pick:this._draw,f=this.core.clips,g=(this.program.gl,0),h=f.length;h>g;g++)a.pick?(b=e[g].uClipMode,c=e[g].uClipNormalAndDist):(b=e[g].uClipMode,c=e[g].uClipNormalAndDist),b&&c&&(d=f[g],"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._depthModePick=this.program.pick.getUniform("SCENEJS_uDepthMode")},drawAndPick:function(a){var b=this.program.gl,c=this.program.UINT_INDEX_ENABLED?b.UNSIGNED_INT:b.UNSIGNED_SHORT;a.pick?this._depthModePick&&this._depthModePick.setValue(a.depthMode):this._depthModeDraw&&this._depthModeDraw.setValue(a.depthMode),b.drawElements(this.core.primitive,this.core.indexBuf.numItems,c,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");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=this.core.transparent;a.transparent!=e&&(a.pick||(e?(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=e),a.pick?this._uClippingPick&&this._uClippingPick.setValue(this.core.clipping):(this._uClippingDraw&&this._uClippingDraw.setValue(this.core.clipping),this._uSolidDraw&&this._uSolidDraw.setValue(this.core.solid))}}),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._aVertexDraw=a.getAttribute("SCENEJS_aVertex"),this._aNormalDraw=a.getAttribute("SCENEJS_aNormal"),this._aUVDraw=a.getAttribute("SCENEJS_aUVCoord"),this._aUV2Draw=a.getAttribute("SCENEJS_aUVCoord2"),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._uMorphFactorDraw=a.getUniform("SCENEJS_uMorphFactor");var b=this.program.pick;this._aVertexPick=b.getAttribute("SCENEJS_aVertex"),this._aMorphVertexPick=b.getAttribute("SCENEJS_aMorphVertex"),this._uMorphFactorPick=b.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(){this.VAOMorphKey1=this.core.key1,this.VAOMorphKey2=this.core.key2;var a=this.core.targets[this.core.key1],b=this.core.targets[this.core.key2];this._aMorphVertexDraw?(this._aVertexDraw.bindFloatArrayBuffer(a.vertexBuf),this._aMorphVertexDraw.bindFloatArrayBuffer(b.vertexBuf)):this._aVertexDraw&&this._aVertexDraw.bindFloatArrayBuffer(this.core2.vertexBuf),this._aMorphNormalDraw?(this._aNormalDraw.bindFloatArrayBuffer(a.normalBuf),this._aMorphNormalDraw.bindFloatArrayBuffer(b.normalBuf)):this._aNormalDraw&&this._aNormalDraw.bindFloatArrayBuffer(this.core2.normalBuf),this._aUVDraw&&this._aUVDraw.bindFloatArrayBuffer(this.core2.uvBuf),this._aUV2Draw&&this._aUV2Draw.bindFloatArrayBuffer(this.core2.uvBuf2),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){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 if(a.VAO){a.VAO.bindVertexArrayOES(null),this.VAO=a.VAO.createVertexArrayOES(),a.VAO.bindVertexArrayOES(this.VAO);this.program.gl}b?this.morphDraw():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),this._aUVDraw&&this._aUVDraw.bindInterleavedFloatArrayBuffer(2,this.core2.interleavedStride,this.core2.interleavedUVOffset),this._aUV2Draw&&this._aUV2Draw.bindInterleavedFloatArrayBuffer(2,this.core2.interleavedStride,this.core2.interleavedUV2Offset),this._aColorDraw&&this._aColorDraw.bindInterleavedFloatArrayBuffer(4,this.core2.interleavedStride,this.core2.interleavedColorOffset),this._aTangentDraw&&this._aTangentDraw.bindFloatArrayBuffer(this.core2.tangentBuf||this.core2.getTangentBuf())):(this.VAOHasInterleavedBuf=!1,this._aVertexDraw&&this._aVertexDraw.bindFloatArrayBuffer(this.core2.vertexBuf),this._aNormalDraw&&this._aNormalDraw.bindFloatArrayBuffer(this.core2.normalBuf),this._aUVDraw&&this._aUVDraw.bindFloatArrayBuffer(this.core2.uvBuf),this._aUV2Draw&&this._aUV2Draw.bindFloatArrayBuffer(this.core2.uvBuf2),this._aColorDraw&&this._aColorDraw.bindFloatArrayBuffer(this.core2.colorBuf),this._aTangentDraw&&this._aTangentDraw.bindFloatArrayBuffer(this.core2.tangentBuf||this.core2.getTangentBuf())),this.core2.indexBuf.bind()},morphPick:function(){var a=this.core.targets[this.core.key1],b=this.core.targets[this.core.key2];this._aMorphVertexPick?(this._aVertexPick.bindFloatArrayBuffer(a.vertexBuf),this._aMorphVertexPick.bindFloatArrayBuffer(b.vertexBuf)):this._aVertexPick&&this._aVertexPick.bindFloatArrayBuffer(this.core2.vertexBuf),this._uMorphFactorPick&&this._uMorphFactorPick.setValue(this.core.factor)},pick:function(a){this.core.targets&&this.core.targets.length?this.morphPick():this._aVertexPick&&this._aVertexPick.bindFloatArrayBuffer(this.core2.vertexBuf),this.core2.indexBuf.bind()}}),SceneJS_ChunkFactory.createChunkType({type:"lights",build:function(){this._uAmbientColor=this._uAmbientColor||[],this._uLightColor=this._uLightColor||[],this._uLightDir=this._uLightDir||[],this._uLightPos=this._uLightPos||[],this._uLightCutOff=this._uLightCutOff||[],this._uLightSpotExp=this._uLightSpotExp||[],this._uLightAttenuation=this._uLightAttenuation||[];for(var a=this.core.lights,b=this.program,c=0,d=a.length;d>c;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._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._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:"name",build:function(){this._uPickColor=this.program.pick.getUniform("SCENEJS_uPickColor")},pick:function(a){if(this._uPickColor&&this.core.name){a.pickNames[a.pickIndex++]=this.core;var b=a.pickIndex>>16&255,c=a.pickIndex>>8&255,d=255&a.pickIndex;this._uPickColor.setValue([d/255,c/255,b/255])}}}),SceneJS_ChunkFactory.createChunkType({type:"program",build:function(){this._depthModeDraw=this.program.draw.getUniform("SCENEJS_uDepthMode"),this._depthModePick=this.program.pick.getUniform("SCENEJS_uDepthMode"),this._rayPickMode=this.program.pick.getUniform("SCENEJS_uRayPickMode")},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;this._rayPickMode&&this._rayPickMode.setValue(a.rayPick),this._depthModePick&&this._depthModePick.setValue(a.depthMode),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:"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.pick?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.pick?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;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++),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));a.textureUnit>10&&(a.textureUnit=0)}}),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++),this._uCubeMapIntensity[e]&&this._uCubeMapIntensity[e].setValue(c.intensity));a.textureUnit>10&&(a.textureUnit=0)}}),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 diff --git a/build/4.2.0/scenejs-4.2.0.js b/build/4.2.0/scenejs-4.2.0.js index 4bebfd82..39e3598e 100644 --- a/build/4.2.0/scenejs-4.2.0.js +++ b/build/4.2.0/scenejs-4.2.0.js @@ -4,7 +4,7 @@ * A WebGL-based 3D scene graph from xeoLabs * http://scenejs.org/ * - * Built on 2015-06-03 + * Built on 2015-06-11 * * MIT License * Copyright 2015, Lindsay Kay @@ -5830,85 +5830,159 @@ SceneJS._webgl.nextHighestPowerOfTwo = function (x) { return x + 1; }; -; -SceneJS._webgl.Uniform = function (gl, program, name, type, size, location, index, logging) { +;SceneJS._webgl.Uniform = function (gl, program, name, type, size, location, index, logging) { var func = null; - this.numberValue = false; - if (type == gl.BOOL) { - this.numberValue = true; + + var value = null; + + if (type === gl.BOOL) { + func = function (v) { + if (value === v) { + return; + } + value = v; gl.uniform1i(location, v); }; - } else if (type == gl.BOOL_VEC2) { + + } else if (type === gl.BOOL_VEC2) { + func = function (v) { + if (value !== null && value[0] === v[0] && value[1] === v[1]) { + return; + } + value = v; gl.uniform2iv(location, v); }; - } else if (type == gl.BOOL_VEC3) { + + } else if (type === gl.BOOL_VEC3) { + func = function (v) { + if (value !== null && value[0] === v[0] && value[1] === v[1] && value[2] === v[2]) { + return; + } + value = v; gl.uniform3iv(location, v); }; - } else if (type == gl.BOOL_VEC4) { + + } else if (type === gl.BOOL_VEC4) { + func = function (v) { + if (value !== null && value[0] === v[0] && value[1] === v[1] && value[2] === v[2] && value[3] === v[3]) { + return; + } + value = v; gl.uniform4iv(location, v); }; - } else if (type == gl.INT) { - this.numberValue = true; + + } else if (type === gl.INT) { + func = function (v) { + if (value === v) { + return; + } + value = v; gl.uniform1iv(location, v); }; - } else if (type == gl.INT_VEC2) { + + } else if (type === gl.INT_VEC2) { + func = function (v) { + if (value !== null && value[0] === v[0] && value[1] === v[1]) { + return; + } + value = v; gl.uniform2iv(location, v); }; - } else if (type == gl.INT_VEC3) { + + } else if (type === gl.INT_VEC3) { + func = function (v) { + if (value !== null && value[0] === v[0] && value[1] === v[1] && value[2] === v[2]) { + return; + } + value = v; gl.uniform3iv(location, v); }; - } else if (type == gl.INT_VEC4) { + + } else if (type === gl.INT_VEC4) { + func = function (v) { + if (value !== null && value[0] === v[0] && value[1] === v[1] && value[2] === v[2] && value[3] === v[3]) { + return; + } + value = v; gl.uniform4iv(location, v); }; - } else if (type == gl.FLOAT) { - this.numberValue = true; + + } else if (type === gl.FLOAT) { + func = function (v) { + if (value === v) { + return; + } + value = v; gl.uniform1f(location, v); }; - } else if (type == gl.FLOAT_VEC2) { + + } else if (type === gl.FLOAT_VEC2) { + func = function (v) { + if (value !== null && value[0] === v[0] && value[1] === v[1]) { + return; + } + value = v; gl.uniform2fv(location, v); }; - } else if (type == gl.FLOAT_VEC3) { + + } else if (type === gl.FLOAT_VEC3) { + func = function (v) { + if (value !== null && value[0] === v[0] && value[1] === v[1] && value[2] === v[2]) { + return; + } + value = v; gl.uniform3fv(location, v); }; - } else if (type == gl.FLOAT_VEC4) { + + } else if (type === gl.FLOAT_VEC4) { + func = function (v) { + if (value !== null && value[0] === v[0] && value[1] === v[1] && value[2] === v[2] && value[3] === v[3]) { + return; + } + value = v; gl.uniform4fv(location, v); }; - } else if (type == gl.FLOAT_MAT2) { + + } else if (type === gl.FLOAT_MAT2) { + func = function (v) { gl.uniformMatrix2fv(location, gl.FALSE, v); }; - } else if (type == gl.FLOAT_MAT3) { + + } else if (type === gl.FLOAT_MAT3) { + func = function (v) { gl.uniformMatrix3fv(location, gl.FALSE, v); }; - } else if (type == gl.FLOAT_MAT4) { + + } else if (type === gl.FLOAT_MAT4) { + func = function (v) { + + // Caching this matrix is actually slower than not caching + gl.uniformMatrix4fv(location, gl.FALSE, v); }; + } else { throw "Unsupported shader uniform type: " + type; } this.setValue = func; - - this.getValue = function () { - return gl.getUniform(program, location); - }; - this.getLocation = function () { return location; }; @@ -8170,7 +8244,8 @@ SceneJS_NodeFactory.prototype.putNode = function (node) { backfaces: true, // Show backfaces frontface: "ccw", // Default vertex winding for front face reflective: true, // Reflects reflection node cubemap, if it exists, by default. - hash: "refl" + solid: false, // When true, renders backfaces without texture or shading, for a cheap solid cross-section effect + hash: "refl;;" }; var coreStack = []; @@ -8200,7 +8275,8 @@ SceneJS_NodeFactory.prototype.putNode = function (node) { this._core.backfaces = true; // Show backfaces this._core.frontface = "ccw"; // Default vertex winding for front face this._core.reflective = true; // Reflects reflection node cubemap, if it exists, by default. - if (params.flags) { // 'flags' property is actually optional in the node definition + this._core.solid = false; // Renders backfaces without texture or shading, for a cheap solid cross-section effect + if (params.flags) { // 'flags' property is actually optional in the node definition this.setFlags(params.flags); } } @@ -8246,6 +8322,14 @@ SceneJS_NodeFactory.prototype.putNode = function (node) { this._engine.branchDirty(this); this._engine.display.imageDirty = true; } + + if (flags.solid != undefined) { + core.solid = flags.solid; + core.hash = core.reflective ? "refl" : ""; + this._engine.branchDirty(this); + this._engine.display.imageDirty = true; + } + return this; }; @@ -8272,7 +8356,8 @@ SceneJS_NodeFactory.prototype.putNode = function (node) { transparent: core.transparent, backfaces: core.backfaces, frontface: core.frontface, - reflective: core.reflective + reflective: core.reflective, + solid: core.solid }; }; @@ -8357,7 +8442,7 @@ SceneJS_NodeFactory.prototype.putNode = function (node) { reflective = !!reflective; if (this._core.reflective != reflective) { this._core.reflective = reflective; - this._core.hash = reflective ? "refl" : ""; + this._core.hash = (reflective ? "refl" : "") + this._core.solid ? ";s" : ";;"; this._engine.branchDirty(this); this._engine.display.imageDirty = true; } @@ -8368,6 +8453,22 @@ SceneJS_NodeFactory.prototype.putNode = function (node) { return this._core.reflective; }; + SceneJS.Flags.prototype.setSolid = function(solid) { + solid = !!solid; + if (this._core.solid != solid) { + this._core.solid = solid; + this._core.hash = (this._core.reflective ? "refl" : "") + solid ? ";s;" : ";;"; + this._engine.branchDirty(this); + this._engine.display.imageDirty = true; + } + return this; + }; + + SceneJS.Flags.prototype.getSolid = function() { + return this._core.solid; + }; + + SceneJS.Flags.prototype._compile = function(ctx) { this._engine.display.flags = coreStack[stackLen++] = this._core; this._compileNodes(ctx); @@ -10575,6 +10676,8 @@ new (function () { */ core.factor = (factor - keys[key1]) / (keys[key2] - keys[key1]); + this._factor = factor; + var morphUpdate = frameUpdate || oldFactor != core.factor; core.key1 = key1; @@ -10592,7 +10695,7 @@ new (function () { }; SceneJS.MorphGeometry.prototype.getFactor = function () { - return this._core.factor; + return this._factor; }; SceneJS.MorphGeometry.prototype.getKeys = function () { @@ -15504,7 +15607,6 @@ SceneJS_Display.prototype._doDrawList = function (params) { var VAO = gl.getExtension("OES_vertex_array_object"); frameCtx.VAO = (VAO) ? VAO : null; - frameCtx.VAO = null; gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight); @@ -15566,7 +15668,6 @@ var SceneJS_ProgramSourceFactory = new (function () { this._sourceCache = {}; // Source codes are shared across all scenes - /** * Get sourcecode for a program to render the given states */ @@ -15603,9 +15704,6 @@ var SceneJS_ProgramSourceFactory = new (function () { this._composePickingVertexShader = function (states) { var morphing = !!states.morphGeometry.targets; var src = [ - - "precision mediump float;", - "attribute vec3 SCENEJS_aVertex;", "uniform mat4 SCENEJS_uMMatrix;", "uniform mat4 SCENEJS_uVMatrix;", @@ -15648,8 +15746,10 @@ var SceneJS_ProgramSourceFactory = new (function () { var clipping = states.clips.clips.length > 0; + var floatPrecision = getFSFloatPrecision(states._canvas.gl); + var src = [ - "precision mediump float;" + "precision " + floatPrecision + " float;" ]; src.push("varying vec4 SCENEJS_vWorldVertex;"); @@ -15770,9 +15870,7 @@ var SceneJS_ProgramSourceFactory = new (function () { var clipping = states.clips.clips.length > 0; var morphing = !!states.morphGeometry.targets; - var src = [ - "precision mediump float;" - ]; + var src = []; src.push("uniform mat4 SCENEJS_uMMatrix;"); // Model matrix src.push("uniform mat4 SCENEJS_uVMatrix;"); // View matrix @@ -16066,12 +16164,15 @@ var SceneJS_ProgramSourceFactory = new (function () { var texturing = this._isTexturing(states); var cubeMapping = this._isCubeMapping(states); var normals = this._hasNormals(states); + var solid = states.flags.solid; var tangents = this._hasTangents(states); var clipping = states.clips.clips.length > 0; + var floatPrecision = getFSFloatPrecision(states._canvas.gl); + var src = ["\n"]; - src.push("precision mediump float;"); + src.push("precision " + floatPrecision + " float;"); if (clipping) { @@ -16124,10 +16225,13 @@ var SceneJS_ProgramSourceFactory = new (function () { } } - /* True when lighting - */ + // True when lighting src.push("uniform bool SCENEJS_uClipping;"); + // True when interior surfaces of solid cross-sections + // are to be rendered without texture and shading + src.push("uniform bool SCENEJS_uSolid;"); + // Added in v4.0 to support depth targets src.push("uniform bool SCENEJS_uDepthMode;"); @@ -16190,6 +16294,18 @@ var SceneJS_ProgramSourceFactory = new (function () { src.push("}"); } + if (normals) { + + if (solid) { + + src.push(" float a = dot(normalize(SCENEJS_vViewNormal), normalize(SCENEJS_vViewEyeVec));"); + src.push(" if (a < 0.0) {"); + src.push(" gl_FragColor = vec4(0.4, 0.4, 1.0, 1.0);"); + src.push(" return;"); + src.push(" }"); + } + } + src.push(" vec3 ambient= SCENEJS_uAmbientColor;"); if (texturing && states.geometry.uvBuf && fragmentHooks.texturePos) { @@ -16466,6 +16582,22 @@ var SceneJS_ProgramSourceFactory = new (function () { return false; } + function getFSFloatPrecision(gl) { + if (!gl.getShaderPrecisionFormat) { + return "mediump"; + } + + if (gl.getShaderPrecisionFormat(gl.FRAGMENT_SHADER, gl.HIGH_FLOAT).precision > 0) { + return "highp"; + } + + if (gl.getShaderPrecisionFormat(gl.FRAGMENT_SHADER, gl.MEDIUM_FLOAT).precision > 0) { + return "mediump"; + } + + return "lowp"; + } + })();;/** * @class Source code for pick and draw shader programs, to be compiled into one or more {@link SceneJS_Program}s * @private @@ -16655,11 +16787,6 @@ var SceneJS_Program = function(id, hash, source, gl) { * This is also re-called to re-create them after WebGL context loss. */ SceneJS_Program.prototype.build = function(gl) { - /** - * Current draw uniform state cached as a bitfield to avoid costly extra uniform1i calls - * @type Number - */ - this.drawUniformFlags = 0; this.gl = gl; this.draw = new SceneJS._webgl.Program(gl, [this.source.drawVertexSrc.join("\n")], [this.source.drawFragmentSrc.join("\n")]); @@ -17046,13 +17173,13 @@ SceneJS_ChunkFactory.prototype.webglRestored = function () { build : function() { - this._uPMatrixDraw = this.program.draw.getUniformLocation("SCENEJS_uPMatrix"); - this._uZNearDraw = this.program.draw.getUniformLocation("SCENEJS_uZNear"); - this._uZFarDraw = this.program.draw.getUniformLocation("SCENEJS_uZFar"); + 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.getUniformLocation("SCENEJS_uPMatrix"); - this._uZNearPick = this.program.pick.getUniformLocation("SCENEJS_uZNear"); - this._uZFarPick = this.program.pick.getUniformLocation("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(frameCtx) { @@ -17064,15 +17191,15 @@ SceneJS_ChunkFactory.prototype.webglRestored = function () { var gl = this.program.gl; if (this._uPMatrixDraw) { - gl.uniformMatrix4fv(this._uPMatrixDraw, gl.FALSE, this.core.mat); + this._uPMatrixDraw.setValue(this.core.mat); } if (this._uZNearDraw) { - gl.uniform1f(this._uZNearDraw, this.core.optics.near); + this._uZNearDraw.setValue(this.core.optics.near); } if (this._uZFarDraw) { - gl.uniform1f(this._uZFarDraw, this.core.optics.far); + this._uZFarDraw.setValue(this.core.optics.far); } frameCtx.cameraMat = this.core.mat; // Query only in draw pass @@ -17088,17 +17215,17 @@ SceneJS_ChunkFactory.prototype.webglRestored = function () { var gl = this.program.gl; if (this._uPMatrixPick) { - gl.uniformMatrix4fv(this._uPMatrixPick, gl.FALSE, this.core.mat); + this._uPMatrixPick.setValue(this.core.mat); } if (frameCtx.rayPick) { // Z-pick pass: feed near and far clip planes into shader if (this._uZNearPick) { - gl.uniform1f(this._uZNearPick, this.core.optics.near); + this._uZNearPick.setValue(this.core.optics.near); } if (this._uZFarPick) { - gl.uniform1f(this._uZFarPick, this.core.optics.far); + this._uZFarPick.setValue(this.core.optics.far); } } @@ -17119,8 +17246,8 @@ SceneJS_ChunkFactory.createChunkType({ for (var i = 0, len = this.core.clips.length; i < len; i++) { this._draw[i] = { - uClipMode :draw.getUniformLocation("SCENEJS_uClipMode" + i), - uClipNormalAndDist: draw.getUniformLocation("SCENEJS_uClipNormalAndDist" + i) + uClipMode :draw.getUniform("SCENEJS_uClipMode" + i), + uClipNormalAndDist: draw.getUniform("SCENEJS_uClipNormalAndDist" + i) }; } @@ -17130,8 +17257,8 @@ SceneJS_ChunkFactory.createChunkType({ for (var i = 0, len = this.core.clips.length; i < len; i++) { this._pick[i] = { - uClipMode :pick.getUniformLocation("SCENEJS_uClipMode" + i), - uClipNormalAndDist: pick.getUniformLocation("SCENEJS_uClipNormalAndDist" + i) + uClipMode :pick.getUniform("SCENEJS_uClipMode" + i), + uClipNormalAndDist: pick.getUniform("SCENEJS_uClipNormalAndDist" + i) }; } }, @@ -17162,16 +17289,16 @@ SceneJS_ChunkFactory.createChunkType({ if (clip.mode == "inside") { - gl.uniform1f(mode, 2); - gl.uniform4fv(normalAndDist, clip.normalAndDist); + mode.setValue(2); + normalAndDist.setValue(clip.normalAndDist); } else if (clip.mode == "outside") { - gl.uniform1f(mode, 1); - gl.uniform4fv(normalAndDist, clip.normalAndDist); + mode.setValue(1); + normalAndDist.setValue(clip.normalAndDist); } else { // disabled - gl.uniform1f(mode, 0); + mode.setValue(0); } } } @@ -17181,7 +17308,7 @@ SceneJS_ChunkFactory.createChunkType({ */ SceneJS_ChunkFactory.createChunkType({ - type:"draw", + type: "draw", /** * As we apply a list of state chunks in a {@link SceneJS_Display}, we track the ID of each chunk @@ -17190,18 +17317,31 @@ SceneJS_ChunkFactory.createChunkType({ * We don't want that for draw chunks however, because they contain GL drawElements calls, * which we need to do for each object. */ - unique:true, + unique: true, - build:function () { - this._depthModeDraw = this.program.draw.getUniformLocation("SCENEJS_uDepthMode"); - this._depthModePick = this.program.pick.getUniformLocation("SCENEJS_uDepthMode"); + build: function () { + this._depthModeDraw = this.program.draw.getUniform("SCENEJS_uDepthMode"); + this._depthModePick = this.program.pick.getUniform("SCENEJS_uDepthMode"); }, - drawAndPick:function (frameCtx) { + drawAndPick: function (frameCtx) { + var gl = this.program.gl; + var indexType = this.program.UINT_INDEX_ENABLED ? gl.UNSIGNED_INT : gl.UNSIGNED_SHORT; - gl.uniform1i(frameCtx.pick ? this._depthModePick : this._depthModeDraw, frameCtx.depthMode); + + if (frameCtx.pick) { + if (this._depthModePick) { + this._depthModePick.setValue(frameCtx.depthMode); + } + } else { + if (this._depthModeDraw) { + this._depthModeDraw.setValue(frameCtx.depthMode); + } + } + gl.drawElements(this.core.primitive, this.core.indexBuf.numItems, indexType, 0); + //frameCtx.textureUnit = 0; } }); @@ -17216,11 +17356,12 @@ SceneJS_ChunkFactory.createChunkType({ var draw = this.program.draw; - this._uClippingDraw = draw.getUniformLocation("SCENEJS_uClipping"); + this._uClippingDraw = draw.getUniform("SCENEJS_uClipping"); + this._uSolidDraw = draw.getUniform("SCENEJS_uSolid"); var pick = this.program.pick; - this._uClippingPick = pick.getUniformLocation("SCENEJS_uClipping"); + this._uClippingPick = pick.getUniform("SCENEJS_uClipping"); }, drawAndPick: function (frameCtx) { @@ -17273,13 +17414,19 @@ SceneJS_ChunkFactory.createChunkType({ } if (frameCtx.pick) { - gl.uniform1i(this._uClippingPick, this.core.clipping); + + if (this._uClippingPick) { + this._uClippingPick.setValue(this.core.clipping); + } } else { - var drawUniforms = (this.core.clipping ? 1 : 0); - if (this.program.drawUniformFlags != drawUniforms) { - gl.uniform1i(this._uClippingDraw, this.core.clipping); - this.program.drawUniformFlags = drawUniforms; + + if (this._uClippingDraw) { + this._uClippingDraw.setValue(this.core.clipping); + } + + if (this._uSolidDraw) { + this._uSolidDraw.setValue(this.core.solid); } } } @@ -17353,13 +17500,13 @@ SceneJS_ChunkFactory.createChunkType({ this._aMorphVertexDraw = draw.getAttribute("SCENEJS_aMorphVertex"); this._aMorphNormalDraw = draw.getAttribute("SCENEJS_aMorphNormal"); - this._uMorphFactorDraw = draw.getUniformLocation("SCENEJS_uMorphFactor"); + this._uMorphFactorDraw = draw.getUniform("SCENEJS_uMorphFactor"); var pick = this.program.pick; this._aVertexPick = pick.getAttribute("SCENEJS_aVertex"); this._aMorphVertexPick = pick.getAttribute("SCENEJS_aMorphVertex"); - this._uMorphFactorPick = pick.getUniformLocation("SCENEJS_uMorphFactor"); + this._uMorphFactorPick = pick.getUniform("SCENEJS_uMorphFactor"); this.VAO = null; this.VAOMorphKey1 = 0; @@ -17415,7 +17562,7 @@ SceneJS_ChunkFactory.createChunkType({ setDrawMorphFactor:function () { if (this._uMorphFactorDraw) { - this.program.gl.uniform1f(this._uMorphFactorDraw, this.core.factor); // Bind LERP factor + this._uMorphFactorDraw.setValue*(this.core.factor); // Bind LERP factor } }, @@ -17511,7 +17658,7 @@ SceneJS_ChunkFactory.createChunkType({ } if (this._uMorphFactorPick) { - this.program.gl.uniform1f(this._uMorphFactorPick, this.core.factor); // Bind LERP factor + this._uMorphFactorPick.setValue(this.core.factor); // Bind LERP factor } }, @@ -17556,20 +17703,20 @@ SceneJS_ChunkFactory.createChunkType({ switch (lights[i].mode) { case "ambient": - this._uAmbientColor[i] = (program.draw.getUniformLocation("SCENEJS_uAmbientColor")); + this._uAmbientColor[i] = (program.draw.getUniform("SCENEJS_uAmbientColor")); break; case "dir": - this._uLightColor[i] = program.draw.getUniformLocation("SCENEJS_uLightColor" + i); + this._uLightColor[i] = program.draw.getUniform("SCENEJS_uLightColor" + i); this._uLightPos[i] = null; - this._uLightDir[i] = program.draw.getUniformLocation("SCENEJS_uLightDir" + i); + this._uLightDir[i] = program.draw.getUniform("SCENEJS_uLightDir" + i); break; case "point": - this._uLightColor[i] = program.draw.getUniformLocation("SCENEJS_uLightColor" + i); - this._uLightPos[i] = program.draw.getUniformLocation("SCENEJS_uLightPos" + i); + this._uLightColor[i] = program.draw.getUniform("SCENEJS_uLightColor" + i); + this._uLightPos[i] = program.draw.getUniform("SCENEJS_uLightPos" + i); this._uLightDir[i] = null; - this._uLightAttenuation[i] = program.draw.getUniformLocation("SCENEJS_uLightAttenuation" + i); + this._uLightAttenuation[i] = program.draw.getUniform("SCENEJS_uLightAttenuation" + i); break; } } @@ -17591,24 +17738,24 @@ SceneJS_ChunkFactory.createChunkType({ light = lights[i]; if (this._uAmbientColor[i]) { - gl.uniform3fv(this._uAmbientColor[i], light.color); + this._uAmbientColor[i].setValue(light.color); } else { if (this._uLightColor[i]) { - gl.uniform3fv(this._uLightColor[i], light.color); + this._uLightColor[i].setValue(light.color); } if (this._uLightPos[i]) { - gl.uniform3fv(this._uLightPos[i], light.pos); + this._uLightPos[i].setValue(light.pos); if (this._uLightAttenuation[i]) { - gl.uniform3fv(this._uLightAttenuation[i], light.attenuation); + this._uLightAttenuation[i].setValue(light.attenuation); } } if (this._uLightDir[i]) { - gl.uniform3fv(this._uLightDir[i], light.dir); + this._uLightDir[i].setValue(light.dir); } } } @@ -17646,11 +17793,11 @@ SceneJS_ChunkFactory.createChunkType({ build : function() { - this._uvMatrixDraw = this.program.draw.getUniformLocation("SCENEJS_uVMatrix"); - this._uVNMatrixDraw = this.program.draw.getUniformLocation("SCENEJS_uVNMatrix"); - this._uWorldEyeDraw = this.program.draw.getUniformLocation("SCENEJS_uWorldEye"); + 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.getUniformLocation("SCENEJS_uVMatrix"); + this._uvMatrixPick = this.program.pick.getUniform("SCENEJS_uVMatrix"); }, draw : function(frameCtx) { @@ -17662,15 +17809,15 @@ SceneJS_ChunkFactory.createChunkType({ var gl = this.program.gl; if (this._uvMatrixDraw) { - gl.uniformMatrix4fv(this._uvMatrixDraw, gl.FALSE, this.core.mat); + this._uvMatrixDraw.setValue(this.core.mat); } if (this._uVNMatrixDraw) { - gl.uniformMatrix4fv(this._uVNMatrixDraw, gl.FALSE, this.core.normalMat); + this._uVNMatrixDraw.setValue(this.core.normalMat); } if (this._uWorldEyeDraw) { - gl.uniform3fv(this._uWorldEyeDraw, this.core.lookAt.eye); + this._uWorldEyeDraw.setValue(this.core.lookAt.eye); } frameCtx.viewMat = this.core.mat; @@ -17681,7 +17828,7 @@ SceneJS_ChunkFactory.createChunkType({ var gl = this.program.gl; if (this._uvMatrixPick) { - gl.uniformMatrix4fv(this._uvMatrixPick, gl.FALSE, this.core.mat); + this._uvMatrixPick.setValue(this.core.mat); } frameCtx.viewMat = this.core.mat; @@ -17693,55 +17840,44 @@ SceneJS_ChunkFactory.createChunkType({ type: "material", - build : function() { + build: function () { var draw = this.program.draw; - this._uMaterialBaseColor = draw.getUniformLocation("SCENEJS_uMaterialColor"); - this._uMaterialSpecularColor = draw.getUniformLocation("SCENEJS_uMaterialSpecularColor"); - this._uMaterialSpecular = draw.getUniformLocation("SCENEJS_uMaterialSpecular"); - this._uMaterialShine = draw.getUniformLocation("SCENEJS_uMaterialShine"); - this._uMaterialEmit = draw.getUniformLocation("SCENEJS_uMaterialEmit"); - this._uMaterialAlpha = draw.getUniformLocation("SCENEJS_uMaterialAlpha"); + this._uMaterialBaseColor = draw.getUniform("SCENEJS_uMaterialColor"); + this._uMaterialSpecularColor = draw.getUniform("SCENEJS_uMaterialSpecularColor"); + this._uMaterialSpecular = draw.getUniform("SCENEJS_uMaterialSpecular"); + this._uMaterialShine = draw.getUniform("SCENEJS_uMaterialShine"); + this._uMaterialEmit = draw.getUniform("SCENEJS_uMaterialEmit"); + this._uMaterialAlpha = draw.getUniform("SCENEJS_uMaterialAlpha"); }, - draw : function() { + draw: function () { var gl = this.program.gl; - var materialSettings = this.program.draw.materialSettings; if (this._uMaterialBaseColor) { - gl.uniform3fv(this._uMaterialBaseColor, this.core.baseColor); + this._uMaterialBaseColor.setValue(this.core.baseColor); } - if (this._uMaterialSpecularColor && - (materialSettings.specularColor[0] != this.core.specularColor[0] || - materialSettings.specularColor[1] != this.core.specularColor[1] || - materialSettings.specularColor[2] != this.core.specularColor[2])) { - gl.uniform3fv(this._uMaterialSpecularColor, this.core.specularColor); - materialSettings.specularColor[0] = this.core.specularColor[0]; - materialSettings.specularColor[1] = this.core.specularColor[1]; - materialSettings.specularColor[2] = this.core.specularColor[2]; + if (this._uMaterialSpecularColor) { + this._uMaterialSpecularColor.setValue(this.core.specularColor); } - if (this._uMaterialSpecular && materialSettings.specular != this.core.specular) { - gl.uniform1f(this._uMaterialSpecular, this.core.specular); - materialSettings.specular = this.core.specular; + if (this._uMaterialSpecular) { + this._uMaterialSpecular.setValue(this.core.specular); } - if (this._uMaterialShine && materialSettings.shine != this.core.shine) { - gl.uniform1f(this._uMaterialShine, this.core.shine); - materialSettings.shine = this.core.shine; + if (this._uMaterialShine) { + this._uMaterialShine.setValue(this.core.shine); } - if (this._uMaterialEmit && materialSettings.emit != this.core.emit) { - gl.uniform1f(this._uMaterialEmit, this.core.emit); - materialSettings.emit = this.core.emit; + if (this._uMaterialEmit) { + this._uMaterialEmit.setValue(this.core.emit); } - if (this._uMaterialAlpha && materialSettings.alpha != this.core.alpha) { - gl.uniform1f(this._uMaterialAlpha, this.core.alpha); - materialSettings.alpha = this.core.alpha; + if (this._uMaterialAlpha) { + this._uMaterialAlpha.setValue(this.core.alpha); } } }); @@ -17752,11 +17888,11 @@ SceneJS_ChunkFactory.createChunkType({ type: "name", - build : function() { - this._uPickColor = this.program.pick.getUniformLocation("SCENEJS_uPickColor"); + build: function () { + this._uPickColor = this.program.pick.getUniform("SCENEJS_uPickColor"); }, - pick : function(frameCtx) { + pick: function (frameCtx) { if (this._uPickColor && this.core.name) { @@ -17766,7 +17902,7 @@ SceneJS_ChunkFactory.createChunkType({ var g = frameCtx.pickIndex >> 8 & 0xFF; var r = frameCtx.pickIndex & 0xFF; - this.program.gl.uniform3fv(this._uPickColor, [r / 255, g / 255, b / 255]); + this._uPickColor.setValue([r / 255, g / 255, b / 255]); } } });;SceneJS_ChunkFactory.createChunkType({ @@ -17776,9 +17912,9 @@ SceneJS_ChunkFactory.createChunkType({ build : function() { // Note that "program" chunks are always after "renderTarget" chunks - this._depthModeDraw = this.program.draw.getUniformLocation("SCENEJS_uDepthMode"); - this._depthModePick = this.program.pick.getUniformLocation("SCENEJS_uDepthMode"); - this._rayPickMode = this.program.pick.getUniformLocation("SCENEJS_uRayPickMode"); + this._depthModeDraw = this.program.draw.getUniform("SCENEJS_uDepthMode"); + this._depthModePick = this.program.pick.getUniform("SCENEJS_uDepthMode"); + this._rayPickMode = this.program.pick.getUniform("SCENEJS_uRayPickMode"); }, draw : function(frameCtx) { @@ -17786,7 +17922,9 @@ SceneJS_ChunkFactory.createChunkType({ drawProgram.bind(); frameCtx.textureUnit = 0; var gl = this.program.gl; - gl.uniform1i(this._depthModeDraw, frameCtx.depthMode); + if (this._depthModeDraw) { + this._depthModeDraw.setValue(frameCtx.depthMode); + } if (!frameCtx.VAO) { for (var i = 0; i < 10; i++) { gl.disableVertexAttribArray(i); @@ -17800,8 +17938,12 @@ SceneJS_ChunkFactory.createChunkType({ var pickProgram = this.program.pick; pickProgram.bind(); var gl = this.program.gl; - gl.uniform1i(this._rayPickMode, frameCtx.rayPick); - gl.uniform1i(this._depthModePick, frameCtx.depthMode); + if (this._rayPickMode) { + this._rayPickMode.setValue(frameCtx.rayPick); + } + if (this._depthModePick) { + this._depthModePick.setValue(frameCtx.depthMode); + } frameCtx.textureUnit = 0; for (var i = 0; i < 10; i++) { gl.disableVertexAttribArray(i); @@ -18135,19 +18277,19 @@ SceneJS_ChunkFactory.createChunkType({ type: "xform", - build : function() { + build: function () { var draw = this.program.draw; - this._uMatLocationDraw = draw.getUniformLocation("SCENEJS_uMMatrix"); - this._uNormalMatLocationDraw = draw.getUniformLocation("SCENEJS_uMNMatrix"); + this._uMatLocationDraw = draw.getUniform("SCENEJS_uMMatrix"); + this._uNormalMatLocationDraw = draw.getUniform("SCENEJS_uMNMatrix"); var pick = this.program.pick; - this._uMatLocationPick = pick.getUniformLocation("SCENEJS_uMMatrix"); + this._uMatLocationPick = pick.getUniform("SCENEJS_uMMatrix"); }, - draw : function(frameCtx) { + draw: function (frameCtx) { /* Rebuild core's matrix from matrices at cores on path up to root */ @@ -18158,17 +18300,17 @@ SceneJS_ChunkFactory.createChunkType({ var gl = this.program.gl; if (this._uMatLocationDraw) { - gl.uniformMatrix4fv(this._uMatLocationDraw, gl.FALSE, this.core.mat); + this._uMatLocationDraw.setValue(this.core.mat); } if (this._uNormalMatLocationDraw) { - gl.uniformMatrix4fv(this._uNormalMatLocationDraw, gl.FALSE, this.core.normalMat); + this._uNormalMatLocationDraw.setValue(this.core.normalMat); } frameCtx.modelMat = this.core.mat; }, - pick : function(frameCtx) { + pick: function (frameCtx) { /* Rebuild core's matrix from matrices at cores on path up to root */ @@ -18179,7 +18321,7 @@ SceneJS_ChunkFactory.createChunkType({ var gl = this.program.gl; if (this._uMatLocationPick) { - gl.uniformMatrix4fv(this._uMatLocationPick, gl.FALSE, this.core.mat); + this._uMatLocationPick.setValue(this.core.mat); } frameCtx.modelMat = this.core.mat; diff --git a/build/4.2.0/scenejs-4.2.0.min.js b/build/4.2.0/scenejs-4.2.0.min.js index 4ceae41e..3952cf72 100644 --- a/build/4.2.0/scenejs-4.2.0.min.js +++ b/build/4.2.0/scenejs-4.2.0.min.js @@ -4,7 +4,7 @@ * A WebGL-based 3D scene graph from xeoLabs * http://scenejs.org/ * - * Built on 2015-06-03 + * Built on 2015-06-11 * * MIT License * Copyright 2015, Lindsay Kay @@ -14,9 +14,9 @@ if(void 0===require){var requirejs,require,define;!function(ba){function J(a){return"[object Function]"===N.call(a)}function K(a){return"[object Array]"===N.call(a)}function z(a,b){if(a){var c;for(c=0;c-1&&(!a[c]||!b(a[c],c,a));c-=1);}}function t(a,b){return ha.call(a,b)}function m(a,b){return t(a,b)&&a[b]}function H(a,b){for(var c in a)if(t(a,c)&&b(a[c],c))break}function S(a,b,c,d){return b&&H(b,function(b,e){(c||!t(a,e))&&(d&&"string"!=typeof b?(a[e]||(a[e]={}),S(a[e],b,c,d)):a[e]=b)}),a}function v(a,b){return function(){return b.apply(a,arguments)}}function ca(a){throw a}function da(a){if(!a)return a;var b=ba;return z(a.split("."),function(a){b=b[a]}),b}function B(a,b,c,d){return b=Error(b+"\nhttp://requirejs.org/docs/errors.html#"+a),b.requireType=a,b.requireModules=d,c&&(b.originalError=c),b}function ia(a){function b(a,b,c){var d,e,f,g,h,i,j,k=b&&b.split("/");d=k;var l=C.map,n=l&&l["*"];if(a&&"."===a.charAt(0))if(b){for(d=m(C.pkgs,b)?k=[b]:k.slice(0,k.length-1),b=a=d.concat(a.split("/")),d=0;b[d];d+=1)if(e=b[d],"."===e)b.splice(d,1),d-=1;else if(".."===e){if(1===d&&(".."===b[2]||".."===b[0]))break;d>0&&(b.splice(d-1,2),d-=2)}d=m(C.pkgs,b=a[0]),a=a.join("/"),d&&a===b+"/"+d.main&&(a=b)}else 0===a.indexOf("./")&&(a=a.substring(2));if(c&&l&&(k||n)){for(b=a.split("/"),d=b.length;d>0;d-=1){if(f=b.slice(0,d).join("/"),k)for(e=k.length;e>0;e-=1)if((c=m(l,k.slice(0,e).join("/")))&&(c=m(c,f))){g=c,h=d;break}if(g)break;!i&&n&&m(n,f)&&(i=m(n,f),j=d)}!g&&i&&(g=i,h=j),g&&(b.splice(0,h,g),a=b.join("/"))}return a}function c(a){A&&z(document.getElementsByTagName("script"),function(b){return b.getAttribute("data-requiremodule")===a&&b.getAttribute("data-requirecontext")===w.contextName?(b.parentNode.removeChild(b),!0):void 0})}function d(a){var b=m(C.paths,a);return b&&K(b)&&1-1&&(b=a.substring(0,c),a=a.substring(c+1,a.length)),[b,a]}function f(a,c,d,f){var g,h,i=null,j=c?c.name:null,k=a,l=!0,n="";return a||(l=!1,a="_@r"+(M+=1)),a=e(a),i=a[0],a=a[1],i&&(i=b(i,j,f),h=m(I,i)),a&&(i?n=h&&h.normalize?h.normalize(a,function(a){return b(a,j,f)}):b(a,j,f):(n=b(a,j,f),a=e(n),i=a[0],n=a[1],d=!0,g=w.nameToUrl(n))),d=!i||h||d?"":"_unnormalized"+(N+=1),{prefix:i,name:n,parentMap:c,unnormalized:!!d,url:g,originalName:k,isDefine:l,id:(i?i+"!"+n:n)+d}}function g(a){var b=a.id,c=m(D,b);return c||(c=D[b]=new w.Module(a)),c}function i(a,b,c){var d=a.id,e=m(D,d);!t(I,d)||e&&!e.defineEmitComplete?(e=g(a),e.error&&"error"===b?c(e.error):e.on(b,c)):"defined"===b&&c(I[d])}function j(a,b){var c=a.requireModules,d=!1;b?b(a):(z(c,function(b){(b=m(D,b))&&(b.error=a,b.events.error&&(d=!0,b.emit("error",a)))}),d||h.onError(a))}function k(){U.length&&(ja.apply(G,[G.length-1,0].concat(U)),U=[])}function l(a){delete D[a],delete E[a]}function n(a,b,c){var d=a.map.id;a.error?a.emit("error",a.error):(b[d]=!0,z(a.depMaps,function(d,e){var f=d.id,g=m(D,f);g&&!a.depMatched[e]&&!c[f]&&(m(b,f)?(a.defineDep(e,I[f]),a.check()):n(g,b,c))}),c[d]=!0)}function o(){var a,b,e,f,g=(e=1e3*C.waitSeconds)&&w.startTime+e<(new Date).getTime(),h=[],i=[],k=!1,l=!0;if(!s){if(s=!0,H(E,function(e){if(a=e.map,b=a.id,e.enabled&&(a.isDefine||i.push(e),!e.error))if(!e.inited&&g)d(b)?k=f=!0:(h.push(b),c(b));else if(!e.inited&&e.fetched&&a.isDefine&&(k=!0,!a.prefix))return l=!1}),g&&h.length)return e=B("timeout","Load timeout for modules: "+h,null,h),e.contextName=w.contextName,j(e);l&&z(i,function(a){n(a,{},{})}),g&&!f||!k||!A&&!ea||y||(y=setTimeout(function(){y=0,o()},50)),s=!1}}function p(a){t(I,a[0])||g(f(a[0],null,!0)).init(a[1],a[2])}function q(a){var a=a.currentTarget||a.srcElement,b=w.onScriptLoad;return a.detachEvent&&!Z?a.detachEvent("onreadystatechange",b):a.removeEventListener("load",b,!1),b=w.onScriptError,(!a.detachEvent||Z)&&a.removeEventListener("error",b,!1),{node:a,id:a&&a.getAttribute("data-requiremodule")}}function r(){var a;for(k();G.length;){if(a=G.shift(),null===a[0])return j(B("mismatch","Mismatched anonymous define() module: "+a[a.length-1]));p(a)}}var s,u,w,x,y,C={waitSeconds:7,baseUrl:"./",paths:{},pkgs:{},shim:{},config:{}},D={},E={},F={},G=[],I={},L={},M=1,N=1;return x={require:function(a){return a.require?a.require:a.require=w.makeRequire(a.map)},exports:function(a){return a.usingExports=!0,a.map.isDefine?a.exports?a.exports:a.exports=I[a.map.id]={}:void 0},module:function(a){return a.module?a.module:a.module={id:a.map.id,uri:a.map.url,config:function(){var b=m(C.pkgs,a.map.id);return(b?m(C.config,a.map.id+"/"+b.main):m(C.config,a.map.id))||{}},exports:I[a.map.id]}}},u=function(a){this.events=m(F,a.id)||{},this.map=a,this.shim=m(C.shim,a.id),this.depExports=[],this.depMaps=[],this.depMatched=[],this.pluginMaps={},this.depCount=0},u.prototype={init:function(a,b,c,d){d=d||{},this.inited||(this.factory=b,c?this.on("error",c):this.events.error&&(c=v(this,function(a){this.emit("error",a)})),this.depMaps=a&&a.slice(0),this.errback=c,this.inited=!0,this.ignore=d.ignore,d.enabled||this.enabled?this.enable():this.check())},defineDep:function(a,b){this.depMatched[a]||(this.depMatched[a]=!0,this.depCount-=1,this.depExports[a]=b)},fetch:function(){if(!this.fetched){this.fetched=!0,w.startTime=(new Date).getTime();var a=this.map;if(!this.shim)return a.prefix?this.callPlugin():this.load();w.makeRequire(this.map,{enableBuildCallback:!0})(this.shim.deps||[],v(this,function(){return a.prefix?this.callPlugin():this.load()}))}},load:function(){var a=this.map.url;L[a]||(L[a]=!0,w.load(this.map.id,a))},check:function(){if(this.enabled&&!this.enabling){var a,b,c=this.map.id;b=this.depExports;var d=this.exports,e=this.factory;if(this.inited){if(this.error)this.emit("error",this.error);else if(!this.defining){if(this.defining=!0,1>this.depCount&&!this.defined){if(J(e)){if(this.events.error&&this.map.isDefine||h.onError!==ca)try{d=w.execCb(c,e,b,d)}catch(f){a=f}else d=w.execCb(c,e,b,d);if(this.map.isDefine&&((b=this.module)&&void 0!==b.exports&&b.exports!==this.exports?d=b.exports:void 0===d&&this.usingExports&&(d=this.exports)),a)return a.requireMap=this.map,a.requireModules=this.map.isDefine?[this.map.id]:null,a.requireType=this.map.isDefine?"define":"require",j(this.error=a)}else d=e;this.exports=d,this.map.isDefine&&!this.ignore&&(I[c]=d,h.onResourceLoad)&&h.onResourceLoad(w,this.map,this.depMaps),l(c),this.defined=!0}this.defining=!1,this.defined&&!this.defineEmitted&&(this.defineEmitted=!0,this.emit("defined",this.exports),this.defineEmitComplete=!0)}}else this.fetch()}},callPlugin:function(){var a=this.map,c=a.id,d=f(a.prefix);this.depMaps.push(d),i(d,"defined",v(this,function(d){var e,k;k=this.map.name;var n=this.map.parentMap?this.map.parentMap.name:null,o=w.makeRequire(a.parentMap,{enableBuildCallback:!0});this.map.unnormalized?(d.normalize&&(k=d.normalize(k,function(a){return b(a,n,!0)})||""),d=f(a.prefix+"!"+k,this.map.parentMap),i(d,"defined",v(this,function(a){this.init([],function(){return a},null,{enabled:!0,ignore:!0})})),(k=m(D,d.id))&&(this.depMaps.push(d),this.events.error&&k.on("error",v(this,function(a){this.emit("error",a)})),k.enable())):(e=v(this,function(a){this.init([],function(){return a},null,{enabled:!0})}),e.error=v(this,function(a){this.inited=!0,this.error=a,a.requireModules=[c],H(D,function(a){0===a.map.id.indexOf(c+"_unnormalized")&&l(a.map.id)}),j(a)}),e.fromText=v(this,function(b,d){var i=a.name,k=f(i),l=Q;d&&(b=d),l&&(Q=!1),g(k),t(C.config,c)&&(C.config[i]=C.config[c]);try{h.exec(b)}catch(m){return j(B("fromtexteval","fromText eval for "+c+" failed: "+m,m,[c]))}l&&(Q=!0),this.depMaps.push(k),w.completeLoad(i),o([i],e)}),d.load(a.name,o,e,C))})),w.enable(d,this),this.pluginMaps[d.id]=d},enable:function(){E[this.map.id]=this,this.enabling=this.enabled=!0,z(this.depMaps,v(this,function(a,b){var c,d;if("string"==typeof a){if(a=f(a,this.map.isDefine?this.map:this.map.parentMap,!1,!this.skipMap),this.depMaps[b]=a,c=m(x,a.id))return void(this.depExports[b]=c(this));this.depCount+=1,i(a,"defined",v(this,function(a){this.defineDep(b,a),this.check()})),this.errback&&i(a,"error",v(this,this.errback))}c=a.id,d=D[c],!t(x,c)&&d&&!d.enabled&&w.enable(a,this)})),H(this.pluginMaps,v(this,function(a){var b=m(D,a.id);b&&!b.enabled&&w.enable(a,this)})),this.enabling=!1,this.check()},on:function(a,b){var c=this.events[a];c||(c=this.events[a]=[]),c.push(b)},emit:function(a,b){z(this.events[a],function(a){a(b)}),"error"===a&&delete this.events[a]}},w={config:C,contextName:a,registry:D,defined:I,urlFetched:L,defQueue:G,Module:u,makeModuleMap:f,nextTick:h.nextTick,onError:j,configure:function(a){a.baseUrl&&"/"!==a.baseUrl.charAt(a.baseUrl.length-1)&&(a.baseUrl+="/");var b=C.pkgs,c=C.shim,d={paths:!0,config:!0,map:!0};H(a,function(a,b){d[b]?"map"===b?(C.map||(C.map={}),S(C[b],a,!0,!0)):S(C[b],a,!0):C[b]=a}),a.shim&&(H(a.shim,function(a,b){K(a)&&(a={deps:a}),!a.exports&&!a.init||a.exportsFn||(a.exportsFn=w.makeShimExports(a)),c[b]=a}),C.shim=c),a.packages&&(z(a.packages,function(a){a="string"==typeof a?{name:a}:a,b[a.name]={name:a.name,location:a.location||a.name,main:(a.main||"main").replace(ka,"").replace(fa,"")}}),C.pkgs=b),H(D,function(a,b){!a.inited&&!a.map.unnormalized&&(a.map=f(b))}),(a.deps||a.callback)&&w.require(a.deps||[],a.callback)},makeShimExports:function(a){return function(){var b;return a.init&&(b=a.init.apply(ba,arguments)),b||a.exports&&da(a.exports)}},makeRequire:function(c,d){function e(b,i,k){var l,m;return d.enableBuildCallback&&i&&J(i)&&(i.__requireJsBuild=!0),"string"==typeof b?J(i)?j(B("requireargs","Invalid require call"),k):c&&t(x,b)?x[b](D[c.id]):h.get?h.get(w,b,c,e):(l=f(b,c,!1,!0),l=l.id,t(I,l)?I[l]:j(B("notloaded",'Module name "'+l+'" has not been loaded yet for context: '+a+(c?"":". Use require([])")))):(r(),w.nextTick(function(){r(),m=g(f(null,c)),m.skipMap=d.skipMap,m.init(b,i,k,{enabled:!0}),o()}),e)}return d=d||{},S(e,{isBrowser:A,toUrl:function(a){var d,e=a.lastIndexOf("."),f=a.split("/")[0];return-1!==e&&("."!==f&&".."!==f||e>1)&&(d=a.substring(e,a.length),a=a.substring(0,e)),w.nameToUrl(b(a,c&&c.id,!0),d,!0)},defined:function(a){return t(I,f(a,c,!1,!0).id)},specified:function(a){return a=f(a,c,!1,!0).id,t(I,a)||t(D,a)}}),c||(e.undef=function(a){k();var b=f(a,c,!0),d=m(D,a);delete I[a],delete L[b.url],delete F[a],d&&(d.events.defined&&(F[a]=d.events),l(a))}),e},enable:function(a){m(D,a.id)&&g(a).enable()},completeLoad:function(a){var b,c,e=m(C.shim,a)||{},f=e.exports;for(k();G.length;){if(c=G.shift(),null===c[0]){if(c[0]=a,b)break;b=!0}else c[0]===a&&(b=!0);p(c)}if(c=m(D,a),!b&&!t(I,a)&&c&&!c.inited){if(C.enforceDefine&&(!f||!da(f)))return d(a)?void 0:j(B("nodefine","No define call for "+a,null,[a]));p([a,e.deps||[],e.exportsFn])}o()},nameToUrl:function(a,b,c){var d,e,f,g,i,j;if(h.jsExtRegExp.test(a))g=a+(b||"");else{for(d=C.paths,e=C.pkgs,g=a.split("/"),i=g.length;i>0;i-=1){if(j=g.slice(0,i).join("/"),f=m(e,j),j=m(d,j)){K(j)&&(j=j[0]),g.splice(0,i,j);break}if(f){a=a===f.name?f.location+"/"+f.main:f.location,g.splice(0,i,a);break}}g=g.join("/"),g+=b||(/\?/.test(g)||c?"":".js"),g=("/"===g.charAt(0)||g.match(/^[\w\+\.\-]+:/)?"":C.baseUrl)+g}return C.urlArgs?g+((-1===g.indexOf("?")?"?":"&")+C.urlArgs):g},load:function(a,b){h.load(w,a,b)},execCb:function(a,b,c,d){return b.apply(d,c)},onScriptLoad:function(a){("load"===a.type||la.test((a.currentTarget||a.srcElement).readyState))&&(R=null,a=q(a),w.completeLoad(a.id))},onScriptError:function(a){var b=q(a);return d(b.id)?void 0:j(B("scripterror","Script error for: "+b.id,a,[b.id]))}},w.require=w.makeRequire(),w}var h,x,y,E,L,F,R,M,s,ga,ma=/(\/\*([\s\S]*?)\*\/|([^:]|^)\/\/(.*)$)/gm,na=/[^.]\s*require\s*\(\s*["']([^'"\s]+)["']\s*\)/g,fa=/\.js$/,ka=/^\.\//;x=Object.prototype;var N=x.toString,ha=x.hasOwnProperty,ja=Array.prototype.splice,A=!("undefined"==typeof window||!navigator||!window.document),ea=!A&&"undefined"!=typeof importScripts,la=A&&"PLAYSTATION 3"===navigator.platform?/^complete$/:/^(complete|loaded)$/,Z="undefined"!=typeof opera&&"[object Opera]"===opera.toString(),G={},u={},U=[],Q=!1;if("undefined"==typeof define){if("undefined"!=typeof requirejs){if(J(requirejs))return;u=requirejs,requirejs=void 0}"undefined"!=typeof require&&!J(require)&&(u=require,require=void 0),h=requirejs=function(a,b,c,d){var e,f="_";return!K(a)&&"string"!=typeof a&&(e=a,K(b)?(a=b,b=c,c=d):a=[]),e&&e.context&&(f=e.context),(d=m(G,f))||(d=G[f]=h.s.newContext(f)),e&&d.configure(e),d.require(a,b,c)},h.config=function(a){return h(a)},h.nextTick="undefined"!=typeof setTimeout?function(a){setTimeout(a,4)}:function(a){a()},require||(require=h),h.version="2.1.6",h.jsExtRegExp=/^\/|:|\?|\.js$/,h.isBrowser=A,x=h.s={contexts:G,newContext:ia},h({}),z(["toUrl","undef","defined","specified"],function(a){h[a]=function(){var b=G._;return b.require[a].apply(b,arguments)}}),A&&(y=x.head=document.getElementsByTagName("head")[0],E=document.getElementsByTagName("base")[0])&&(y=x.head=E.parentNode),h.onError=ca,h.load=function(a,b,c){var d,e=a&&a.config||{};if(A)return d=e.xhtml?document.createElementNS("http://www.w3.org/1999/xhtml","html:script"):document.createElement("script"),d.type=e.scriptType||"text/javascript",d.charset="utf-8",d.async=!0,d.setAttribute("data-requirecontext",a.contextName),d.setAttribute("data-requiremodule",b),!d.attachEvent||d.attachEvent.toString&&0>d.attachEvent.toString().indexOf("[native code")||Z?(d.addEventListener("load",a.onScriptLoad,!1),d.addEventListener("error",a.onScriptError,!1)):(Q=!0,d.attachEvent("onreadystatechange",a.onScriptLoad)),d.src=c,M=d,E?y.insertBefore(d,E):y.appendChild(d),M=null,d;if(ea)try{importScripts(c),a.completeLoad(b)}catch(f){a.onError(B("importscripts","importScripts failed for "+b+" at "+c,f,[b]))}},A&&O(document.getElementsByTagName("script"),function(a){return y||(y=a.parentNode),(L=a.getAttribute("data-main"))?(s=L,u.baseUrl||(F=s.split("/"),s=F.pop(),ga=F.length?F.join("/")+"/":"./",u.baseUrl=ga),s=s.replace(fa,""),h.jsExtRegExp.test(s)&&(s=L),u.deps=u.deps?u.deps.concat(s):[s],!0):void 0}),define=function(a,b,c){var d,e;"string"!=typeof a&&(c=b,b=a,a=null),K(b)||(c=b,b=null),!b&&J(c)&&(b=[],c.length&&(c.toString().replace(ma,"").replace(na,function(a,c){b.push(c)}),b=(1===c.length?["require"]:["require","exports","module"]).concat(b))),Q&&((d=M)||(R&&"interactive"===R.readyState||O(document.getElementsByTagName("script"),function(a){return"interactive"===a.readyState?R=a:void 0}),d=R),d&&(a||(a=d.getAttribute("data-requiremodule")),e=G[d.getAttribute("data-requirecontext")])),(e?e.defQueue:U).push([a,b,c])},define.amd={jQuery:!0},h.exec=function(b){return eval(b)},h(u)}}(this)}WebGLDebugUtils=function(){function a(a){if(null==m){m={};for(var b in a)"number"==typeof a[b]&&(m[a[b]]=b)}}function b(){if(null==m)throw"WebGLDebugUtils.init(ctx) not called"}function c(a){return b(),void 0!==m[a]}function d(a){b();var c=m[a];return void 0!==c?c:"*UNKNOWN WebGL ENUM (0x"+a.toString(16)+")"}function e(a,b,c){var e=l[a];return void 0!==e&&e[b]?d(c):null===c?"null":void 0===c?"undefined":c.toString()}function f(a,b){for(var c="",d=0;dd;++d)a.disableVertexAttribArray(d),a.vertexAttribPointer(d,4,a.FLOAT,!1,0,0),a.vertexAttrib1f(d,0);a.deleteBuffer(c);for(var e=a.getParameter(a.MAX_TEXTURE_IMAGE_UNITS),d=0;e>d;++d)a.activeTexture(a.TEXTURE0+d),a.bindTexture(a.TEXTURE_CUBE_MAP,null),a.bindTexture(a.TEXTURE_2D,null);for(a.activeTexture(a.TEXTURE0),a.useProgram(null),a.bindBuffer(a.ARRAY_BUFFER,null),a.bindBuffer(a.ELEMENT_ARRAY_BUFFER,null),a.bindFramebuffer(a.FRAMEBUFFER,null),a.bindRenderbuffer(a.RENDERBUFFER,null),a.disable(a.BLEND),a.disable(a.CULL_FACE),a.disable(a.DEPTH_TEST),a.disable(a.DITHER),a.disable(a.SCISSOR_TEST),a.blendColor(0,0,0,0),a.blendEquation(a.FUNC_ADD),a.blendFunc(a.ONE,a.ZERO),a.clearColor(0,0,0,0),a.clearDepth(1),a.clearStencil(-1),a.colorMask(!0,!0,!0,!0),a.cullFace(a.BACK),a.depthFunc(a.LESS),a.depthMask(!0),a.depthRange(0,1),a.frontFace(a.CCW),a.hint(a.GENERATE_MIPMAP_HINT,a.DONT_CARE),a.lineWidth(1),a.pixelStorei(a.PACK_ALIGNMENT,4),a.pixelStorei(a.UNPACK_ALIGNMENT,4),a.pixelStorei(a.UNPACK_FLIP_Y_WEBGL,!1),a.pixelStorei(a.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!1),a.UNPACK_COLORSPACE_CONVERSION_WEBGL&&a.pixelStorei(a.UNPACK_COLORSPACE_CONVERSION_WEBGL,a.BROWSER_DEFAULT_WEBGL),a.polygonOffset(0,0),a.sampleCoverage(1,!1),a.scissor(0,0,a.canvas.width,a.canvas.height),a.stencilFunc(a.ALWAYS,0,4294967295),a.stencilMask(4294967295),a.stencilOp(a.KEEP,a.KEEP,a.KEEP),a.viewport(0,0,a.canvas.width,a.canvas.height),a.clear(a.COLOR_BUFFER_BIT|a.DEPTH_BUFFER_BIT|a.STENCIL_BUFFER_BIT);a.getError(););}function j(a){function b(a){return"function"==typeof a?a:function(b){a.handleEvent(b)}}function c(a){var b=a.addEventListener;a.addEventListener=function(c,d,e){switch(c){case"webglcontextlost":x(d);break;case"webglcontextrestored":y(d);break;default:b.apply(a,arguments)}}}function d(){for(var a=Object.keys(w),b=0;b=0&&setTimeout(function(){a.restoreContext()},v)},0)}},a.restoreContext=function(){q&&o.length&&setTimeout(function(){if(!u)throw"can not restore. webglcontestlost listener did not call event.preventDefault";h(),i(l),q=!1,t=0,u=!1;for(var a=o.slice(),b=j("context restored"),c=0;c0)return!1;if(0===b.length)return!0;for(var c in b)if(a.call(b,c))return!1;return!0},this.reset=function(){var a=[];for(var b in this._engines)this._engines.hasOwnProperty(b)&&(a.push(this._engines[b]),delete this._engines[b],this._engineIds.removeItem(b));for(;a.length>0;)a.pop().destroy();SceneJS_events.fireEvent(SceneJS_events.RESET)}};!function(){var a;SceneJS.on("configs",function(b){if(b.pluginPath!=a){a=b.pluginPath;var c=a+"/lib";require.config({paths:{scenejsPluginDeps:c}})}})}();var SceneJS_eventManager=function(){this._handlerIds=new SceneJS_Map,this.typeHandlers={}};SceneJS_eventManager.prototype.createEvent=function(a){this.typeHandlers[a]||(this.typeHandlers[a]={handlers:{},numSubs:0})},SceneJS_eventManager.prototype.onEvent=function(a,b){var c=this.typeHandlers[a]||(this.typeHandlers[a]={handlers:{},numSubs:0}),d=this._handlerIds.addItem(a),e=c.handlers;return e[d]=b,c.numSubs++,d},SceneJS_eventManager.prototype.fireEvent=function(a,b){var c=this.typeHandlers[a]||(this.typeHandlers[a]={handlers:{},numSubs:0});if(c.numSubs>0){var d=c.handlers;for(var e in d)d.hasOwnProperty(e)&&d[e](b)}},SceneJS_eventManager.prototype.unEvent=function(a){var b=this._handlerIds.items[a];if(b){this._handlerIds.removeItem(a);var c=this.typeHandlers[b];c&&(delete c[a],this.typeHandlers[b].numSubs--)}},SceneJS.Plugins=new function(){function a(a,c,f,g){var h=d[a]||(d[a]={});h[c]=g,b(f,0,function(){for(var b=a+c,d=e[b]||(e[b]=[]);d.length>0;)d.pop()(g);delete e[b]})}function b(a,d,e){if(!a||d>=a.length)return void e();var f=a[d],g=SceneJS_configsModule.configs.pluginPath;if(!g)throw"no pluginPath config";f=g+"/"+f,c(f,function(){b(a,d+1,e)})}function c(a,b){var c=document.createElement("script");c.type="text/javascript",c.readyState?c.onreadystatechange=function(){("loaded"==c.readyState||"complete"==c.readyState)&&(c.onreadystatechange=null,b&&b())}:c.onload=function(){b&&b()},c.src=a,document.getElementsByTagName("head")[0].appendChild(c)}var d={},e={};this.addPlugin=function(){var b,c,d=arguments[0],e=arguments[1];4==arguments.length?(b=arguments[2],c=arguments[3]):c=arguments[2],a(d,e,b,c)},this.hasPlugin=function(a,b){var c=d[a];return c&&!!c[b]},this.getPlugin=function(a,b,f){var g=d[a];if(g){var h=g[b];if(h)return void f(h)}var i=a+b,j=e[i]||(e[i]=[]);if(j.push(f),!(j.length>1)){var k=SceneJS_configsModule.configs.pluginPath;if(!k)throw"no pluginPath config";var l=k+"/"+a+"/"+b+".js";c(l)}}};var SceneJS_events=new function(){this.ERROR=0,this.RESET=1,this.NODE_CREATED=2,this.SCENE_CREATED=3,this.SCENE_COMPILING=4,this.SCENE_DESTROYED=5,this.OBJECT_COMPILING=6,this.WEBGL_CONTEXT_LOST=7,this.WEBGL_CONTEXT_RESTORED=8;var a=[];this.addListener=function(b,c,d){var e=a[b];e||(e=[],a[b]=e);for(var f={command:c,priority:void 0==d?e.length:d},g=-1,h=0,i=e.length;i>h;h++)if(!e[h]){g=h;break}0>g&&(e.push(f),g=e.length-1);var j=b+"."+g;return j},this.removeListener=function(b){var c=b.lastIndexOf("."),d=parseInt(b.substr(0,c)),e=parseInt(b.substr(c+1)),f=a[d];f&&delete f[e]},this.fireEvent=function(b,c){var d=a[b];if(d){c=c||{};for(var e=0;e',e.appendChild(f)}var h=document.getElementById(b);if(!h)throw SceneJS_error.fatalError(SceneJS.errors.CANVAS_NOT_FOUND,"SceneJS.Scene attribute 'canvasId' does not match any elements in the page");this.canvasId=b,this.options=d||{},this.canvas=this.options.simulateWebGLContextLost?WebGLDebugUtils.makeLostContextSimulatingCanvas(h):h,this.ssaaMultiplier=this.options.ssaaMultiplier||1,this.canvas.width=this.canvas.clientWidth*this.ssaaMultiplier,this.canvas.height=this.canvas.clientHeight*this.ssaaMultiplier,this.contextAttr=c,this.gl=null,this.initWebGL()};SceneJS_Canvas.prototype._WEBGL_CONTEXT_NAMES=["webgl","experimental-webgl","webkit-3d","moz-webgl","moz-glweb20"],SceneJS_Canvas.prototype.initWebGL=function(){for(var a=0;!this.gl&&af;f++)d.createNode(a.nodes[f],function(a){c.addNode(a),++e==g&&(b&&b(c),d.scene.publish("nodes/"+c.id,c))});else b&&(b(c),d.scene.publish("nodes/"+c.id,c))})},SceneJS_Engine.prototype._doDestroyNodes=function(){for(var a;this._numNodesToDestroy>0;)a=this._nodesToDestroy[--this._numNodesToDestroy],a._doDestroy(),this._coreFactory.putCore(a._core),this._nodeFactory.putNode(a)},SceneJS_Engine.prototype.findNode=function(a){return this._nodeFactory.nodes.items[a]},SceneJS_Engine.prototype.findNodes=function(a){var b=new RegExp(a),c=[],d=this._nodeFactory.nodes.items;for(var e in d)d.hasOwnProperty(e)&&b.test(e)&&c.push(d[e]);return c},SceneJS_Engine.prototype.hasCore=function(a,b){return this._coreFactory.hasCore(a,b)},SceneJS_Engine.prototype.branchDirty=function(a){if(!this.sceneDirty&&a!=window){a.branchDirty=!0,a.dirty=!0;for(var b=a.parent;b&&!b.dirty&&!b.branchDirty;b=b.parent)b.dirty=!0;this._sceneBranchesDirty=!0}},SceneJS_Engine.prototype.renderFrame=function(a){var b=!1;if(this._needCompile()||a&&a.force)for(var c=(new Date).getTime(),d=a&&a.force,e=0;e0?setTimeout(window[e],1e3/d.fps):requestAnimationFrame(window[e]))},setTimeout(window[e],0)}},SceneJS_Engine.prototype.pick=function(a,b,c){this._needCompile()&&this._doCompile();var d=this.display.pick({canvasX:a,canvasY:b,rayPick:c?c.rayPick:!1});return d},SceneJS_Engine.prototype.readPixels=function(a,b){return this._needCompile()&&this._doCompile(),this.display.readPixels(a,b)},SceneJS_Engine.prototype._needCompile=function(){return this.display.imageDirty||this.display.drawListDirty||this.display.stateSortDirty||this.display.stateOrderDirty||this.display.objectListDirty||this._sceneBranchesDirty||this.sceneDirty},SceneJS_Engine.prototype._doCompile=function(){if(this._sceneBranchesDirty||this.sceneDirty){this._sceneBranchesDirty=!1,SceneJS_events.fireEvent(SceneJS_events.SCENE_COMPILING,{engine:this}),this.pubSubProxy=new SceneJS_PubSubProxy(this.scene,null);var a={pubSubProxy:this.pubSubProxy};this.scene._compileNodes(a),this.sceneDirty=!1}this._doDestroyNodes()},SceneJS_Engine.prototype.pause=function(a){this.paused=a},SceneJS_Engine.prototype.stop=function(){this.running&&(this.running=!1,this.paused=!1,window["__scenejs_sceneLoop"+this.id]=null)},SceneJS_Engine.prototype.destroyNode=function(a){this._nodesToDestroy[this._numNodesToDestroy++]=a;var b=this.sceneStatus.nodes[a.id];b&&(this.sceneStatus.numTasks-=b.numTasks,delete this.sceneStatus.nodes[a.id])},SceneJS_Engine.prototype.destroy=function(){this.destroyed=!0},self.Int32Array||(self.Int32Array=Array,self.Float32Array=Array),function(){for(var a=0,b=["ms","moz","webkit","o"],c=0;ch;h++)i[h](g);SceneJS.publish("configs",this.configs)},this.getConfigs=function(a){if(a){for(var b=this.configs,c=a.split("."),d=0;b&&dc;c++)b.push("----");e=b.join("")},this.error=function(a){this._log("error",a)},this.warn=function(a){this._log("warn",a)},this.info=function(a){this._log("info",a)},this.debug=function(a){this._log("debug",a)},this.setFuncs=function(a){if(a){b=a;for(var d in c)this._flush(d)}},this._flush=function(a){var d=c[a];if(d){var e=b?b[a]:null;if(e){for(var f=0;fy;++y)f=b[y],c=f[0],d=f[1],e=f[2],g[y]=[i*c+m*d+q*e+u,j*c+n*d+r*e+v,k*c+o*d+s*e+w,l*c+p*d+t*e+x];return g},SceneJS_math_transformVector3=function(a,b){var c=b[0],d=b[1],e=b[2];return[a[0]*c+a[4]*d+a[8]*e,a[1]*c+a[5]*d+a[9]*e,a[2]*c+a[6]*d+a[10]*e]},SceneJS_math_transformVector4=function(a,b){var c=b[0],d=b[1],e=b[2],f=b[3];return[a[0]*c+a[4]*d+a[8]*e+a[12]*f,a[1]*c+a[5]*d+a[9]*e+a[13]*f,a[2]*c+a[6]*d+a[10]*e+a[14]*f,a[3]*c+a[7]*d+a[11]*e+a[15]*f]},SceneJS_math_projectVec4=function(a){var b=1/a[3];return[a[0]*b,a[1]*b,a[2]*b,1]},SceneJS_math_Plane3=function(a,b,c){if(this.normal=[0,0,1],this.offset=0,a&&b){var d=a[0],e=a[1],f=a[2];if(this.offset=b,c){var g=Math.sqrt(d*d+e*e+f*f);g>0&&(g=1/g,this.normal[0]=d*g,this.normal[1]=e*g,this.normal[2]=f*g,this.offset*=g)}}},SceneJS_math_MAX_DOUBLE=Number.POSITIVE_INFINITY,SceneJS_math_MIN_DOUBLE=Number.NEGATIVE_INFINITY,SceneJS_math_Box3=function(a,b){this.min=a||[SceneJS_math_MAX_DOUBLE,SceneJS_math_MAX_DOUBLE,SceneJS_math_MAX_DOUBLE],this.max=b||[SceneJS_math_MIN_DOUBLE,SceneJS_math_MIN_DOUBLE,SceneJS_math_MIN_DOUBLE],this.init=function(a,b){return this.min[0]=a[0],this.min[1]=a[1],this.min[2]=a[2],this.max[0]=b[0],this.max[1]=b[1],this.max[2]=b[2],this},this.fromPoints=function(a){for(var b=a.length,c=0;b>c;++c){var d=a[c][3],e=a[c][0]/d,f=a[c][1]/d,g=a[c][2]/d;ethis.max[0]&&(this.max[0]=e),f>this.max[1]&&(this.max[1]=f),g>this.max[2]&&(this.max[2]=g)}return this},this.isEmpty=function(){return this.min[0]>=this.max[0]&&this.min[1]>=this.max[1]&&this.min[2]>=this.max[2]},this.getCenter=function(){return[(this.max[0]+this.min[0])/2,(this.max[1]+this.min[1])/2,(this.max[2]+this.min[2])/2]},this.getSize=function(){return[this.max[0]-this.min[0],this.max[1]-this.min[1],this.max[2]-this.min[2]]},this.getFacesAreas=function(){var a=this.size;return[a[1]*a[2],a[0]*a[2],a[0]*a[1]]},this.getSurfaceArea=function(){var a=this.getFacesAreas();return 2*(a[0]+a[1]+a[2])},this.getVolume=function(){var a=this.size;return a[0]*a[1]*a[2]},this.getOffset=function(a){return this.min[0]-=a,this.min[1]-=a,this.min[2]-=a,this.max[0]+=a,this.max[1]+=a,this.max[2]+=a,this}},SceneJS_math_AxisBox3=function(a,b){var c=a[0],d=a[1],e=a[2],f=b[0],g=b[1],h=b[2];this.verts=[[c,d,e],[f,d,e],[f,g,e],[c,g,e],[c,d,h],[f,d,h],[f,g,h],[c,g,h]],this.toBox3=function(){for(var a=new SceneJS_math_Box3,b=0;8>b;++b)for(var c=this.verts[b],d=0;3>d;++d)c[d]a.max[d]&&(a.max[d]=c[d])}},SceneJS_math_Sphere3=function(a,b){this.center=[a[0],a[1],a[2]],this.radius=b,this.isEmpty=function(){return 0===this.radius},this.surfaceArea=function(){return 4*Math.PI*this.radius*this.radius},this.getVolume=function(){var a=this.radius;return 4/3*Math.PI*a*a*a}},SceneJS_math_billboardMat=function(a){var b=[SceneJS_math_getColMat4(a,0),SceneJS_math_getColMat4(a,1),SceneJS_math_getColMat4(a,2)],c=[SceneJS_math_lenVec4(b[0]),SceneJS_math_lenVec4(b[1]),SceneJS_math_lenVec4(b[2])],d=SceneJS_math_mat4();SceneJS_math_rcpVec3(c,d);var e=SceneJS_math_scalingMat4v(c);SceneJS_math_mulVec4Scalar(b[0],d[0]),SceneJS_math_mulVec4Scalar(b[1],d[1]),SceneJS_math_mulVec4Scalar(b[2],d[2]);var f=SceneJS_math_identityMat4();return SceneJS_math_setRowMat4(f,0,b[0]),SceneJS_math_setRowMat4(f,1,b[1]),SceneJS_math_setRowMat4(f,2,b[2]),SceneJS_math_mulMat4(f,e)},SceneJS_math_FrustumPlane=function(a,b,c,d){var e=1/Math.sqrt(a*a+b*b+c*c);this.normal=[a*e,b*e,c*e],this.offset=d*e,this.testVertex=[this.normal[0]>=0?1:0,this.normal[1]>=0?1:0,this.normal[2]>=0?1:0]},SceneJS_math_OUTSIDE_FRUSTUM=3,SceneJS_math_INTERSECT_FRUSTUM=4,SceneJS_math_INSIDE_FRUSTUM=5,SceneJS_math_Frustum=function(a,b,c){var d=SceneJS_math_mat4();SceneJS_math_mulMat4(b,a,d);var e=d[0],f=d[1],g=d[2],h=d[3],i=d[4],j=d[5],k=d[6],l=d[7],m=d[8],n=d[9],o=d[10],p=d[11],q=d[12],r=d[13],s=d[14],t=d[15],u=[new SceneJS_math_FrustumPlane(h-e,l-i,p-m,t-q),new SceneJS_math_FrustumPlane(h+e,l+i,p+m,t+q),new SceneJS_math_FrustumPlane(h-f,l-j,p-n,t-r),new SceneJS_math_FrustumPlane(h+f,l+j,p+n,t+r),new SceneJS_math_FrustumPlane(h-g,l-k,p-o,t-s),new SceneJS_math_FrustumPlane(h+g,l+k,p+o,t+s)],v=[SceneJS_math_getColMat4(a,0),SceneJS_math_getColMat4(a,1),SceneJS_math_getColMat4(a,2)],w=[SceneJS_math_lenVec4(v[0]),SceneJS_math_lenVec4(v[1]),SceneJS_math_lenVec4(v[2])],x=SceneJS_math_rcpVec3(w),y=SceneJS_math_scalingMat4v(w),z=SceneJS_math_scalingMat4v(x);SceneJS_math_mulVec4Scalar(v[0],x[0]),SceneJS_math_mulVec4Scalar(v[1],x[1]),SceneJS_math_mulVec4Scalar(v[2],x[2]);var A=SceneJS_math_identityMat4();SceneJS_math_setRowMat4(A,0,v[0]),SceneJS_math_setRowMat4(A,1,v[1]),SceneJS_math_setRowMat4(A,2,v[2]),this.matrix||(this.matrix=SceneJS_math_mat4()),SceneJS_math_mulMat4(b,a,this.matrix),this.billboardMatrix||(this.billboardMatrix=SceneJS_math_mat4()),SceneJS_math_mulMat4(z,SceneJS_math_mulMat4(A,y),this.billboardMatrix),this.viewport=c.slice(0,4),this.textAxisBoxIntersection=function(a){for(var b=SceneJS_math_INSIDE_FRUSTUM,c=[a.min,a.max],d=null,e=0;6>e;++e){if(d=u[e],d.normal[0]*c[d.testVertex[0]][0]+d.normal[1]*c[d.testVertex[1]][1]+d.normal[2]*c[d.testVertex[2]][2]+d.offset<0)return SceneJS_math_OUTSIDE_FRUSTUM;d.normal[0]*c[1-d.testVertex[0]][0]+d.normal[1]*c[1-d.testVertex[1]][1]+d.normal[2]*c[1-d.testVertex[2]][2]+d.offset<0&&(b=SceneJS_math_INTERSECT_FRUSTUM)}return b},this.getProjectedSize=function(a){var b=SceneJS_math_mat4();SceneJS_math_subVec3(a.max,a.min,b);var d=SceneJS_math_lenVec3(b),e=Math.abs(d),f=[.5*(a.min[0]+a.max[0]),.5*(a.min[1]+a.max[1]),.5*(a.min[2]+a.max[2]),0],g=.5*e,h=[-g,0,0,1],i=[g,0,0,1];return h=SceneJS_math_mulMat4v4(this.billboardMatrix,h),h=SceneJS_math_addVec4(h,f),h=SceneJS_math_projectVec4(SceneJS_math_mulMat4v4(this.matrix,h)),i=SceneJS_math_mulMat4v4(this.billboardMatrix,i),i=SceneJS_math_addVec4(i,f),i=SceneJS_math_projectVec4(SceneJS_math_mulMat4v4(this.matrix,i)),c[2]*Math.abs(i[0]-h[0])},this.getProjectedState=function(a){for(var b,d,e,f=SceneJS_math_transformPoints3(this.matrix,a),g=1e7,h=1e7,i=-1e7,j=-1e7,k=f.length,l=0;k>l;++l)b=SceneJS_math_projectVec4(f[l]),d=b[0],e=b[1],-.5>d&&(d=-.5),-.5>e&&(e=-.5),d>.5&&(d=.5),e>.5&&(e=.5),g>d&&(g=d),h>e&&(h=e),d>i&&(i=d),e>j&&(j=e);g+=.5,h+=.5,i+=.5,j+=.5;var m=c[2],n=c[3];g*=m+15,h*=n+15,i*=m+15,j*=n+15;var o=SceneJS_math_mat4();SceneJS_math_subVec2([i,j],[g,h],o);var p=SceneJS_math_lenVec2(o);return 0>g&&(g=0),i>m&&(i=m),0>h&&(h=0),j>n&&(j=n),{canvasBox:{min:[g,h],max:[i,j]},canvasSize:p}}},SceneJS_math_identityQuaternion=function(){return[0,0,0,1]},SceneJS_math_angleAxisQuaternion=function(a,b,c,d){var e=d/180*Math.PI,f=e/2,g=Math.sin(f);return[g*a,g*b,g*c,Math.cos(f)]},SceneJS_math_mulQuaternions=function(a,b){var c=a[0],d=a[1],e=a[2],f=a[3],g=b[0],h=b[1],i=b[2],j=b[3];return[f*g+c*j+d*i-e*h,f*h+d*j+e*g-c*i,f*i+e*j+c*h-d*g,f*j-c*g-d*h-e*i]},SceneJS_math_newMat4FromQuaternion=function(a){var b=a[0],c=a[1],d=a[2],e=a[3],f=2*b,g=2*c,h=2*d,i=f*e,j=g*e,k=h*e,l=f*b,m=g*b,n=h*b,o=g*c,p=h*c,q=h*d,r=SceneJS_math_identityMat4();return SceneJS_math_setCellMat4(r,0,0,1-(o+q)),SceneJS_math_setCellMat4(r,0,1,m-k),SceneJS_math_setCellMat4(r,0,2,n+j),SceneJS_math_setCellMat4(r,1,0,m+k),SceneJS_math_setCellMat4(r,1,1,1-(l+q)),SceneJS_math_setCellMat4(r,1,2,p-i),SceneJS_math_setCellMat4(r,2,0,n-j),SceneJS_math_setCellMat4(r,2,1,p+i),SceneJS_math_setCellMat4(r,2,2,1-(l+o)),r},SceneJS_math_slerp=function(a,b,c){var d=.0174532925*b[3],e=.0174532925*c[3],f=d*e+b[0]*c[0]+b[1]*c[1]+b[2]*c[2];if(Math.abs(f)>=1)return[b[0],b[1],b[2],b[3]];var g=Math.acos(f),h=Math.sqrt(1-f*f);if(Math.abs(h)<.001)return[.5*b[0]+.5*c[0],.5*b[1]+.5*c[1],.5*b[2]+.5*c[2],.5*b[3]+.5*c[3]];var i=Math.sin((1-a)*g)/h,j=Math.sin(a*g)/h;return[b[0]*i+c[0]*j,b[1]*i+c[1]*j,b[2]*i+c[2]*j,57.295779579*(d*i+e*j)]},SceneJS_math_normalizeQuaternion=function(a){var b=SceneJS_math_lenVec4([a[0],a[1],a[2],a[3]]);return[a[0]/b,a[1]/b,a[2]/b,a[3]/b]},SceneJS_math_conjugateQuaternion=function(a){return[-a[0],-a[1],-a[2],a[3]]},SceneJS_math_angleAxisFromQuaternion=function(a){a=SceneJS_math_normalizeQuaternion(a);var b=a[3],c=2*Math.acos(b),d=Math.sqrt(1-b*b);return.001>d?{x:a[0],y:a[1],z:a[2],angle:57.295779579*c}:{x:a[0]/d,y:a[1]/d,z:a[2]/d,angle:57.295779579*c}},SceneJS_sceneStatusModule=new function(){function a(a){var b=document.getElementsByTagName("body")[0],c=document.createElement("div"),d=c.style;return d.position="absolute",d.width="200px",d.right="10px",d.top="0",d.padding="10px",d["z-index"]="10000",b.appendChild(c),c}function b(a,b){var c=document.createElement("div"),d=c.style;return d["font-family"]="Helvetica",d["font-size"]="14px",d.padding="5px",d.margin="4px",d["padding-left"]="12px",d.border="1px solid #000055",d.color="black",d.background="#AAAAAA",d.opacity="0.8",d["border-radius"]="3px",d["-moz-border-radius"]="3px",d["box-shadow"]="3px 3px 3px #444444",c.innerHTML=b,a.appendChild(c),c}function c(a){a.style.background="#AAFFAA";var b=.8,c=setInterval(function(){0>=b?(a.parentNode.removeChild(a),clearInterval(c)):(a.style.opacity=b,b-=.1)},100)}function d(a){a.style.background="#FFAAAA"}this.sceneStatus={};var e=new SceneJS_Map,f={},g={},h=this;SceneJS_events.addListener(SceneJS_events.SCENE_DESTROYED,function(a){var b=a.engine.id;delete h.sceneStatus[b],delete g[b]}),this.taskStarted=function(c,d){var h=SceneJS_configsModule.configs.statusPopups!==!1,i=c.getScene(),j=i.getId(),k=c.getId(),l=i.getCanvas(),m=e.addItem(),n=this.sceneStatus[j];n||(n=this.sceneStatus[j]={numTasks:0}),n.numTasks++;var o=g[j];o||(o=g[j]={sceneId:j,nodeStates:{},scene:i,popupContainer:h?a(l):null,descCounts:{}});var p=o.descCounts[d];void 0==p&&(p=o.descCounts[d]=0),o.descCounts[d]++;var q=o.nodeStates[k];q||(q=o.nodeStates[k]={nodeId:k,numTasks:0,tasks:{}}),d=d+" "+o.descCounts[d]+"...",q.numTasks++;var r={sceneState:o,nodeState:q,description:d,element:h?b(o.popupContainer,d):null};return q.tasks[m]=r,f[m]=r,m},this.taskFinished=function(a){if(-1==a||null==a)return null;var b=f[a];if(!b)return null;var d=b.sceneState;this.sceneStatus[d.sceneId].numTasks--,b.element&&c(b.element);var e=b.nodeState;return--e.numTasks<0&&(e.numTasks=0),delete e.tasks[a],0==e.numTasks&&delete d.nodeStates[e.nodeId],null},this.taskFailed=function(a){if(-1==a||null==a)return null;var b=f[a];if(!b)return null;var c=!!SceneJS_configsModule.configs.statusPopups,e=b.sceneState;this.sceneStatus[e.sceneId].numTasks--,c&&d(b.element);var g=b.nodeState;return g.numTasks--,delete g.tasks[a],0==g.numTasks&&delete b.sceneState.nodeStates[g.nodeId],null}};SceneJS._webgl={},SceneJS._webgl.ArrayBuffer=function(a,b,c,d,e,f){this.allocated=!1,this.gl=a,this.type=b, -this.numItems=d,this.itemSize=e,this.usage=f,this._allocate(c,d)},SceneJS._webgl.ArrayBuffer.prototype._allocate=function(a,b){if(this.allocated=!1,this.handle=this.gl.createBuffer(),!this.handle)throw SceneJS_error.fatalError(SceneJS.errors.OUT_OF_VRAM,"Failed to allocate WebGL ArrayBuffer");this.handle&&(this.gl.bindBuffer(this.type,this.handle),this.gl.bufferData(this.type,a,this.usage),this.gl.bindBuffer(this.type,null),this.numItems=b,this.length=a.length,this.allocated=!0)},SceneJS._webgl.ArrayBuffer.prototype.setData=function(a,b){this.allocated&&(a.length>this.length?(this.destroy(),this._allocate(a,a.length)):b||0===b?this.gl.bufferSubData(this.type,b,a):this.gl.bufferData(this.type,a))},SceneJS._webgl.ArrayBuffer.prototype.unbind=function(){this.allocated&&this.gl.bindBuffer(this.type,null)},SceneJS._webgl.ArrayBuffer.prototype.destroy=function(){this.allocated&&(this.gl.deleteBuffer(this.handle),this.handle=null,this.allocated=!1)},SceneJS._webgl.ArrayBuffer.prototype.bind=function(){this.allocated&&this.gl.bindBuffer(this.type,this.handle)},SceneJS._webgl.Attribute=function(a,b,c,d,e,f){this.gl=a,this.location=f,this.bindFloatArrayBuffer=function(b){b&&(b.bind(),a.enableVertexAttribArray(f),a.vertexAttribPointer(f,b.itemSize,a.FLOAT,!1,0,0))}},SceneJS._webgl.Attribute.prototype.bindInterleavedFloatArrayBuffer=function(a,b,c){this.gl.enableVertexAttribArray(this.location),this.gl.vertexAttribPointer(this.location,a,this.gl.FLOAT,!1,b,c)},SceneJS._webgl.enumMap={funcAdd:"FUNC_ADD",funcSubtract:"FUNC_SUBTRACT",funcReverseSubtract:"FUNC_REVERSE_SUBTRACT",zero:"ZERO",one:"ONE",srcColor:"SRC_COLOR",oneMinusSrcColor:"ONE_MINUS_SRC_COLOR",dstColor:"DST_COLOR",oneMinusDstColor:"ONE_MINUS_DST_COLOR",srcAlpha:"SRC_ALPHA",oneMinusSrcAlpha:"ONE_MINUS_SRC_ALPHA",dstAlpha:"DST_ALPHA",oneMinusDstAlpha:"ONE_MINUS_DST_ALPHA",contantColor:"CONSTANT_COLOR",oneMinusConstantColor:"ONE_MINUS_CONSTANT_COLOR",constantAlpha:"CONSTANT_ALPHA",oneMinusConstantAlpha:"ONE_MINUS_CONSTANT_ALPHA",srcAlphaSaturate:"SRC_ALPHA_SATURATE",front:"FRONT",back:"BACK",frontAndBack:"FRONT_AND_BACK",never:"NEVER",less:"LESS",equal:"EQUAL",lequal:"LEQUAL",greater:"GREATER",notequal:"NOTEQUAL",gequal:"GEQUAL",always:"ALWAYS",cw:"CW",ccw:"CCW",linear:"LINEAR",nearest:"NEAREST",linearMipMapNearest:"LINEAR_MIPMAP_NEAREST",nearestMipMapNearest:"NEAREST_MIPMAP_NEAREST",nearestMipMapLinear:"NEAREST_MIPMAP_LINEAR",linearMipMapLinear:"LINEAR_MIPMAP_LINEAR",repeat:"REPEAT",clampToEdge:"CLAMP_TO_EDGE",mirroredRepeat:"MIRRORED_REPEAT",alpha:"ALPHA",rgb:"RGB",rgba:"RGBA",luminance:"LUMINANCE",luminanceAlpha:"LUMINANCE_ALPHA",textureBinding2D:"TEXTURE_BINDING_2D",textureBindingCubeMap:"TEXTURE_BINDING_CUBE_MAP",compareRToTexture:"COMPARE_R_TO_TEXTURE",unsignedByte:"UNSIGNED_BYTE"},SceneJS._webgl.RenderBuffer=function(a){this.allocated=!1,this.canvas=a.canvas,this.gl=a.canvas.gl,this.buf=null,this.bound=!1},SceneJS._webgl.RenderBuffer.prototype.webglRestored=function(a){this.gl=a,this.buf=null,this.allocated=!1,this.bound=!1},SceneJS._webgl.RenderBuffer.prototype.bind=function(){this._touch(),this.bound||(this.gl.bindFramebuffer(this.gl.FRAMEBUFFER,this.buf.framebuf),this.bound=!0)},SceneJS._webgl.RenderBuffer.prototype._touch=function(){var a=this.canvas.canvas.width,b=this.canvas.canvas.height;if(this.buf){if(this.buf.width==a&&this.buf.height==b)return;this.gl.deleteTexture(this.buf.texture),this.gl.deleteFramebuffer(this.buf.framebuf),this.gl.deleteRenderbuffer(this.buf.renderbuf)}this.buf={framebuf:this.gl.createFramebuffer(),renderbuf:this.gl.createRenderbuffer(),texture:this.gl.createTexture(),width:a,height:b},this.gl.bindFramebuffer(this.gl.FRAMEBUFFER,this.buf.framebuf),this.gl.bindTexture(this.gl.TEXTURE_2D,this.buf.texture),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_MAG_FILTER,this.gl.NEAREST),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_MIN_FILTER,this.gl.NEAREST),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_WRAP_S,this.gl.CLAMP_TO_EDGE),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_WRAP_T,this.gl.CLAMP_TO_EDGE);try{this.gl.texImage2D(this.gl.TEXTURE_2D,0,this.gl.RGBA,a,b,0,this.gl.RGBA,this.gl.UNSIGNED_BYTE,null)}catch(c){var d=new WebGLUnsignedByteArray(a*b*3);this.gl.texImage2D(this.gl.TEXTURE_2D,0,this.gl.RGBA,a,b,0,this.gl.RGBA,this.gl.UNSIGNED_BYTE,d)}if(this.gl.bindRenderbuffer(this.gl.RENDERBUFFER,this.buf.renderbuf),this.gl.renderbufferStorage(this.gl.RENDERBUFFER,this.gl.DEPTH_COMPONENT16,a,b),this.gl.framebufferTexture2D(this.gl.FRAMEBUFFER,this.gl.COLOR_ATTACHMENT0,this.gl.TEXTURE_2D,this.buf.texture,0),this.gl.framebufferRenderbuffer(this.gl.FRAMEBUFFER,this.gl.DEPTH_ATTACHMENT,this.gl.RENDERBUFFER,this.buf.renderbuf),this.gl.bindTexture(this.gl.TEXTURE_2D,null),this.gl.bindRenderbuffer(this.gl.RENDERBUFFER,null),this.gl.bindFramebuffer(this.gl.FRAMEBUFFER,null),this.gl.bindFramebuffer(this.gl.FRAMEBUFFER,this.buf.framebuf),!this.gl.isFramebuffer(this.buf.framebuf))throw SceneJS_error.fatalError(SceneJS.errors.INVALID_FRAMEBUFFER,"Invalid framebuffer");var e=this.gl.checkFramebufferStatus(this.gl.FRAMEBUFFER);switch(e){case this.gl.FRAMEBUFFER_COMPLETE:break;case this.gl.FRAMEBUFFER_INCOMPLETE_ATTACHMENT:throw SceneJS_error.fatalError(SceneJS.errors.ERROR,"Incomplete framebuffer: FRAMEBUFFER_INCOMPLETE_ATTACHMENT");case this.gl.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:throw SceneJS_error.fatalError(SceneJS.errors.ERROR,"Incomplete framebuffer: FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT");case this.gl.FRAMEBUFFER_INCOMPLETE_DIMENSIONS:throw SceneJS_error.fatalError(SceneJS.errors.ERROR,"Incomplete framebuffer: FRAMEBUFFER_INCOMPLETE_DIMENSIONS");case this.gl.FRAMEBUFFER_UNSUPPORTED:throw SceneJS_error.fatalError(SceneJS.errors.ERROR,"Incomplete framebuffer: FRAMEBUFFER_UNSUPPORTED");default:throw SceneJS_error.fatalError(SceneJS.errors.ERROR,"Incomplete framebuffer: "+e)}this.bound=!1},SceneJS._webgl.RenderBuffer.prototype.clear=function(){if(!this.bound)throw"Render buffer not bound";this.gl.clear(this.gl.COLOR_BUFFER_BIT|this.gl.DEPTH_BUFFER_BIT),this.gl.disable(this.gl.BLEND)},SceneJS._webgl.RenderBuffer.prototype.read=function(a,b){var c=a,d=this.canvas.canvas.height-b,e=new Uint8Array(4);return this.gl.readPixels(c,d,1,1,this.gl.RGBA,this.gl.UNSIGNED_BYTE,e),e},SceneJS._webgl.RenderBuffer.prototype.unbind=function(){this.gl.bindFramebuffer(this.gl.FRAMEBUFFER,null),this.bound=!1},SceneJS._webgl.RenderBuffer.prototype.getTexture=function(){var a=this;return{bind:function(b){return a.buf&&a.buf.texture?(a.gl.activeTexture(a.gl["TEXTURE"+b]),a.gl.bindTexture(a.gl.TEXTURE_2D,a.buf.texture),!0):!1},unbind:function(b){a.buf&&a.buf.texture&&(a.gl.activeTexture(a.gl["TEXTURE"+b]),a.gl.bindTexture(a.gl.TEXTURE_2D,null))}}},SceneJS._webgl.RenderBuffer.prototype.destroy=function(){this.buf&&(this.gl.deleteTexture(this.buf.texture),this.gl.deleteFramebuffer(this.buf.framebuf),this.gl.deleteRenderbuffer(this.buf.renderbuf),this.buf=null,this.bound=!1)},SceneJS._webgl.Program=function(a,b,c){this.allocated=!1,this.gl=a,this._uniforms={},this._samplers={},this._attributes={},this.uniformValues=[],this.materialSettings={specularColor:[0,0,0],specular:0,shine:0,emit:0,alpha:0},this._shaders=[];var d,e,f,g,h,i;for(e=0;ee;++e)f=a.getActiveUniform(this.handle,e),f&&(g=f.name,"\x00"==g[g.length-1]&&(g=g.substr(0,g.length-1)),h=a.getUniformLocation(this.handle,g),f.type==a.SAMPLER_2D||f.type==a.SAMPLER_CUBE||35682==f.type?this._samplers[g]=new SceneJS._webgl.Sampler(a,this.handle,g,f.type,f.size,h):(this._uniforms[g]=new SceneJS._webgl.Uniform(a,this.handle,g,f.type,f.size,h,k),this.uniformValues[k]=null,++k));var l=a.getProgramParameter(this.handle,a.ACTIVE_ATTRIBUTES);for(e=0;l>e;e++)d=a.getActiveAttrib(this.handle,e),d&&(h=a.getAttribLocation(this.handle,d.name),this._attributes[d.name]=new SceneJS._webgl.Attribute(a,this.handle,d.name,d.type,d.size,h));this.allocated=!0}},SceneJS._webgl.Program.prototype.bind=function(){this.allocated&&this.gl.useProgram(this.handle)},SceneJS._webgl.Program.prototype.getUniformLocation=function(a){if(this.allocated){var b=this._uniforms[a];return b?b.getLocation():void 0}},SceneJS._webgl.Program.prototype.getUniform=function(a){if(this.allocated){var b=this._uniforms[a];return b?b:void 0}},SceneJS._webgl.Program.prototype.getAttribute=function(a){if(this.allocated){var b=this._attributes[a];return b?b:void 0}},SceneJS._webgl.Program.prototype.bindFloatArrayBuffer=function(a,b){if(this.allocated){var c=this._attributes[a];c&&c.bindFloatArrayBuffer(b)}},SceneJS._webgl.Program.prototype.bindTexture=function(a,b,c){if(!this.allocated)return!1;var d=this._samplers[a];return d?d.bindTexture(b,c):!1},SceneJS._webgl.Program.prototype.destroy=function(){if(this.allocated){this.gl.deleteProgram(this.handle);for(var a in this._shaders)this.gl.deleteShader(this._shaders[a].handle);this.handle=null,this._attributes=null,this._uniforms=null,this._samplers=null,this.allocated=!1}},SceneJS._webgl.Program.prototype.setUniform=function(a,b){if(this.allocated){var c=this._uniforms[a];c&&(this.uniformValues[c.index]===b&&c.numberValue||(c.setValue(b),this.uniformValues[c.index]=b))}},SceneJS._webgl.Sampler=function(a,b,c,d,e,f){this.bindTexture=function(b,c){return b.bind(c)?(a.uniform1i(f,c),!0):!1}},SceneJS._webgl.Shader=function(a,b,c){if(this.allocated=!1,this.handle=a.createShader(b),!this.handle)throw SceneJS_error.fatalError(SceneJS.errors.OUT_OF_VRAM,"Failed to create WebGL shader");if(a.shaderSource(this.handle,c),a.compileShader(this.handle),this.valid=0!=a.getShaderParameter(this.handle,a.COMPILE_STATUS),!this.valid&&!a.isContextLost()){SceneJS.log.error("Shader program failed to compile: "+a.getShaderInfoLog(this.handle)),SceneJS.log.error("Shader source:");for(var d=c.split("\n"),e=0;eb){var d=b/c,e=a.width*d,f=a.height*d,g=document.createElement("canvas");g.width=SceneJS._webgl.nextHighestPowerOfTwo(e),g.height=SceneJS._webgl.nextHighestPowerOfTwo(f);var h=g.getContext("2d");h.drawImage(a,0,0,a.width,a.height,0,0,g.width,g.height),a=g}return a},SceneJS._webgl.ensureImageSizePowerOfTwo=function(a){if(!SceneJS._webgl.isPowerOfTwo(a.width)||!SceneJS._webgl.isPowerOfTwo(a.height)){var b=document.createElement("canvas");b.width=SceneJS._webgl.nextHighestPowerOfTwo(a.width),b.height=SceneJS._webgl.nextHighestPowerOfTwo(a.height);var c=b.getContext("2d");c.drawImage(a,0,0,a.width,a.height,0,0,b.width,b.height),a=b}return a},SceneJS._webgl.isPowerOfTwo=function(a){return 0==(a&a-1)},SceneJS._webgl.nextHighestPowerOfTwo=function(a){--a;for(var b=1;32>b;b<<=1)a|=a>>b;return a+1},SceneJS._webgl.Uniform=function(a,b,c,d,e,f,g,h){var i=null;if(this.numberValue=!1,d==a.BOOL)this.numberValue=!0,i=function(b){a.uniform1i(f,b)};else if(d==a.BOOL_VEC2)i=function(b){a.uniform2iv(f,b)};else if(d==a.BOOL_VEC3)i=function(b){a.uniform3iv(f,b)};else if(d==a.BOOL_VEC4)i=function(b){a.uniform4iv(f,b)};else if(d==a.INT)this.numberValue=!0,i=function(b){a.uniform1iv(f,b)};else if(d==a.INT_VEC2)i=function(b){a.uniform2iv(f,b)};else if(d==a.INT_VEC3)i=function(b){a.uniform3iv(f,b)};else if(d==a.INT_VEC4)i=function(b){a.uniform4iv(f,b)};else if(d==a.FLOAT)this.numberValue=!0,i=function(b){a.uniform1f(f,b)};else if(d==a.FLOAT_VEC2)i=function(b){a.uniform2fv(f,b)};else if(d==a.FLOAT_VEC3)i=function(b){a.uniform3fv(f,b)};else if(d==a.FLOAT_VEC4)i=function(b){a.uniform4fv(f,b)};else if(d==a.FLOAT_MAT2)i=function(b){a.uniformMatrix2fv(f,a.FALSE,b)};else if(d==a.FLOAT_MAT3)i=function(b){a.uniformMatrix3fv(f,a.FALSE,b)};else{if(d!=a.FLOAT_MAT4)throw"Unsupported shader uniform type: "+d;i=function(b){a.uniformMatrix4fv(f,a.FALSE,b)}}this.setValue=i,this.getValue=function(){return a.getUniform(b,f)},this.getLocation=function(){return f},this.index=g};var SceneJS_nodeEventsModule=new function(){var a,b=[],c=[],d=0,e={type:"listeners",stateId:SceneJS._baseStateId++,empty:!0,listeners:[]};SceneJS_events.addListener(SceneJS_events.SCENE_COMPILING,function(){d=0,a=!0}),SceneJS_events.addListener(SceneJS_events.OBJECT_COMPILING,function(f){if(a){if(d>0){var g={type:"listeners",stateId:b[d-1],listeners:c.slice(0,d)};f.display.renderListeners=g}else f.display.renderListeners=e;a=!1}}),this.preVisitNode=function(e){var f=e._topicSubs.rendered,g=e._topicSubs.worldPos,h=e._topicSubs.viewPos,i=e._topicSubs.cameraPos,j=e._topicSubs.projPos,k=e._topicSubs.canvasPos;(f||g||h||i||j||k)&&(b[d]=e.id,c[d]=function(a){f&&e.publish("rendered",a,!0),g&&e.publish("worldPos",a.getWorldPos()),h&&e.publish("viewPos",a.getViewPos()),i&&e.publish("cameraPos",a.getCameraPos()),j&&e.publish("projPos",a.getProjPos()),k&&e.publish("canvasPos",a.getCanvasPos())},d++,a=!0)},this.postVisitNode=function(c){c.id==b[d-1]&&(d--,a=!0)}},SceneJS_Core=function(a){this.type=a,this.coreId=null,this.stateId=null,this.useCount=0},SceneJS_CoreFactory=function(){this._stateMap=new SceneJS_Map(null,SceneJS._baseStateId),this._cores={}};SceneJS_CoreFactory.coreTypes={},SceneJS_CoreFactory.createCoreType=function(a,b){},SceneJS_CoreFactory.addCoreBuilder=function(a,b){},SceneJS_CoreFactory.coreAliases={rotate:"xform",translate:"xform",scale:"xform",matrix:"xform",xform:"xform"},SceneJS_CoreFactory.prototype.getCore=function(a,b){var c=SceneJS_CoreFactory.coreAliases[a];c&&(a=c);var d=this._cores[a];d||(d=this._cores[a]={});var e;return b&&(e=d[b])?(e.useCount++,e):(e=new SceneJS_Core(a),e.useCount=1,e.stateId=this._stateMap.addItem(e),e.coreId=void 0!=b&&null!=b?b:e.stateId,d[e.coreId]=e,e)},SceneJS_CoreFactory.prototype.hasCore=function(a,b){var c=SceneJS_CoreFactory.coreAliases[a];c&&(a=c);var d=this._cores[a];return d&&d[b]},SceneJS_CoreFactory.prototype.putCore=function(a){if(0!=a.useCount&&--a.useCount<=0){var b=this._cores[a.type];delete b[a.coreId],this._stateMap.removeItem(a.stateId)}},SceneJS_CoreFactory.prototype.webglRestored=function(){var a,b;for(var c in this._cores)if(this._cores.hasOwnProperty(c)&&(a=this._cores[c]))for(var d in a)a.hasOwnProperty(d)&&(b=a[d],b&&b.webglRestored&&b.webglRestored())},SceneJS.Node=function(){},SceneJS.Node.prototype.constructor=SceneJS.Node,SceneJS.Node.prototype._construct=function(a,b,c,d){this._engine=a,this._core=b,this.coreId=b.coreId,this.id=c.id||c.nodeId||d,this.type=c.type||"node",this.data=c.data,this.parent=null,this.nodes=[],this._handleMap=new SceneJS_Map,this._topicSubs={},this._handleTopics={},this._topicPubs={},this._listeners={},this._numListeners=0,this.dirty=!1,this.branchDirty=!1,this._init&&this._init(c)},SceneJS.Node.prototype.taskStarted=function(a){return SceneJS_sceneStatusModule.taskStarted(this,a||"Task")},SceneJS.Node.prototype.taskFinished=function(a){return SceneJS_sceneStatusModule.taskFinished(a)},SceneJS.Node.prototype.taskFailed=function(a){return SceneJS_sceneStatusModule.taskFailed(a)},SceneJS.Node.prototype.log=function(){var a,b;switch(1==arguments.length?(a="info",b=arguments[0]):2==arguments.length&&(a=arguments[0],b=arguments[1]),a){case"warn":b="WARN; [SceneJS.Node type="+this.type+", id="+this.id+"] : "+b;break;case"error":b="ERROR; [SceneJS.Node type="+this.type+", id="+this.id+"] : "+b;break;default:b="INFO; [SceneJS.Node type="+this.type+", id="+this.id+"] : "+b}console[a]?console[a](b):console.log(b)},SceneJS.Node.prototype.publish=function(a,b,c){if(c||(this._topicPubs[a]=b),this._topicSubs[a]){var d=this._topicSubs[a];for(var e in d)d.hasOwnProperty(e)&&d[e].call(this,b)}},SceneJS.Node.prototype.unpublish=function(a){var b=this._topicSubs[a];if(b)for(var c in b)b.hasOwnProperty(c)&&b[c].call(this,null);delete this._topicPubs[a]},SceneJS.Node.prototype.on=function(a,b){var c=this._topicSubs[a];c||(c={},this._topicSubs[a]=c);var d=this._handleMap.addItem();c[d]=b,this._handleTopics[d]=a;var e=this._topicPubs[a];return e&&b.call(this,e),"rendered"==a&&this._engine.branchDirty(this),d},SceneJS.Node.prototype.off=function(a){var b=this._handleTopics[a];if(b){delete this._handleTopics[a];var c=this._topicSubs[b];c&&delete c[a],this._handleMap.removeItem(a),"rendered"==b&&this._engine.branchDirty(this)}},SceneJS.Node.prototype.once=function(a,b){var c=this,d=this.on(a,function(a){c.off(d),b(a)})},SceneJS.Node.prototype.getScene=function(){return this._engine.scene},SceneJS.Node.prototype.getCoreId=function(){return this._core.coreId},SceneJS.Node.prototype.getID=function(){return this.id},SceneJS.Node.prototype.getId=function(){return this.id},SceneJS.Node.prototype.getNodeId=function(){return this.id},SceneJS.Node.prototype.getType=function(){return this.type},SceneJS.Node.prototype.getData=function(){return this.data},SceneJS.Node.prototype.setData=function(a){return this.data=a,this},SceneJS.Node.prototype.getNumNodes=function(){return this.nodes.length},SceneJS.Node.prototype.getNodes=function(){return this.nodes.slice(0)},SceneJS.Node.prototype.getNodeAt=function(a){return 0>a||a>=this.nodes.length?null:this.nodes[a]},SceneJS.Node.prototype.getFirstNode=function(){return 0==this.nodes.length?null:this.nodes[0]},SceneJS.Node.prototype.getLastNode=function(){return 0==this.nodes.length?null:this.nodes[this.nodes.length-1]},SceneJS.Node.prototype.getNode=function(a){for(var b=0;b0?(b[0].parent=null,this._engine.display.objectListDirty=!0,b[0]):null},SceneJS.Node.prototype.disconnect=function(){if(this.parent){for(var a=0;ab;b++)this.nodes[b].parent=null;var c=this.nodes;return this.nodes=[],this._engine.display.objectListDirty=!0,c},SceneJS.Node.prototype.removeNodes=function(){for(var a=this.disconnectNodes(),b=0;ba;a++)d[a].parent=this.parent;for(a=0,b=c.nodes.length;b>a;a++)if(c.nodes[a]===this)return c.nodes.splice.apply(c.nodes,[a,1].concat(d)),this.nodes=[],this.parent=null,this.destroy(),this._engine.branchDirty(c),c},SceneJS.Node.prototype.addNodes=function(a,b){if(!a)throw SceneJS_error.fatalError(SceneJS.errors.ILLEGAL_NODE_CONFIG,"Node#addNodes - nodes argument is undefined");for(var c,d=[],e=a.length,f=a.length-1;f>=0;f--){var g=a[f];if("node"==g.type||this._engine.hasNodeType(g.type)){if(c=this.addNode(g),d[f]=c,0==--e)return b&&b(a),a}else{var h=this;!function(){var c=f;h.addNode(g,function(f){d[c]=f,0==--e&&b&&b(a)})}()}}return null},SceneJS.Node.prototype.addNode=function(a,b){if(a=a||{},a._compile){if(null!=a.parent)throw SceneJS_error.fatalError(SceneJS.errors.ILLEGAL_NODE_CONFIG,"Node#addNode - node argument is still attached to another parent");return this.nodes.push(a),a.parent=this,this._engine.branchDirty(a),b&&b(a),a}if("string"==typeof a){var c=this._engine.findNode(a);if(!c)throw SceneJS_error.fatalError(SceneJS.errors.ILLEGAL_NODE_CONFIG,"Node#addNode - node not found: '"+a+"'");if(a=c,null!=a.parent)throw SceneJS_error.fatalError(SceneJS.errors.ILLEGAL_NODE_CONFIG,"Node#addNode - node argument is still attached to another parent");return this.nodes.push(a),a.parent=this,this._engine.branchDirty(a),b&&b(a),a}if(a.type=a.type||"node","node"==a.type||this._engine.hasNodeType(a.type))return a=this._engine.createNode(a),this.nodes.push(a),a.parent=this,this._engine.branchDirty(a),b&&b(a),a;var d=this;return this._engine.createNode(a,function(a){d.nodes.push(a),a.parent=d,d._engine.branchDirty(a),b&&b(a)}),null},SceneJS.Node.prototype.insertNode=function(a,b){if(!a)throw SceneJS_error.fatalError(SceneJS.errors.ILLEGAL_NODE_CONFIG,"SceneJS.Node#insertNode - node argument is undefined");if(a._compile||(a=this._engine.createNode(a)),!a._compile)throw SceneJS_error.fatalError(SceneJS.errors.ILLEGAL_NODE_CONFIG,"SceneJS.Node#insertNode - node argument is not a SceneJS.Node");if(null!=a.parent)throw SceneJS_error.fatalError(SceneJS.errors.ILLEGAL_NODE_CONFIG,"SceneJS.Node#insertNode - node argument is still attached to another parent");if(void 0===b||null===b)a.addNodes(this.disconnectNodes()),this.addNode(a);else{if(0>b)throw SceneJS_error.fatalError(SceneJS.errors.ILLEGAL_NODE_CONFIG,"SceneJS.Node#insertNode - node index out of range: -1");b>=this.nodes.length?this.nodes.push(a):this.nodes.splice(b,0,a)}return a.parent=this,a},SceneJS.Node.prototype.mapNodes=function(a){if(a(this))return this;for(var b,c=0;cg;g++)e=d[g],e.options.scope?e.fn.call(e.options.scope,f):e.fn.call(this,f)}},SceneJS.Node.prototype.removeListener=function(a,b){var c=this._listeners[a];if(!c)return null;for(var d=0;d0},SceneJS.Node.prototype.removeListeners=function(){return this._listeners={},this._numListeners=0,this},SceneJS.Node.prototype.getParent=function(a){return this.parent},SceneJS.Node.prototype.getParentOfType=function(a){for(var b=this.parent;b&&b.type!=a;)b=b.parent;return b},SceneJS.Node.prototype.eachParent=function(a){if(!a)throw"SceneJS.Node.eachParent param 'fn' is null or undefined";for(var b=0,c=this;c.parent;){if(a.call(c.parent,b++)===!0)return c.parent;c=c.parent}return null},SceneJS.Node.prototype.hasNode=function(a){if(null===a||void 0===a)throw"SceneJS.Node.hasNode param 'node' is null or undefined";var b,c=typeof a;if("number"==c)b=this.getNodeAt(a);else{if("string"!=c)throw"SceneJS.Node.hasNode param 'node' should be either an index number or an ID string";b=this.getNode(a)}return void 0!=b&&null!=b},SceneJS.Node.prototype.node=function(a){if(null===a||void 0===a)throw"SceneJS.Node.node param 'node' is null or undefined";var b,c=typeof a;if("number"==c)b=this.getNodeAt(a);else{if("string"!=c)throw"SceneJS.Node.node param 'node' should be either an index number or an ID string";b=this.getNode(a)}if(!b)throw"SceneJS.Node.node - node not found: '"+a+"'";return b},SceneJS.Node.prototype.eachNode=function(a,b){if(!a)throw"SceneJS.Node.eachNode param 'fn' is null or undefined";if("function"!=typeof a)throw"SceneJS.Node.eachNode param 'fn' should be a function";var c;b=b||{};var d=0;return b.andSelf&&a.call(this,d++)===!0?this:(b.depthFirst||b.breadthFirst?b.depthFirst&&(c=this._iterateEachNodeDepthFirst(a,this,d,!1)):c=this._iterateEachNode(a,this,d),c?c:void 0)},SceneJS.Node.prototype.numNodes=function(){return this.nodes.length},SceneJS.Node.prototype._iterateEachNode=function(a,b,c){for(var d,e=b.nodes.length,f=0;e>f;f++)if(d=b.nodes[f],a.call(d,c++)===!0)return d;return null},SceneJS.Node.prototype._iterateEachNodeDepthFirst=function(a,b,c,d){if(d&&a.call(b,c++)===!0)return b;d=!0;for(var e,f=b.nodes.length,g=0;f>g;g++)if(e=this._iterateEachNodeDepthFirst(a,b.nodes[g],c,d))return e;return null},SceneJS.Node.prototype.findNodesByType=function(a,b){return this._findNodesByType(a,[],b)},SceneJS.Node.prototype._findNodesByType=function(a,b,c){var d;for(d=0;dd;d++)c=this.nodes[d],c.branchDirty=c.branchDirty||this.branchDirty,(c.dirty||c.branchDirty||this._engine.sceneDirty)&&(c._compile(a),c.dirty=!1,c.branchDirty=!1);b&&SceneJS_nodeEventsModule.postVisitNode(this)},SceneJS.Node.prototype.destroy=function(){if(!this.destroyed){if(this.parent)for(var a=0;aa;a++)this.nodes[a]._destroyTree()},SceneJS.Node.prototype._doDestroy=function(){return this._destroy&&this._destroy(),this},SceneJS_PubSubProxy=function(a,b){this.scene=a,this.proxy=b};var SceneJS_NodeFactory=function(){this.nodes=new SceneJS_Map({})};SceneJS_NodeFactory.nodeTypes={},SceneJS_NodeFactory._subs={},SceneJS_NodeFactory.createNodeType=function(a,b,c){if(SceneJS_NodeFactory.nodeTypes[a])throw"Node type already defined: "+a;var d=function(){SceneJS.Node.apply(this,arguments),this.type=a};d.prototype=new SceneJS.Node,d.prototype.constructor=d,SceneJS_NodeFactory.nodeTypes[a]=d;var e=SceneJS_NodeFactory.nodeTypes[a];if(!e)throw"Node type plugin did not install itself correctly";c&&c(d);var f=SceneJS_NodeFactory._subs[a];if(f){for(;f.length>0;)f.pop()(e);delete f[a]}return d},SceneJS_NodeFactory.prototype.getNode=function(a,b,c,d){b.type=b.type||"node";var e;if(e="node"==b.type?SceneJS.Node:SceneJS_NodeFactory.nodeTypes[b.type])return this._createNode(e,a,b,c,d);var f=this;this._getType(a,b.type,function(e){f._createNode(e,a,b,c,d)})},SceneJS_NodeFactory.prototype._createNode=function(a,b,c,d,e){var f=new a,g=c.id||c.nodeId;return g?this.nodes.addItem(g,f):g=this.nodes.addItem(f),f._construct(b,d,c,g),e&&e(f),f},SceneJS_NodeFactory.prototype._getType=function(a,b,c){var d=SceneJS_NodeFactory.nodeTypes[b];if(d)return void c(d);var e=SceneJS_NodeFactory._subs[b]||(SceneJS_NodeFactory._subs[b]=[]);if(e.push(c),!(e.length>1)){var f=SceneJS_sceneStatusModule.taskStarted(a.scene,"Loading plugin");e.push(function(){SceneJS_sceneStatusModule.taskFinished(f)});var g=SceneJS_configsModule.configs.pluginPath;if(!g)throw"no typePath config";this._loadScript(g+"/node/"+b+".js",function(){SceneJS_sceneStatusModule.taskFailed(f)})}},SceneJS_NodeFactory.prototype._loadScript=function(a,b){var c=document.createElement("script");c.type="text/javascript",c.src=a,c.onerror=b,document.getElementsByTagName("head")[0].appendChild(c)},SceneJS_NodeFactory.prototype.putNode=function(a){this.nodes.removeItem(a.id)},function(){function a(a){var b=a.optics; -if("ortho"==b.type?a.matrix=SceneJS_math_orthoMat4c(b.left,b.right,b.bottom,b.top,b.near,b.far):"frustum"==b.type?a.matrix=SceneJS_math_frustumMatrix4(b.left,b.right,b.bottom,b.top,b.near,b.far):"perspective"==b.type&&(a.matrix=SceneJS_math_perspectiveMatrix4(b.fovy*Math.PI/180,b.aspect,b.near,b.far)),a.pan){var c=a.pan,d=SceneJS_math_translationMat4v([c.x||0,c.y||0,c.z||0]);a.matrix=SceneJS_math_mulMat4(d,a.matrix,[])}a.mat?a.mat.set(a.matrix):a.mat=new Float32Array(a.matrix)}var b=SceneJS_math_perspectiveMatrix4(45,1,.1,1e4),c=new Float32Array(b),d={type:"camera",stateId:SceneJS._baseStateId++,matrix:b,mat:c,optics:{type:"perspective",fovy:45,aspect:1,near:.1,far:1e4},checkAspect:function(b,c){b.optics.aspect!=c&&(b.optics.aspect=c,a(this))}},e=[],f=0;SceneJS_events.addListener(SceneJS_events.SCENE_COMPILING,function(a){a.engine.display.projTransform=d,f=0}),SceneJS.Camera=SceneJS_NodeFactory.createNodeType("camera"),SceneJS.Camera.prototype._init=function(b){if(1==this._core.useCount){b.optics=b.optics||{};var c=this.getScene().getCanvas();b.optics.aspect=c.width/c.height,this.setOptics(b.optics),b.pan&&this.setPan(b.pan);var d=this;this._canvasSizeSub=this.getScene().on("canvasSize",function(b){d._core.optics.aspect=b.aspect,a(d._core),d._engine.display.imageDirty=!0})}},SceneJS.Camera.getDefaultMatrix=function(){return c},SceneJS.Camera.prototype.setOptics=function(b){var c=this._core;if(b){var d=b.type||c.optics.type||"perspective";if("ortho"==d)c.optics=SceneJS._applyIf(SceneJS_math_ORTHO_OBJ,{type:d,left:b.left,bottom:b.bottom,near:b.near,right:b.right,top:b.top,far:b.far});else if("frustum"==d)c.optics={type:d,left:b.left||-1,bottom:b.bottom||-1,near:b.near||.1,right:b.right||1,top:b.top||1,far:b.far||1e4};else{if("perspective"!=d)throw b.type?SceneJS_error.fatalError(SceneJS.errors.ILLEGAL_NODE_CONFIG,"SceneJS.Camera configuration invalid: optics type not supported - supported types are 'perspective', 'frustum' and 'ortho'"):SceneJS_error.fatalError(SceneJS.errors.ILLEGAL_NODE_CONFIG,"SceneJS.Camera configuration invalid: optics type not specified - supported types are 'perspective', 'frustum' and 'ortho'");c.optics={type:d,fovy:b.fovy||60,aspect:void 0==b.aspect?1:b.aspect,near:b.near||.1,far:b.far||1e4}}}else c.optics={type:"perspective",fovy:60,aspect:1,near:.1,far:1e4};this._core.optics.pan=b.pan,a(this._core),this.publish("matrix",this._core.matrix),this._engine.display.imageDirty=!0},SceneJS.Camera.prototype.setPan=function(b){this._core.pan=b,a(this._core),this.publish("matrix",this._core.matrix),this._engine.display.imageDirty=!0},SceneJS.Camera.prototype.getOptics=function(){var a={};for(var b in this._core.optics)this._core.optics.hasOwnProperty(b)&&(a[b]=this._core.optics[b]);return a},SceneJS.Camera.prototype.getMatrix=function(){return this._core.matrix.slice(0)},SceneJS.Camera.prototype._compile=function(a){this._engine.display.projTransform=e[f++]=this._core,this._compileNodes(a),this._engine.display.projTransform=--f>0?e[f-1]:d},SceneJS.Camera.prototype._destroy=function(){this.getScene().off(this._canvasSizeSub)}}(),function(){var a={type:"clips",stateId:SceneJS._baseStateId++,empty:!0,hash:"",clips:[]},b=[],c=0;SceneJS_events.addListener(SceneJS_events.SCENE_COMPILING,function(b){b.engine.display.clips=a,c=0}),SceneJS.Clips=SceneJS_NodeFactory.createNodeType("clips"),SceneJS.Clips.prototype._init=function(a){if(1==this._core.useCount){var b=a.clips;if(!b)throw SceneJS_error.fatalError(SceneJS.errors.NODE_CONFIG_EXPECTED,"clips node attribute missing : 'clips'");this._core.clips=this._core.clips||[];for(var c=0,d=b.length;d>c;c++)this._setClip(c,b[c])}},SceneJS.Clips.prototype.setClips=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.clips.length)throw SceneJS_error.fatalError(SceneJS.errors.ILLEGAL_NODE_CONFIG,"Invalid argument to set 'clips': index out of range ("+this._core.clips.length+" clips defined)");this._setClip(b,a[c]||{})}this._engine.display.imageDirty=!0},SceneJS.Clips.prototype._setClip=function(a,b){var c=this._core.clips[a]||(this._core.clips[a]={});c.normalAndDist=[b.x||0,b.y||0,b.z||0,b.dist||0];var d=b.mode||c.mode||"disabled";if("inside"!=d&&"outside"!=d&&"disabled"!=d)throw SceneJS_error.fatalError(SceneJS.errors.ILLEGAL_NODE_CONFIG,"clips node invalid value for property 'mode': should be 'inside' or 'outside' or 'disabled'");c.mode=d,this._core.hash=null},SceneJS.Clips.prototype._compile=function(d){this._core.hash||(this._core.hash=this._core.clips.length),this._engine.display.clips=b[c++]=this._core,this._compileNodes(d),this._engine.display.clips=--c>0?b[c-1]:a}}(),function(){var a={stateId:SceneJS._baseStateId++,type:"enable",enabled:!0},b=[],c=0;SceneJS_events.addListener(SceneJS_events.SCENE_COMPILING,function(b){b.engine.display.enable=a,c=0}),SceneJS.Enable=SceneJS_NodeFactory.createNodeType("enable"),SceneJS.Enable.prototype._init=function(a){1==this._core.useCount&&(this._core.enabled=!0,void 0!=a.enabled&&this.setEnabled(a.enabled))},SceneJS.Enable.prototype.setEnabled=function(a){return a!==this._core.enabled&&(this._core.enabled=a,this._engine.display.drawListDirty=!0,this.publish("enabled",a)),this},SceneJS.Enable.prototype.getEnabled=function(){return this._core.enabled},SceneJS.Enable.prototype._compile=function(d){this._engine.display.enable=b[c++]=this._core,this._compileNodes(d),this._engine.display.enable=--c>0?b[c-1]:a}}(),function(){var a={stateId:SceneJS._baseStateId++,type:"flags",picking:!0,clipping:!0,enabled:!0,transparent:!1,backfaces:!0,frontface:"ccw",reflective:!0,hash:"refl"},b=[],c=0;SceneJS_events.addListener(SceneJS_events.SCENE_COMPILING,function(b){b.engine.display.flags=a,c=0}),SceneJS.Flags=SceneJS_NodeFactory.createNodeType("flags"),SceneJS.Flags.prototype._init=function(a){1==this._core.useCount&&(this._core.picking=!0,this._core.clipping=!0,this._core.enabled=!0,this._core.transparent=!1,this._core.backfaces=!0,this._core.frontface="ccw",this._core.reflective=!0,a.flags&&this.setFlags(a.flags))},SceneJS.Flags.prototype.setFlags=function(a){var b=this._core;return void 0!=a.picking&&(b.picking=!!a.picking,this._engine.display.drawListDirty=!0),void 0!=a.clipping&&(b.clipping=!!a.clipping,this._engine.display.imageDirty=!0),void 0!=a.enabled&&(b.enabled=!!a.enabled,this._engine.display.drawListDirty=!0),void 0!=a.transparent&&(b.transparent=!!a.transparent,this._engine.display.stateSortDirty=!0),void 0!=a.backfaces&&(b.backfaces=!!a.backfaces,this._engine.display.imageDirty=!0),void 0!=a.frontface&&(b.frontface=a.frontface,this._engine.display.imageDirty=!0),void 0!=a.reflective&&(b.reflective=a.reflective,b.hash=b.reflective?"refl":"",this._engine.branchDirty(this),this._engine.display.imageDirty=!0),this},SceneJS.Flags.prototype.addFlags=function(a){return this.setFlags(a)},SceneJS.Flags.prototype.getFlags=function(){var a=this._core;return{picking:a.picking,clipping:a.clipping,enabled:a.enabled,transparent:a.transparent,backfaces:a.backfaces,frontface:a.frontface,reflective:a.reflective}},SceneJS.Flags.prototype.setPicking=function(a){return a=!!a,this._core.picking!=a&&(this._core.picking=a,this._engine.display.drawListDirty=!0),this},SceneJS.Flags.prototype.getPicking=function(){return this._core.picking},SceneJS.Flags.prototype.setClipping=function(a){return a=!!a,this._core.clipping!=a&&(this._core.clipping=a,this._engine.display.imageDirty=!0),this},SceneJS.Flags.prototype.getClipping=function(){return this._core.clipping},SceneJS.Flags.prototype.setEnabled=function(a){return a=!!a,this._core.enabled!=a&&(this._core.enabled=a,this._engine.display.drawListDirty=!0),this},SceneJS.Flags.prototype.getEnabled=function(){return this._core.enabled},SceneJS.Flags.prototype.setTransparent=function(a){return a=!!a,this._core.transparent!=a&&(this._core.transparent=a,this._engine.display.stateOrderDirty=!0),this},SceneJS.Flags.prototype.getTransparent=function(){return this._core.transparent},SceneJS.Flags.prototype.setBackfaces=function(a){return a=!!a,this._core.backfaces!=a&&(this._core.backfaces=a,this._engine.display.imageDirty=!0),this},SceneJS.Flags.prototype.getBackfaces=function(){return this._core.backfaces},SceneJS.Flags.prototype.setFrontface=function(a){return this._core.frontface!=a&&(this._core.frontface=a,this._engine.display.imageDirty=!0),this},SceneJS.Flags.prototype.getFrontface=function(){return this._core.frontface},SceneJS.Flags.prototype.setReflective=function(a){return a=!!a,this._core.reflective!=a&&(this._core.reflective=a,this._core.hash=a?"refl":"",this._engine.branchDirty(this),this._engine.display.imageDirty=!0),this},SceneJS.Flags.prototype.getReflective=function(){return this._core.reflective},SceneJS.Flags.prototype._compile=function(d){this._engine.display.flags=b[c++]=this._core,this._compileNodes(d),this._engine.display.flags=--c>0?b[c-1]:a}}(),new function(){var a={type:"renderTarget",stateId:SceneJS._baseStateId++,targets:null},b={},c=[],d=0;SceneJS_events.addListener(SceneJS_events.SCENE_COMPILING,function(b){b.engine.display.renderTarget=a,d=0}),SceneJS_events.addListener(SceneJS_events.WEBGL_CONTEXT_RESTORED,function(){for(var a in b)b.hasOwnProperty(a)&&b[a]._core.renderBuf.webglRestored()}),SceneJS.ColorTarget=SceneJS_NodeFactory.createNodeType("colorTarget"),SceneJS.ColorTarget.prototype._init=function(a){b[this._core.coreId]=this,this._core.bufType="color",this._core.renderBuf=new SceneJS._webgl.RenderBuffer({canvas:this._engine.canvas})},SceneJS.ColorTarget.prototype._compile=function(b){this.__core||(this.__core=this._engine._coreFactory.getCore("renderTarget"));var e=this._engine.display.renderTarget;this._core.empty||(this.__core.targets=e&&e.targets?e.targets.concat([this._core]):[this._core]),c[d++]=this.__core,this._engine.display.renderTarget=this.__core,this._compileNodes(b),this._engine.display.renderTarget=--d>0?c[d-1]:a},SceneJS.ColorTarget.prototype._destroy=function(){this._core&&(this._core.renderBuf&&this._core.renderBuf.destroy(),delete b[this._core.coreId])}},new function(){var a={type:"renderTarget",stateId:SceneJS._baseStateId++,targets:null},b={},c=[],d=0;SceneJS_events.addListener(SceneJS_events.SCENE_COMPILING,function(b){b.engine.display.renderTarget=a,d=0}),SceneJS_events.addListener(SceneJS_events.WEBGL_CONTEXT_RESTORED,function(){for(var a in b)b.hasOwnProperty(a)&&b[a]._buildNodeCore()}),SceneJS.DepthTarget=SceneJS_NodeFactory.createNodeType("depthTarget"),SceneJS.DepthTarget.prototype._init=function(a){b[this._core.coreId]=this,this._core.bufType="depth",this._core.renderBuf=new SceneJS._webgl.RenderBuffer({canvas:this._engine.canvas})},SceneJS.DepthTarget.prototype._compile=function(b){this.__core||(this.__core=this._engine._coreFactory.getCore("renderTarget"));var e=this._engine.display.renderTarget;this._core.empty||(this.__core.targets=e&&e.targets?e.targets.concat([this._core]):[this._core]),c[d++]=this.__core,this._engine.display.renderTarget=this.__core,this._compileNodes(b),this._engine.display.renderTarget=--d>0?c[d-1]:a},SceneJS.DepthTarget.prototype._destroy=function(){this._core&&(this._core.renderBuf&&this._core.renderBuf.destroy(),delete b[this._core.coreId])}},new function(){var a=[],b=0;SceneJS_events.addListener(SceneJS_events.SCENE_COMPILING,function(){b=0}),SceneJS.Geometry=SceneJS_NodeFactory.createNodeType("geometry"),SceneJS.Geometry.prototype._init=function(a){if(1==this._core.useCount){this._initNodeCore(a,{origin:a.origin,scale:a.scale,autoNormals:"auto"==a.normals}),this._buildNodeCore(this._engine.canvas.gl,this._core);var b=this;this._core.webglRestored=function(){b._buildNodeCore(b._engine.canvas.gl,b._core)}}},SceneJS.Geometry.prototype._initNodeCore=function(a,b){var c=this;b=b||{};var d=a.primitive||"triangles",e=this._core,f=this._engine.canvas.UINT_INDEX_ENABLED?Uint32Array:Uint16Array;e.primitive=this._getPrimitiveType(d),a.normals&&"triangles"==d&&("auto"===a.normals||a.normals===!0)&&a.positions&&a.indices&&this._buildNormals(a),e.arrays={positions:a.positions?new Float32Array(b.scale||b.origin?this._applyOptions(a.positions,b):a.positions):void 0,normals:a.normals?new Float32Array(a.normals):void 0,uv:a.uv?new Float32Array(a.uv):void 0,uv2:a.uv2?new Float32Array(a.uv2):void 0,colors:a.colors?new Float32Array(a.colors):void 0,indices:a.indices?new f(a.indices):void 0},delete a.positions,delete a.normals,delete a.uv,delete a.uv2,delete a.indices,delete a.colors,e.getTangentBuf=function(){if(e.tangentBuf)return e.tangentBuf;var a=e.arrays;if(a.positions&&a.indices&&a.uv){var b=c._engine.canvas.gl,d=new Float32Array(c._buildTangents(a));e.arrays.tangents=d;var f=b.STATIC_DRAW;return e.tangentBuf=new SceneJS._webgl.ArrayBuffer(b,b.ARRAY_BUFFER,d,d.length,3,f)}}},SceneJS.Geometry.prototype._getPrimitiveType=function(a){var b=this._engine.canvas.gl;switch(a){case"points":return b.POINTS;case"lines":return b.LINES;case"line-loop":return b.LINE_LOOP;case"line-strip":return b.LINE_STRIP;case"triangles":return b.TRIANGLES;case"triangle-strip":return b.TRIANGLE_STRIP;case"triangle-fan":return b.TRIANGLE_FAN;default:throw SceneJS_error.fatalError(SceneJS.errors.ILLEGAL_NODE_CONFIG,"geometry primitive unsupported: '"+a+"' - supported types are: 'points', 'lines', 'line-loop', 'line-strip', 'triangles', 'triangle-strip' and 'triangle-fan'")}},SceneJS.Geometry.prototype._applyOptions=function(a,b){var c=a.slice?a.slice(0):new Float32Array(a);if(b.scale)for(var d=void 0!=b.scale.x?b.scale.x:1,e=void 0!=b.scale.y?b.scale.y:1,f=void 0!=b.scale.z?b.scale.z:1,g=0,h=c.length;h>g;g+=3)c[g]*=d,c[g+1]*=e,c[g+2]*=f;if(b.origin)for(var i=void 0!=b.origin.x?b.origin.x:0,j=void 0!=b.origin.y?b.origin.y:0,k=void 0!=b.origin.z?b.origin.z:0,g=0,h=c.length;h>g;g+=3)c[g]-=i,c[g+1]-=j,c[g+2]-=k;return c};var c=function(a){a.vertexBuf&&(a.vertexBuf.destroy(),a.vertexBuf=null),a.normalBuf&&(a.normalBuf.destroy(),a.normalBuf=null),a.uvBuf&&(a.uvBuf.destroy(),a.uvBuf=null),a.uvBuf2&&(a.uvBuf2.destroy(),a.uvBuf2=null),a.colorBuf&&(a.colorBuf.destroy(),a.colorBuf=null),a.tangentBuf&&(a.tangentBuf.destroy(),a.tangentBuf=null),a.indexBuf&&(a.indexBuf.destroy(),a.indexBuf=null),a.interleavedBuf&&(a.interleavedBuf.destroy(),a.interleavedBuf=null)};SceneJS.Geometry.prototype._buildNodeCore=function(a,b){var d=a.STATIC_DRAW;try{var e=b.arrays,f=SceneJS.getConfigs("enableInterleaving")!==!1,g=0,h=0,i=[],j=[],k=function(a,b){return 0==g?g=a.length/b:a.length/b!=g&&(f=!1),i.push(a),j.push(b),h+=b,4*(h-b)};if(e.positions&&(f&&(b.interleavedPositionOffset=k(e.positions,3)),b.vertexBuf=new SceneJS._webgl.ArrayBuffer(a,a.ARRAY_BUFFER,e.positions,e.positions.length,3,d)),e.normals&&(f&&(b.interleavedNormalOffset=k(e.normals,3)),b.normalBuf=new SceneJS._webgl.ArrayBuffer(a,a.ARRAY_BUFFER,e.normals,e.normals.length,3,d)),e.uv&&(f&&(b.interleavedUVOffset=k(e.uv,2)),b.uvBuf=new SceneJS._webgl.ArrayBuffer(a,a.ARRAY_BUFFER,e.uv,e.uv.length,2,d)),e.uv2&&(f&&(b.interleavedUV2Offset=k(e.uv2,2)),b.uvBuf2=new SceneJS._webgl.ArrayBuffer(a,a.ARRAY_BUFFER,e.uv2,e.uv2.length,2,d)),e.colors&&(f&&(b.interleavedColorOffset=k(e.colors,4)),b.colorBuf=new SceneJS._webgl.ArrayBuffer(a,a.ARRAY_BUFFER,e.colors,e.colors.length,4,d)),e.indices&&(b.indexBuf=new SceneJS._webgl.ArrayBuffer(a,a.ELEMENT_ARRAY_BUFFER,e.indices,e.indices.length,1,d)),h>0&&f){for(var l=[],m=i.length,n=0;g>n;++n)for(var o=0;m>o;++o)for(var p=j[o],q=0;p>q;++q)l.push(i[o][n*p+q]);b.interleavedStride=4*h,b.interleavedBuf=new SceneJS._webgl.ArrayBuffer(a,a.ARRAY_BUFFER,new Float32Array(l),l.length,h,d),b.interleavedBuf.dirty=!1}}catch(r){throw c(b),SceneJS_error.fatalError(SceneJS.errors.ERROR,"Failed to allocate geometry: "+r)}},SceneJS.Geometry.prototype._updateArray=function(a,b,c){var d=a.length,e=b.length;e+c>d&&(e-=e+c-d);for(var f=c,g=0;e>g;f++,g++)a[f]=b[g]},SceneJS.Geometry.prototype._buildNormals=function(a){for(var b,c,d,e,f,g,h=a.positions,i=a.indices,j=new Array(h.length/3),k=0,l=i.length-3;l>k;k+=3){b=i[k+0],c=i[k+1],d=i[k+2],e=[h[3*b+0],h[3*b+1],h[3*b+2]],f=[h[3*c+0],h[3*c+1],h[3*c+2]],g=[h[3*d+0],h[3*d+1],h[3*d+2]],f=SceneJS_math_subVec4(f,e,[0,0,0,0]),g=SceneJS_math_subVec4(g,e,[0,0,0,0]);var m=SceneJS_math_normalizeVec4(SceneJS_math_cross3Vec4(f,g,[0,0,0,0]),[0,0,0,0]);j[b]||(j[b]=[]),j[c]||(j[c]=[]),j[d]||(j[d]=[]),j[b].push(m),j[c].push(m),j[d].push(m)}for(var n=new Array(h.length),k=0,l=j.length;l>k;k++){for(var o=j[k].length,p=0,q=0,r=0,s=0;o>s;s++)p+=j[k][s][0],q+=j[k][s][1],r+=j[k][s][2];n[3*k+0]=p/o,n[3*k+1]=q/o,n[3*k+2]=r/o}a.normals=n},SceneJS.Geometry.prototype._buildTangents=function(a){for(var b=a.positions,c=a.indices,d=a.uv,e=[],f=0;ft;t++){var u=c[f+t];"undefined"!=typeof e[u]?e[u]=SceneJS_math_addVec3(e[u],s,[]):e[u]=s}}for(var v=[],w=0;wf;f+=3)c=b[f],d=b[f+1],e=b[f+2],cthis._boundary.xmax&&(this._boundary.xmax=c),d>this._boundary.ymax&&(this._boundary.ymax=d),e>this._boundary.zmax&&(this._boundary.zmax=e);return this._boundary},SceneJS.Geometry.prototype._compile=function(c){if(this._core._loading)return void this._compileNodes(c);var d=this._core;d.vertexBuf||(d=this._inheritVBOs(d)),d.indexBuf?(d.hash=[d.normalBuf?"t":"f",d.arrays&&d.arrays.tangents?"t":"f",d.uvBuf?"t":"f",d.uvBuf2?"t":"f",d.colorBuf?"t":"f",d.primitive].join(""),d.stateId=this._core.stateId,d.type="geometry",this._engine.display.geometry=a[b++]=d,SceneJS_events.fireEvent(SceneJS_events.OBJECT_COMPILING,{display:this._engine.display}),this._engine.display.buildObject(this.id)):a[b++]=this._core,this._compileNodes(c),b--},SceneJS.Geometry.prototype._inheritVBOs=function(c){for(var d={primitive:c.primitive,boundary:c.boundary,normalBuf:c.normalBuf,uvBuf:c.uvBuf,uvBuf2:c.uvBuf2,colorBuf:c.colorBuf,interleavedBuf:c.interleavedBuf,indexBuf:c.indexBuf,interleavedStride:c.interleavedStride,interleavedPositionOffset:c.interleavedPositionOffset,interleavedNormalOffset:c.interleavedNormalOffset,interleavedUVOffset:c.interleavedUVOffset,interleavedUV2Offset:c.interleavedUV2Offset,interleavedColorOffset:c.interleavedColorOffset},e=b-1;e>=0;e--)if(a[e].vertexBuf)return d.vertexBuf=a[e].vertexBuf,d.boundary=a[e].boundary,d.normalBuf=a[e].normalBuf,d.uvBuf=a[e].uvBuf,d.uvBuf2=a[e].uvBuf2,d.colorBuf=a[e].colorBuf,d.interleavedBuf=a[e].interleavedBuf,d.interleavedStride=a[e].interleavedStride,d.interleavedPositionOffset=a[e].interleavedPositionOffset,d.interleavedNormalOffset=a[e].interleavedNormalOffset,d.interleavedUVOffset=a[e].interleavedUVOffset,d.interleavedUV2Offset=a[e].interleavedUV2Offset,d.interleavedColorOffset=a[e].interleavedColorOffset,d;return d},SceneJS.Geometry.prototype._destroy=function(){this._engine.display.removeObject(this.id),1==this._core.useCount&&(this._destroyNodeCore(),this._source&&this._source.destroy&&this._source.destroy())},SceneJS.Geometry.prototype._destroyNodeCore=function(){document.getElementById(this._engine.canvas.canvasId)&&c(this._core)}},function(){var a={type:"stage",stateId:SceneJS._baseStateId++,priority:0,pickable:!0,enabled:!0},b=[],c=0;SceneJS_events.addListener(SceneJS_events.SCENE_COMPILING,function(b){b.engine.display.stage=a,c=0}),SceneJS.Stage=SceneJS_NodeFactory.createNodeType("stage"),SceneJS.Stage.prototype._init=function(a){1==this._core.useCount&&(this._core.priority=a.priority||0,this._core.enabled=a.enabled!==!1,this._core.pickable=!!a.pickable)},SceneJS.Stage.prototype.setPriority=function(a){a=a||0,this._core.priority!=a&&(this._core.priority=a,this._engine.display.stateOrderDirty=!0)},SceneJS.Stage.prototype.getPriority=function(){return this._core.priority},SceneJS.Stage.prototype.setEnabled=function(a){a=!!a,this._core.enabled!=a&&(this._core.enabled=a,this._engine.display.drawListDirty=!0)},SceneJS.Stage.prototype.getEnabled=function(){return this._core.enabled},SceneJS.Stage.prototype.getEnabled=function(){return this._core.enabled},SceneJS.Stage.prototype._compile=function(d){this._engine.display.stage=b[c++]=this._core,this._compileNodes(d),this._engine.display.stage=--c>0?b[c-1]:a}}(),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}}(),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}}(),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},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],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.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.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}},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){if(this._sourceConfigs=a.source,this._source=null,a.source){if(!a.source.type)throw SceneJS_error.fatalError(SceneJS.errors.ILLEGAL_NODE_CONFIG,"morphGeometry config expected: source.type");var b=this;SceneJS.Plugins.getPlugin("morphGeometry",this._sourceConfigs.type,function(c){if(!c)throw SceneJS_error.fatalError(SceneJS.errors.PLUGIN_INVALID,"morphGeometry: no support for source type '"+b._sourceConfigs.type+"' - need to include plugin for self source type, or install a custom source service with SceneJS.Plugins.addPlugin(SceneJS.Plugins.MORPH_GEO_SOURCE_PLUGIN, '"+b._sourceConfigs.type+"', ).");if(!c.getSource)throw SceneJS_error.fatalError(SceneJS.errors.PLUGIN_INVALID,"morphGeometry: 'getSource' method not found on MorphGeoFactoryService (SceneJS.Plugins.MORPH_GEO_SOURCE_PLUGIN)");if(b._source=c.getSource(),!b._source.subscribe)throw SceneJS_error.fatalError(SceneJS.errors.PLUGIN_INVALID,"morphGeometry: 'subscribe' method not found on source provided by plugin type '"+a.source.type+"'");var d=!1;b._source.subscribe(function(a){if(d){if(a.targets)for(var c,e,f,g=a.targets,h=b._core.targets,i=0,j=g.length;j>i;i++)c=g[i],e=c.targetIndex,f=h[e],c.positions&&f.vertexBuf&&(f.vertexBuf.bind(),f.vertexBuf.setData(c.positions,0));b._display.imageDirty=!0}else b._buildNodeCore(a),b._core._loading=!1,b._fireEvent("loaded"),b._engine.branchDirty(b),d=!0}),b._core._loading=!0,b._fireEvent("loading"),b._source.configure(b._sourceConfigs)})}else a.create instanceof Function?this._buildNodeCore(a.create()):this._buildNodeCore(a);this._core.webglRestored=function(){},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="Float32Array"==typeof o?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="Float32Array"==typeof o?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="Float32Array"==typeof o?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="Float32Array"==typeof o?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)}},SceneJS.MorphGeometry.prototype.setSource=function(a){this._sourceConfigs=a;var b=this._source;b&&b.configure(a)},SceneJS.MorphGeometry.prototype.getSource=function(){return this._sourceConfigs},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},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){if(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.normalBuf&&a.normalBuf.destroy(),a.uvBuf&&a.uvBuf.destroy(),a.uvBuf2&&a.uvBuf2.destroy();this._source&&this._source.destroy&&this._source.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}}(),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}},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}}(),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,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}}(),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.setSSAAMultiplier=function(a){return this._engine.canvas.setSSAAMultiplier(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.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){return this._engine.readPixels(a,b)},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}}(),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}}(),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=SceneJS_sceneStatusModule.taskStarted(this,"Loading texture"),g=new Image;g.onload=function(){var d=a.createTexture();a.bindTexture(a.TEXTURE_2D,d);var e=SceneJS_configsModule.configs.maxTextureSize;e&&(g=SceneJS._webgl.clampImageSize(g,e)),a.texImage2D(a.TEXTURE_2D,0,a.RGBA,a.RGBA,a.UNSIGNED_BYTE,c._ensureImageSizePowerOfTwo(g)),c._setLayerTexture(a,b,d),SceneJS_sceneStatusModule.taskFinished(f),c._engine.display.imageDirty=!0},g.onerror=function(){SceneJS_sceneStatusModule.taskFailed(f)},0==e.indexOf("data")?g.src=e:(g.crossOrigin="Anonymous",g.src=e)}},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},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){if(b.applyFrom&&"uv"!=b.applyFrom&&"uv2"!=b.applyFrom&&"normal"!=b.applyFrom&&"geometry"!=b.applyFrom)throw SceneJS_error.fatalError(SceneJS.errors.NODE_CONFIG_EXPECTED,"texture applyFrom value is unsupported - should be either 'uv', 'uv2', 'normal' or 'geometry'");if(b.applyTo&&"baseColor"!=b.applyTo&&"color"!=b.applyTo&&"specular"!=b.applyTo&&"emit"!=b.applyTo&&"alpha"!=b.applyTo&&"normals"!=b.applyTo&&"shine"!=b.applyTo)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,applyFrom:b.applyFrom?b.applyFrom:"uv",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._core.src=b.src,this._loadTexture(b.src)):b.image?(this._core.image=b.image,this._initTexture(b.image)):b.target&&this.getScene().getNode(b.target,function(a){c.setTarget(a)}),this._core.webglRestored=function(){c._core.image?c._initTexture(c._core.image):c._core.src?c._loadTexture(c._core.src):c._core.target}}},SceneJS.TextureMap.prototype._loadTexture=function(a){var b=this,c=SceneJS_sceneStatusModule.taskStarted(this,"Loading texture"),d=new Image;d.onload=function(){b._initTexture(d),SceneJS_sceneStatusModule.taskFinished(c),b._engine.display.imageDirty=!0},d.onerror=function(){SceneJS_sceneStatusModule.taskFailed(c)},0==a.indexOf("data")?d.src=a:(d.crossOrigin="Anonymous",d.src=a)},SceneJS.TextureMap.prototype._initTexture=function(a){var b=this._engine.canvas.gl,c=b.createTexture();b.bindTexture(b.TEXTURE_2D,c);var d=SceneJS_configsModule.configs.maxTextureSize;d&&(a=SceneJS._webgl.clampImageSize(a,d)),b.texImage2D(b.TEXTURE_2D,0,b.RGBA,b.RGBA,b.UNSIGNED_BYTE,SceneJS._webgl.ensureImageSizePowerOfTwo(a)),this._core.image=a,this._core.texture=new SceneJS._webgl.Texture2D(b,{texture:c,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._initTexture(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},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)}},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},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)}}(),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,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.cubemap=null,this.modelTransform=null,this.viewTransform=null,this.projTransform=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._drawList=[],this._drawListLen=0,this._pickDrawList=[],this._pickDrawListLen=0,this._targetList=[],this._targetListLen=0,this._frameCtx={pickNames:[],canvas:this._canvas,VAO:null},this._frameCtx.renderListenerCtx=new SceneJS.RenderContext(this._frameCtx), -this.objectListDirty=!0,this.stateOrderDirty=!0,this.stateSortDirty=!0,this.drawListDirty=!0,this.imageDirty=!0,this.pickBufDirty=!0,this.rayPickBufDirty=!0};SceneJS_Display.prototype.webglRestored=function(){this._programFactory.webglRestored(),this._chunkFactory.webglRestored();var a=this._canvas.gl;this.pickBuf&&this.pickBuf.webglRestored(a),this.rayPickBuf&&this.rayPickBuf.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.stage=this.stage,b.layer=this.layer,b.renderTarget=this.renderTarget,b.texture=this.texture,b.cubemap=this.cubemap,b.geometry=this.geometry,b.enable=this.enable,b.flags=this.flags,b.tag=this.tag;var c=[this.geometry.hash,this.shader.hash,this.clips.hash,this.morphGeometry.hash,this.texture.hash,this.cubemap.hash,this.lights.hash,this.flags.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,"name",this.name),this._setChunk(b,12,"lights",this.lights),this._setChunk(b,13,"material",this.material),this._setChunk(b,14,"texture",this.texture),this._setChunk(b,15,"cubemap",this.cubemap),this._setChunk(b,16,"clips",this.clips),this._setChunk(b,17,"renderer",this.renderer),this._setChunk(b,18,"geometry",this.morphGeometry,this.geometry),this._setChunk(b,19,"listeners",this.renderListeners),this._setChunk(b,20,"draw",this.geometry)},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];b&&(this._programFactory.putProgram(b.program),b.program=null,b.hash=null,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)&&(this._doDrawList({clear:a.clear!==!1}),this.imageDirty=!1,this.pickBufDirty=!0)},SceneJS_Display.prototype._buildObjectList=function(){this._objectListLen=0;for(var a in this._objects)this._objects.hasOwnProperty(a)&&(this._objectList[this._objectListLen++]=this._objects[a])},SceneJS_Display.prototype._makeStateSortKeys=function(){for(var a,b=0,c=this._objectListLen;c>b;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||[];for(var a=0;23>a;a++)this._lastStateId[a]=null,this._lastPickStateId[a]=null;this._drawListLen=0,this._pickDrawListLen=0;var b,c,d,e,f,g={},h=[],i=[];this._tagSelector&&(c=this._tagSelector.mask,d=this._tagSelector.regex),this._objectDrawList=this._objectDrawList||[],this._objectDrawListLen=0;for(var a=0,j=this._objectListLen;j>a;a++)if(b=this._objectList[a],b.enable.enabled!==!1&&(f=b.flags,f.enabled!==!1&&b.layer.enabled&&(!c||(e=b.tag,!e.tag||(e.mask!=c&&(e.mask=c,e.matches=d.test(e.tag)),e.matches)))))if(b.renderTarget.targets)for(var k,l,m,n=b.renderTarget.targets,o=0,p=n.length;p>o;o++)k=n[o],l=k.coreId,m=g[l],m||(m=[],g[l]=m,h.push(m),i.push(this._chunkFactory.getChunk(k.stateId,"renderTarget",b.program,k))),m.push(b);else this._objectDrawList[this._objectDrawListLen++]=b;for(var m,k,b,q,a=0,j=h.length;j>a;a++){m=h[a],k=i[a],this._appendRenderTargetChunk(k);for(var o=0,p=m.length;p>o;o++)b=m[o],q=b.stage&&b.stage.pickable,this._appendObjectToDrawLists(b,q)}b&&this._appendRenderTargetChunk(this._chunkFactory.getChunk(-1,"renderTarget",b.program,{}));for(var a=0,j=this._objectDrawListLen;j>a;a++)b=this._objectDrawList[a],q=!b.stage||b.stage&&b.stage.pickable,this._appendObjectToDrawLists(b,q);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=a.flags.picking,f=0,g=d.length;g>f;f++)c=d[f],c&&(c.draw&&(c.unique||this._lastStateId[f]!=c.id)&&(this._drawList[this._drawListLen++]=c,this._lastStateId[f]=c.id),c.pick&&b!==!1&&e&&(c.unique||this._lastPickStateId[f]!=c.id)&&(this._pickDrawList[this._pickDrawListLen++]=c,this._lastPickStateId[f]=c.id))},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("--------------------------------------------------------------------------------------------------")},SceneJS_Display.prototype.pick=function(a){var b=this._canvas.canvas,c=this._canvas.ssaaMultiplier,d=null,e=a.canvasX*c,f=a.canvasY*c,g=this.pickBuf;g||(g=this.pickBuf=new SceneJS._webgl.RenderBuffer({canvas:this._canvas}),this.pickBufDirty=!0),this.render(),g.bind(),this.pickBufDirty&&(g.clear(),this._doDrawList({pick:!0,clear:!0}),this._canvas.gl.finish(),this.pickBufDirty=!1,this.rayPickBufDirty=!0);var h=g.read(e,f),i=h[0]+256*h[1]+65536*h[2],j=i>=1?i-1:-1;g.unbind();var k=this._frameCtx.pickNames[j];if(k&&(d={name:k.name,path:k.path,nodeId:k.nodeId,canvasPos:[e,f]},a.rayPick)){var l=this.rayPickBuf;l||(l=this.rayPickBuf=new SceneJS._webgl.RenderBuffer({canvas:this._canvas}),this.rayPickBufDirty=!0),l.bind(),this.rayPickBufDirty&&(l.clear(),this._doDrawList({pick:!0,rayPick:!0,clear:!0}),this.rayPickBufDirty=!1),h=l.read(e,f),l.unbind();var m=this._unpackDepth(h),n=b.width,o=b.height,p=(e-n/2)/(n/2),q=-(f-o/2)/(o/2),r=this._frameCtx.cameraMat,s=this._frameCtx.viewMat,t=SceneJS_math_mulMat4(r,s,[]),u=SceneJS_math_inverseMat4(t,[]),v=SceneJS_math_transformVector4(u,[p,q,-1,1]);v=SceneJS_math_mulVec4Scalar(v,1/v[3]);var w=SceneJS_math_transformVector4(u,[p,q,1,1]);w=SceneJS_math_mulVec4Scalar(w,1/w[3]);var x=SceneJS_math_subVec3(w,v,[]),y=SceneJS_math_addVec3(v,SceneJS_math_mulVec4Scalar(x,m,[]),[]);d.worldPos=y}return d},SceneJS_Display.prototype.readPixels=function(a,b){this._readPixelBuf||(this._readPixelBuf=new SceneJS._webgl.RenderBuffer({canvas:this._canvas})),this._readPixelBuf.bind(),this._readPixelBuf.clear(),this.render({force:!0});for(var c,d,e=0;b>e;e++)c=a[e]||(a[e]={}),d=this._readPixelBuf.read(c.x,c.y),c.r=d[0],c.g=d[1],c.b=d[2],c.a=d[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._doDrawList=function(a){var b=this._canvas.gl,c=this._frameCtx;c.renderTarget=null,c.targetIndex=0,c.renderBuf=null,c.viewMat=null,c.modelMat=null,c.cameraMat=null,c.renderer=null,c.depthbufEnabled=null,c.clearDepth=null,c.depthFunc=b.LESS,c.scissorTestEnabled=!1,c.blendEnabled=!1,c.backfaces=!0,c.frontface="ccw",c.pick=!!a.pick,c.rayPick=!!a.rayPick,c.pickIndex=0,c.textureUnit=0,c.lineWidth=1,c.transparent=!1,c.ambientColor=this._ambientColor,c.aspect=this._canvas.canvas.width/this._canvas.canvas.height,this._canvas.UINT_INDEX_ENABLED&&b.getExtension("OES_element_index_uint");var d=b.getExtension("OES_vertex_array_object");if(c.VAO=d?d:null,c.VAO=null,b.viewport(0,0,b.drawingBufferWidth,b.drawingBufferHeight),this.transparent?b.clearColor(0,0,0,0):b.clearColor(this._ambientColor[0],this._ambientColor[1],this._ambientColor[2],1),a.clear&&b.clear(b.COLOR_BUFFER_BIT|b.DEPTH_BUFFER_BIT|b.STENCIL_BUFFER_BIT),b.frontFace(b.CCW),b.disable(b.CULL_FACE),b.disable(b.BLEND),a.pick)for(var e=0,f=this._pickDrawListLen;f>e;e++)this._pickDrawList[e].pick(c);else for(var e=0,f=this._drawListLen;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.destroy=function(){this._programFactory.destroy()};var SceneJS_ProgramSourceFactory=new function(){function a(a){if(a.renderTarget&&a.renderTarget.targets)for(var b=a.renderTarget.targets,c=0,d=b.length;d>c;c++)if("depth"===b[c].bufType)return!0;return!1}this._sourceCache={},this.getSource=function(a,b){var c=this._sourceCache[a];return c?(c.useCount++,c):this._sourceCache[a]=new SceneJS_ProgramSource(a,this._composePickingVertexShader(b),this._composePickingFragmentShader(b),this._composeRenderingVertexShader(b),this._composeRenderingFragmentShader(b))},this.putSource=function(a){var b=this._sourceCache[a];b&&0==--b.useCount&&(this._sourceCache[b.hash]=null)},this._composePickingVertexShader=function(a){var b=!!a.morphGeometry.targets,c=["precision mediump float;","attribute vec3 SCENEJS_aVertex;","uniform mat4 SCENEJS_uMMatrix;","uniform mat4 SCENEJS_uVMatrix;","uniform mat4 SCENEJS_uVNMatrix;","uniform mat4 SCENEJS_uPMatrix;"];return c.push("varying vec4 SCENEJS_vWorldVertex;"),c.push("varying vec4 SCENEJS_vViewVertex;"),b&&(c.push("uniform float SCENEJS_uMorphFactor;"),a.morphGeometry.targets[0].vertexBuf&&c.push("attribute vec3 SCENEJS_aMorphVertex;")),c.push("void main(void) {"),c.push(" vec4 tmpVertex=vec4(SCENEJS_aVertex, 1.0); "),b&&a.morphGeometry.targets[0].vertexBuf&&c.push(" tmpVertex = vec4(mix(tmpVertex.xyz, SCENEJS_aMorphVertex, SCENEJS_uMorphFactor), 1.0); "),c.push(" SCENEJS_vWorldVertex = SCENEJS_uMMatrix * tmpVertex; "),c.push(" SCENEJS_vViewVertex = SCENEJS_uVMatrix * SCENEJS_vWorldVertex;"),c.push(" gl_Position = SCENEJS_uPMatrix * SCENEJS_vViewVertex;"),c.push("}"),c},this._composePickingFragmentShader=function(a){var b=a.clips.clips.length>0,c=["precision mediump float;"];if(c.push("varying vec4 SCENEJS_vWorldVertex;"),c.push("varying vec4 SCENEJS_vViewVertex;"),c.push("uniform bool SCENEJS_uRayPickMode;"),c.push("uniform vec3 SCENEJS_uPickColor;"),c.push("uniform float SCENEJS_uZNear;"),c.push("uniform float SCENEJS_uZFar;"),c.push("uniform bool SCENEJS_uClipping;"),b)for(var d=0;d 0.0) { discard; }"),c.push("}")}return c.push(" if (SCENEJS_uRayPickMode) {"),c.push(" float zNormalizedDepth = abs((SCENEJS_uZNear + SCENEJS_vViewVertex.z) / (SCENEJS_uZFar - SCENEJS_uZNear));"),c.push(" gl_FragColor = packDepth(zNormalizedDepth); "),c.push(" } else {"),c.push(" gl_FragColor = vec4(SCENEJS_uPickColor.rgb, 1.0); "),c.push(" }"),c.push("}"),c},this._isTexturing=function(a){if(a.texture.layers&&a.texture.layers.length>0){if(a.geometry.uvBuf||a.geometry.uvBuf2)return!0;if(a.morphGeometry.targets&&(a.morphGeometry.targets[0].uvBuf||a.morphGeometry.targets[0].uvBuf2))return!0}return!1},this._isCubeMapping=function(a){return a.flags.reflective&&a.cubemap.layers&&a.cubemap.layers.length>0&&a.geometry.normalBuf},this._hasNormals=function(a){return a.geometry.normalBuf?!0:a.morphGeometry.targets&&a.morphGeometry.targets[0].normalBuf?!0:!1},this._hasTangents=function(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},this._composeRenderingVertexShader=function(a){var b=a.shader.shaders||{};if(b.vertex&&b.vertex.code&&""!=b.vertex.code&&SceneJS._isEmpty(b.vertex.hooks))return[b.vertex.code];var c=b.vertex||{},d=c.hooks||{},e=b.fragment||{},f=e.hooks||{},g=this._isTexturing(a),h=this._hasNormals(a),i=this._hasTangents(a),j=a.clips.clips.length>0,k=!!a.morphGeometry.targets,l=["precision mediump float;"];if(l.push("uniform mat4 SCENEJS_uMMatrix;"),l.push("uniform mat4 SCENEJS_uVMatrix;"),l.push("uniform mat4 SCENEJS_uPMatrix;"),l.push("attribute vec3 SCENEJS_aVertex;"),l.push("uniform vec3 SCENEJS_uWorldEye;"),l.push("varying vec3 SCENEJS_vViewEyeVec;"),h){l.push("attribute vec3 SCENEJS_aNormal;"),l.push("uniform mat4 SCENEJS_uMNMatrix;"),l.push("uniform mat4 SCENEJS_uVNMatrix;"),l.push("varying vec3 SCENEJS_vViewNormal;"),i&&l.push("attribute vec4 SCENEJS_aTangent;");for(var m=0;m0,k=["\n"];if(k.push("precision mediump float;"),j&&k.push("varying vec4 SCENEJS_vWorldVertex;"),k.push("varying vec4 SCENEJS_vViewVertex;"),k.push("uniform float SCENEJS_uZNear;"),k.push("uniform float SCENEJS_uZFar;"),j)for(var l=0;ll;l++)m=b.texture.layers[l],k.push("uniform sampler2D SCENEJS_uSampler"+l+";"),m.matrix&&k.push("uniform mat4 SCENEJS_uLayer"+l+"Matrix;"),k.push("uniform float SCENEJS_uLayer"+l+"BlendFactor;")}if(h&&g)for(var m,l=0,n=b.cubemap.layers.length;n>l;l++)m=b.cubemap.layers[l],k.push("uniform samplerCube SCENEJS_uCubeMapSampler"+l+";"),k.push("uniform float SCENEJS_uCubeMapIntensity"+l+";");if(k.push("uniform bool SCENEJS_uClipping;"),k.push("uniform bool SCENEJS_uDepthMode;"),k.push("uniform bool SCENEJS_uTransparent;"),b.geometry.colorBuf&&k.push("varying vec4 SCENEJS_vColor;"),k.push("uniform vec3 SCENEJS_uAmbientColor;"),k.push("uniform vec3 SCENEJS_uMaterialColor;"),k.push("uniform float SCENEJS_uMaterialAlpha;"),k.push("uniform float SCENEJS_uMaterialEmit;"),k.push("uniform vec3 SCENEJS_uMaterialSpecularColor;"),k.push("uniform float SCENEJS_uMaterialSpecular;"),k.push("uniform float SCENEJS_uMaterialShine;"),k.push("varying vec3 SCENEJS_vViewEyeVec;"),h){k.push("varying vec3 SCENEJS_vViewNormal;");for(var o,l=0;l 0.0) { discard; }"),k.push("}")}k.push(" vec3 ambient= SCENEJS_uAmbientColor;"),f&&b.geometry.uvBuf&&e.texturePos&&k.push(e.texturePos+"(SCENEJS_vUVCoord);"),e.viewPos&&k.push(e.viewPos+"(SCENEJS_vViewVertex);"),h&&e.viewNormal&&k.push(e.viewNormal+"(SCENEJS_vViewNormal);"),b.geometry.colorBuf?k.push(" vec3 color = SCENEJS_vColor.rgb;"):k.push(" vec3 color = SCENEJS_uMaterialColor;"),k.push(" float alpha = SCENEJS_uMaterialAlpha;"),k.push(" float emit = SCENEJS_uMaterialEmit;"),k.push(" float specular = SCENEJS_uMaterialSpecular;"),k.push(" vec3 specularColor = SCENEJS_uMaterialSpecularColor;"),k.push(" float shine = SCENEJS_uMaterialShine;"),e.materialBaseColor&&k.push("color="+e.materialBaseColor+"(color);"),e.materialAlpha&&k.push("alpha="+e.materialAlpha+"(alpha);"),e.materialEmit&&k.push("emit="+e.materialEmit+"(emit);"),e.materialSpecular&&k.push("specular="+e.materialSpecular+"(specular);"),e.materialSpecularColor&&k.push("specularColor="+e.materialSpecularColor+"(specularColor);"),e.materialShine&&k.push("shine="+e.materialShine+"(shine);"),h&&(k.push(" float attenuation = 1.0;"),i?k.push(" vec3 viewNormalVec = vec3(0.0, 1.0, 0.0);"):k.push(" vec3 viewNormalVec = normalize(SCENEJS_vViewNormal);"));var m;if(f){k.push(" vec4 texturePos;"),k.push(" vec2 textureCoord=vec2(0.0,0.0);");for(var l=0,n=b.texture.layers.length;n>l;l++){if(m=b.texture.layers[l],"normal"==m.applyFrom&&h){if(!b.geometry.normalBuf){SceneJS.log.warn("Texture layer applyFrom='normal' but geo has no normal vectors");continue}k.push("texturePos=vec4(viewNormalVec.xyz, 1.0);")}if("uv"==m.applyFrom){if(!b.geometry.uvBuf){SceneJS.log.warn("Texture layer applyTo='uv' but geometry has no UV coordinates");continue}k.push("texturePos = vec4(SCENEJS_vUVCoord.s, SCENEJS_vUVCoord.t, 1.0, 1.0);")}if("uv2"==m.applyFrom){if(!b.geometry.uvBuf2){SceneJS.log.warn("Texture layer applyTo='uv2' but geometry has no UV2 coordinates");continue}k.push("texturePos = vec4(SCENEJS_vUVCoord2.s, SCENEJS_vUVCoord2.t, 1.0, 1.0);")}m.matrix?k.push("textureCoord=(SCENEJS_uLayer"+l+"Matrix * texturePos).xy;"):k.push("textureCoord=texturePos.xy;"),"alpha"==m.applyTo&&("multiply"==m.blendMode?k.push("alpha = alpha * (SCENEJS_uLayer"+l+"BlendFactor * texture2D(SCENEJS_uSampler"+l+", vec2(textureCoord.x, 1.0 - textureCoord.y)).b);"):"add"==m.blendMode&&k.push("alpha = ((1.0 - SCENEJS_uLayer"+l+"BlendFactor) * alpha) + (SCENEJS_uLayer"+l+"BlendFactor * texture2D(SCENEJS_uSampler"+l+", vec2(textureCoord.x, 1.0 - textureCoord.y)).b);")),"baseColor"==m.applyTo&&("multiply"==m.blendMode?k.push("color = color * (SCENEJS_uLayer"+l+"BlendFactor * texture2D(SCENEJS_uSampler"+l+", vec2(textureCoord.x, 1.0 - textureCoord.y)).rgb);"):k.push("color = ((1.0 - SCENEJS_uLayer"+l+"BlendFactor) * color) + (SCENEJS_uLayer"+l+"BlendFactor * texture2D(SCENEJS_uSampler"+l+", vec2(textureCoord.x, 1.0 - textureCoord.y)).rgb);")),"emit"==m.applyTo&&("multiply"==m.blendMode?k.push("emit = emit * (SCENEJS_uLayer"+l+"BlendFactor * texture2D(SCENEJS_uSampler"+l+", vec2(textureCoord.x, 1.0 - textureCoord.y)).r);"):k.push("emit = ((1.0 - SCENEJS_uLayer"+l+"BlendFactor) * emit) + (SCENEJS_uLayer"+l+"BlendFactor * texture2D(SCENEJS_uSampler"+l+", vec2(textureCoord.x, 1.0 - textureCoord.y)).r);")),"specular"==m.applyTo&&h&&("multiply"==m.blendMode?k.push("specular = specular * (SCENEJS_uLayer"+l+"BlendFactor * texture2D(SCENEJS_uSampler"+l+", vec2(textureCoord.x, 1.0 - textureCoord.y)).r);"):k.push("specular = ((1.0 - SCENEJS_uLayer"+l+"BlendFactor) * specular) + (SCENEJS_uLayer"+l+"BlendFactor * texture2D(SCENEJS_uSampler"+l+", vec2(textureCoord.x, 1.0 - textureCoord.y)).r);")),"shine"==m.applyTo&&("multiply"==m.blendMode?k.push("shine = shine * (SCENEJS_uLayer"+l+"BlendFactor * texture2D(SCENEJS_uSampler"+l+", vec2(textureCoord.x, 1.0 - textureCoord.y)).r);"):k.push("shine = ((1.0 - SCENEJS_uLayer"+l+"BlendFactor) * shine) + (SCENEJS_uLayer"+l+"BlendFactor * texture2D(SCENEJS_uSampler"+l+", vec2(textureCoord.x, 1.0 - textureCoord.y)).r);")),"normals"==m.applyTo&&h&&k.push("viewNormalVec = normalize(texture2D(SCENEJS_uSampler"+l+", vec2(textureCoord.x, -textureCoord.y)).xyz * 2.0 - 1.0);")}}if(h&&g){k.push("vec3 envLookup = reflect(SCENEJS_vViewEyeVec, viewNormalVec);"),k.push("envLookup.y = envLookup.y * -1.0;"),k.push("vec4 envColor;");for(var l=0,n=b.cubemap.layers.length;n>l;l++)m=b.cubemap.layers[l],k.push("envColor = textureCube(SCENEJS_uCubeMapSampler"+l+", envLookup);"),k.push("color = mix(color, envColor.rgb, specular * SCENEJS_uCubeMapIntensity"+l+");")}if(k.push(" vec4 fragColor;"),h){k.push(" vec3 lightValue = vec3(0.0, 0.0, 0.0);"),k.push(" vec3 specularValue = vec3(0.0, 0.0, 0.0);"),k.push(" vec3 viewLightVec;"),k.push(" float dotN;"),k.push(" float lightDist;");for(var o,l=0,n=b.lights.lights.length;n>l;l++)o=b.lights.lights[l],"ambient"!=o.mode&&(k.push("viewLightVec = SCENEJS_vViewLightVecAndDist"+l+".xyz;"),"point"==o.mode&&(k.push("dotN = max(dot(normalize(viewNormalVec), normalize(viewLightVec)), 0.0);"),k.push("lightDist = SCENEJS_vViewLightVecAndDist"+l+".w;"),k.push("attenuation = 1.0 - ( SCENEJS_uLightAttenuation"+l+"[0] + SCENEJS_uLightAttenuation"+l+"[1] * lightDist + SCENEJS_uLightAttenuation"+l+"[2] * lightDist * lightDist);"),o.diffuse&&k.push(" lightValue += dotN * SCENEJS_uLightColor"+l+" * attenuation;"),o.specular&&k.push(" specularValue += specularColor * SCENEJS_uLightColor"+l+" * specular * pow(max(dot(reflect(normalize(-viewLightVec), normalize(-viewNormalVec)), normalize(-SCENEJS_vViewVertex.xyz)), 0.0), shine) * attenuation;")),"dir"==o.mode&&(k.push("dotN = max(dot(normalize(viewNormalVec), normalize(viewLightVec)), 0.0);"),o.diffuse&&k.push(" lightValue += dotN * SCENEJS_uLightColor"+l+";"),o.specular&&k.push("specularValue += specularColor * SCENEJS_uLightColor"+l+" * specular * pow(max(dot(reflect(normalize(-viewLightVec), normalize(-viewNormalVec)), normalize(-SCENEJS_vViewVertex.xyz)), 0.0), shine);")));k.push(" fragColor = vec4((specularValue.rgb + color.rgb * (lightValue.rgb + ambient.rgb)) + (emit * color.rgb), alpha);")}else k.push("fragColor = vec4((color.rgb + (emit * color.rgb)) * (vec3(1.0, 1.0, 1.0) + ambient.rgb), alpha);");return e.pixelColor&&k.push("fragColor="+e.pixelColor+"(fragColor);"),a(b)?(k.push(" if (SCENEJS_uDepthMode) {"),k.push(" float depth = length(SCENEJS_vViewVertex) / (SCENEJS_uZFar - SCENEJS_uZNear);"),k.push(" const vec4 bias = vec4(1.0 / 255.0,"),k.push(" 1.0 / 255.0,"),k.push(" 1.0 / 255.0,"),k.push(" 0.0);"),k.push(" float r = depth;"),k.push(" float g = fract(r * 255.0);"),k.push(" float b = fract(g * 255.0);"),k.push(" float a = fract(b * 255.0);"),k.push(" vec4 colour = vec4(r, g, b, a);"),k.push(" gl_FragColor = colour - (colour.yzww * bias);"),k.push(" } else {"),k.push(" gl_FragColor = fragColor;"),k.push(" };")):k.push(" gl_FragColor = fragColor;"),k.push("}"),k}},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.UINT_INDEX_ENABLED=!!d.getExtension("OES_element_index_uint"),this.draw=null,this.pick=null,this.useCount=0,this.build(d)};SceneJS_Program.prototype.build=function(a){this.drawUniformFlags=0,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){this._freeObjects[this._numFreeObjects++]=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.ssaaMultiplier,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];if(g)return g.useCount++,g;var h=SceneJS_ChunkFactory._freeChunks[b];return h.chunksLen>0&&(g=h.chunks[--h.chunksLen]),g?g.init(a,c,d,e):g=new f(a,c,d,e),g.type=b,g.useCount=1,this._chunks[a]=g,g},SceneJS_ChunkFactory.prototype.putChunk=function(a){if(0!=a.useCount&&--a.useCount<=0){a.recycle&&a.recycle(),delete this._chunks[a.id];var b=SceneJS_ChunkFactory._freeChunks[a.type];b.chunks[b.chunksLen++]=a}},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.getUniformLocation("SCENEJS_uPMatrix"),this._uZNearDraw=this.program.draw.getUniformLocation("SCENEJS_uZNear"),this._uZFarDraw=this.program.draw.getUniformLocation("SCENEJS_uZFar"),this._uPMatrixPick=this.program.pick.getUniformLocation("SCENEJS_uPMatrix"),this._uZNearPick=this.program.pick.getUniformLocation("SCENEJS_uZNear"),this._uZFarPick=this.program.pick.getUniformLocation("SCENEJS_uZFar")},draw:function(a){this.core.checkAspect&&this.core.checkAspect(this.core,a.aspect);var b=this.program.gl;this._uPMatrixDraw&&b.uniformMatrix4fv(this._uPMatrixDraw,b.FALSE,this.core.mat),this._uZNearDraw&&b.uniform1f(this._uZNearDraw,this.core.optics.near),this._uZFarDraw&&b.uniform1f(this._uZFarDraw,this.core.optics.far),a.cameraMat=this.core.mat},pick:function(a){this.core.checkAspect&&this.core.checkAspect(this.core,a.aspect);var b=this.program.gl;this._uPMatrixPick&&b.uniformMatrix4fv(this._uPMatrixPick,b.FALSE,this.core.mat),a.rayPick&&(this._uZNearPick&&b.uniform1f(this._uZNearPick,this.core.optics.near),this._uZFarPick&&b.uniform1f(this._uZFarPick,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.getUniformLocation("SCENEJS_uClipMode"+b),uClipNormalAndDist:a.getUniformLocation("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.getUniformLocation("SCENEJS_uClipMode"+b),uClipNormalAndDist:d.getUniformLocation("SCENEJS_uClipNormalAndDist"+b)}},drawAndPick:function(a){for(var b,c,d,e=a.pick?this._pick:this._draw,f=this.core.clips,g=this.program.gl,h=0,i=f.length;i>h;h++)a.pick?(b=e[h].uClipMode,c=e[h].uClipNormalAndDist):(b=e[h].uClipMode,c=e[h].uClipNormalAndDist),b&&c&&(d=f[h],"inside"==d.mode?(g.uniform1f(b,2),g.uniform4fv(c,d.normalAndDist)):"outside"==d.mode?(g.uniform1f(b,1),g.uniform4fv(c,d.normalAndDist)):g.uniform1f(b,0))}}),SceneJS_ChunkFactory.createChunkType({type:"draw",unique:!0,build:function(){this._depthModeDraw=this.program.draw.getUniformLocation("SCENEJS_uDepthMode"),this._depthModePick=this.program.pick.getUniformLocation("SCENEJS_uDepthMode")},drawAndPick:function(a){var b=this.program.gl,c=this.program.UINT_INDEX_ENABLED?b.UNSIGNED_INT:b.UNSIGNED_SHORT;b.uniform1i(a.pick?this._depthModePick:this._depthModeDraw,a.depthMode),b.drawElements(this.core.primitive,this.core.indexBuf.numItems,c,0)}}),SceneJS_ChunkFactory.createChunkType({type:"flags",build:function(){var a=this.program.draw;this._uClippingDraw=a.getUniformLocation("SCENEJS_uClipping");var b=this.program.pick;this._uClippingPick=b.getUniformLocation("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=this.core.transparent;if(a.transparent!=e&&(a.pick||(e?(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=e),a.pick)b.uniform1i(this._uClippingPick,this.core.clipping);else{var f=this.core.clipping?1:0;this.program.drawUniformFlags!=f&&(b.uniform1i(this._uClippingDraw,this.core.clipping),this.program.drawUniformFlags=f)}}}),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._aVertexDraw=a.getAttribute("SCENEJS_aVertex"),this._aNormalDraw=a.getAttribute("SCENEJS_aNormal"),this._aUVDraw=a.getAttribute("SCENEJS_aUVCoord"),this._aUV2Draw=a.getAttribute("SCENEJS_aUVCoord2"),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._uMorphFactorDraw=a.getUniformLocation("SCENEJS_uMorphFactor");var b=this.program.pick;this._aVertexPick=b.getAttribute("SCENEJS_aVertex"),this._aMorphVertexPick=b.getAttribute("SCENEJS_aMorphVertex"),this._uMorphFactorPick=b.getUniformLocation("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(){this.VAOMorphKey1=this.core.key1,this.VAOMorphKey2=this.core.key2;var a=this.core.targets[this.core.key1],b=this.core.targets[this.core.key2];this._aMorphVertexDraw?(this._aVertexDraw.bindFloatArrayBuffer(a.vertexBuf),this._aMorphVertexDraw.bindFloatArrayBuffer(b.vertexBuf)):this._aVertexDraw&&this._aVertexDraw.bindFloatArrayBuffer(this.core2.vertexBuf),this._aMorphNormalDraw?(this._aNormalDraw.bindFloatArrayBuffer(a.normalBuf),this._aMorphNormalDraw.bindFloatArrayBuffer(b.normalBuf)):this._aNormalDraw&&this._aNormalDraw.bindFloatArrayBuffer(this.core2.normalBuf),this._aUVDraw&&this._aUVDraw.bindFloatArrayBuffer(this.core2.uvBuf),this._aUV2Draw&&this._aUV2Draw.bindFloatArrayBuffer(this.core2.uvBuf2),this._aColorDraw&&this._aColorDraw.bindFloatArrayBuffer(this.core2.colorBuf),this.setDrawMorphFactor()},setDrawMorphFactor:function(){this._uMorphFactorDraw&&this.program.gl.uniform1f(this._uMorphFactorDraw,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){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 if(a.VAO){a.VAO.bindVertexArrayOES(null),this.VAO=a.VAO.createVertexArrayOES(),a.VAO.bindVertexArrayOES(this.VAO);this.program.gl}b?this.morphDraw():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),this._aUVDraw&&this._aUVDraw.bindInterleavedFloatArrayBuffer(2,this.core2.interleavedStride,this.core2.interleavedUVOffset),this._aUV2Draw&&this._aUV2Draw.bindInterleavedFloatArrayBuffer(2,this.core2.interleavedStride,this.core2.interleavedUV2Offset),this._aColorDraw&&this._aColorDraw.bindInterleavedFloatArrayBuffer(4,this.core2.interleavedStride,this.core2.interleavedColorOffset),this._aTangentDraw&&this._aTangentDraw.bindFloatArrayBuffer(this.core2.tangentBuf||this.core2.getTangentBuf())):(this.VAOHasInterleavedBuf=!1,this._aVertexDraw&&this._aVertexDraw.bindFloatArrayBuffer(this.core2.vertexBuf),this._aNormalDraw&&this._aNormalDraw.bindFloatArrayBuffer(this.core2.normalBuf),this._aUVDraw&&this._aUVDraw.bindFloatArrayBuffer(this.core2.uvBuf),this._aUV2Draw&&this._aUV2Draw.bindFloatArrayBuffer(this.core2.uvBuf2),this._aColorDraw&&this._aColorDraw.bindFloatArrayBuffer(this.core2.colorBuf),this._aTangentDraw&&this._aTangentDraw.bindFloatArrayBuffer(this.core2.tangentBuf||this.core2.getTangentBuf())),this.core2.indexBuf.bind()},morphPick:function(){var a=this.core.targets[this.core.key1],b=this.core.targets[this.core.key2];this._aMorphVertexPick?(this._aVertexPick.bindFloatArrayBuffer(a.vertexBuf),this._aMorphVertexPick.bindFloatArrayBuffer(b.vertexBuf)):this._aVertexPick&&this._aVertexPick.bindFloatArrayBuffer(this.core2.vertexBuf),this._uMorphFactorPick&&this.program.gl.uniform1f(this._uMorphFactorPick,this.core.factor)},pick:function(a){this.core.targets&&this.core.targets.length?this.morphPick():this._aVertexPick&&this._aVertexPick.bindFloatArrayBuffer(this.core2.vertexBuf),this.core2.indexBuf.bind()}}),SceneJS_ChunkFactory.createChunkType({type:"lights",build:function(){this._uAmbientColor=this._uAmbientColor||[],this._uLightColor=this._uLightColor||[],this._uLightDir=this._uLightDir||[],this._uLightPos=this._uLightPos||[],this._uLightCutOff=this._uLightCutOff||[],this._uLightSpotExp=this._uLightSpotExp||[],this._uLightAttenuation=this._uLightAttenuation||[];for(var a=this.core.lights,b=this.program,c=0,d=a.length;d>c;c++)switch(a[c].mode){case"ambient":this._uAmbientColor[c]=b.draw.getUniformLocation("SCENEJS_uAmbientColor");break;case"dir":this._uLightColor[c]=b.draw.getUniformLocation("SCENEJS_uLightColor"+c),this._uLightPos[c]=null,this._uLightDir[c]=b.draw.getUniformLocation("SCENEJS_uLightDir"+c);break;case"point":this._uLightColor[c]=b.draw.getUniformLocation("SCENEJS_uLightColor"+c),this._uLightPos[c]=b.draw.getUniformLocation("SCENEJS_uLightPos"+c),this._uLightDir[c]=null,this._uLightAttenuation[c]=b.draw.getUniformLocation("SCENEJS_uLightAttenuation"+c)}},draw:function(a){a.dirty&&this.build();for(var b,c=this.core.lights,d=this.program.gl,e=0,f=c.length;f>e;e++)b=c[e],this._uAmbientColor[e]?d.uniform3fv(this._uAmbientColor[e],b.color):(this._uLightColor[e]&&d.uniform3fv(this._uLightColor[e],b.color),this._uLightPos[e]&&(d.uniform3fv(this._uLightPos[e],b.pos),this._uLightAttenuation[e]&&d.uniform3fv(this._uLightAttenuation[e],b.attenuation)),this._uLightDir[e]&&d.uniform3fv(this._uLightDir[e],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.getUniformLocation("SCENEJS_uVMatrix"),this._uVNMatrixDraw=this.program.draw.getUniformLocation("SCENEJS_uVNMatrix"),this._uWorldEyeDraw=this.program.draw.getUniformLocation("SCENEJS_uWorldEye"),this._uvMatrixPick=this.program.pick.getUniformLocation("SCENEJS_uVMatrix")},draw:function(a){this.core.dirty&&this.core.rebuild();var b=this.program.gl;this._uvMatrixDraw&&b.uniformMatrix4fv(this._uvMatrixDraw,b.FALSE,this.core.mat),this._uVNMatrixDraw&&b.uniformMatrix4fv(this._uVNMatrixDraw,b.FALSE,this.core.normalMat),this._uWorldEyeDraw&&b.uniform3fv(this._uWorldEyeDraw,this.core.lookAt.eye),a.viewMat=this.core.mat},pick:function(a){var b=this.program.gl;this._uvMatrixPick&&b.uniformMatrix4fv(this._uvMatrixPick,b.FALSE,this.core.mat),a.viewMat=this.core.mat}}),SceneJS_ChunkFactory.createChunkType({type:"material",build:function(){var a=this.program.draw;this._uMaterialBaseColor=a.getUniformLocation("SCENEJS_uMaterialColor"),this._uMaterialSpecularColor=a.getUniformLocation("SCENEJS_uMaterialSpecularColor"),this._uMaterialSpecular=a.getUniformLocation("SCENEJS_uMaterialSpecular"),this._uMaterialShine=a.getUniformLocation("SCENEJS_uMaterialShine"),this._uMaterialEmit=a.getUniformLocation("SCENEJS_uMaterialEmit"),this._uMaterialAlpha=a.getUniformLocation("SCENEJS_uMaterialAlpha")},draw:function(){var a=this.program.gl,b=this.program.draw.materialSettings;this._uMaterialBaseColor&&a.uniform3fv(this._uMaterialBaseColor,this.core.baseColor),!this._uMaterialSpecularColor||b.specularColor[0]==this.core.specularColor[0]&&b.specularColor[1]==this.core.specularColor[1]&&b.specularColor[2]==this.core.specularColor[2]||(a.uniform3fv(this._uMaterialSpecularColor,this.core.specularColor),b.specularColor[0]=this.core.specularColor[0],b.specularColor[1]=this.core.specularColor[1],b.specularColor[2]=this.core.specularColor[2]),this._uMaterialSpecular&&b.specular!=this.core.specular&&(a.uniform1f(this._uMaterialSpecular,this.core.specular),b.specular=this.core.specular),this._uMaterialShine&&b.shine!=this.core.shine&&(a.uniform1f(this._uMaterialShine,this.core.shine),b.shine=this.core.shine),this._uMaterialEmit&&b.emit!=this.core.emit&&(a.uniform1f(this._uMaterialEmit,this.core.emit),b.emit=this.core.emit),this._uMaterialAlpha&&b.alpha!=this.core.alpha&&(a.uniform1f(this._uMaterialAlpha,this.core.alpha),b.alpha=this.core.alpha)}}),SceneJS_ChunkFactory.createChunkType({type:"name",build:function(){this._uPickColor=this.program.pick.getUniformLocation("SCENEJS_uPickColor")},pick:function(a){if(this._uPickColor&&this.core.name){a.pickNames[a.pickIndex++]=this.core;var b=a.pickIndex>>16&255,c=a.pickIndex>>8&255,d=255&a.pickIndex;this.program.gl.uniform3fv(this._uPickColor,[d/255,c/255,b/255])}}}),SceneJS_ChunkFactory.createChunkType({type:"program",build:function(){this._depthModeDraw=this.program.draw.getUniformLocation("SCENEJS_uDepthMode"),this._depthModePick=this.program.pick.getUniformLocation("SCENEJS_uDepthMode"),this._rayPickMode=this.program.pick.getUniformLocation("SCENEJS_uRayPickMode")},draw:function(a){var b=this.program.draw;b.bind(),a.textureUnit=0;var c=this.program.gl;if(c.uniform1i(this._depthModeDraw,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;c.uniform1i(this._rayPickMode,a.rayPick),c.uniform1i(this._depthModePick,a.depthMode),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:"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.pick?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.pick?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;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++),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));a.textureUnit>10&&(a.textureUnit=0)}}),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++),this._uCubeMapIntensity[e]&&this._uCubeMapIntensity[e].setValue(c.intensity));a.textureUnit>10&&(a.textureUnit=0)}}),SceneJS_ChunkFactory.createChunkType({type:"xform",build:function(){var a=this.program.draw;this._uMatLocationDraw=a.getUniformLocation("SCENEJS_uMMatrix"),this._uNormalMatLocationDraw=a.getUniformLocation("SCENEJS_uMNMatrix");var b=this.program.pick;this._uMatLocationPick=b.getUniformLocation("SCENEJS_uMMatrix")},draw:function(a){(SceneJS_configsModule.configs.forceXFormCoreRebuild===!0||this.core.dirty&&this.core.build)&&this.core.build();var b=this.program.gl;this._uMatLocationDraw&&b.uniformMatrix4fv(this._uMatLocationDraw,b.FALSE,this.core.mat),this._uNormalMatLocationDraw&&b.uniformMatrix4fv(this._uNormalMatLocationDraw,b.FALSE,this.core.normalMat),a.modelMat=this.core.mat},pick:function(a){this.core.dirty&&this.core.build();var b=this.program.gl;this._uMatLocationPick&&b.uniformMatrix4fv(this._uMatLocationPick,b.FALSE,this.core.mat),a.modelMat=this.core.mat}}); \ No newline at end of file +this.numItems=d,this.itemSize=e,this.usage=f,this._allocate(c,d)},SceneJS._webgl.ArrayBuffer.prototype._allocate=function(a,b){if(this.allocated=!1,this.handle=this.gl.createBuffer(),!this.handle)throw SceneJS_error.fatalError(SceneJS.errors.OUT_OF_VRAM,"Failed to allocate WebGL ArrayBuffer");this.handle&&(this.gl.bindBuffer(this.type,this.handle),this.gl.bufferData(this.type,a,this.usage),this.gl.bindBuffer(this.type,null),this.numItems=b,this.length=a.length,this.allocated=!0)},SceneJS._webgl.ArrayBuffer.prototype.setData=function(a,b){this.allocated&&(a.length>this.length?(this.destroy(),this._allocate(a,a.length)):b||0===b?this.gl.bufferSubData(this.type,b,a):this.gl.bufferData(this.type,a))},SceneJS._webgl.ArrayBuffer.prototype.unbind=function(){this.allocated&&this.gl.bindBuffer(this.type,null)},SceneJS._webgl.ArrayBuffer.prototype.destroy=function(){this.allocated&&(this.gl.deleteBuffer(this.handle),this.handle=null,this.allocated=!1)},SceneJS._webgl.ArrayBuffer.prototype.bind=function(){this.allocated&&this.gl.bindBuffer(this.type,this.handle)},SceneJS._webgl.Attribute=function(a,b,c,d,e,f){this.gl=a,this.location=f,this.bindFloatArrayBuffer=function(b){b&&(b.bind(),a.enableVertexAttribArray(f),a.vertexAttribPointer(f,b.itemSize,a.FLOAT,!1,0,0))}},SceneJS._webgl.Attribute.prototype.bindInterleavedFloatArrayBuffer=function(a,b,c){this.gl.enableVertexAttribArray(this.location),this.gl.vertexAttribPointer(this.location,a,this.gl.FLOAT,!1,b,c)},SceneJS._webgl.enumMap={funcAdd:"FUNC_ADD",funcSubtract:"FUNC_SUBTRACT",funcReverseSubtract:"FUNC_REVERSE_SUBTRACT",zero:"ZERO",one:"ONE",srcColor:"SRC_COLOR",oneMinusSrcColor:"ONE_MINUS_SRC_COLOR",dstColor:"DST_COLOR",oneMinusDstColor:"ONE_MINUS_DST_COLOR",srcAlpha:"SRC_ALPHA",oneMinusSrcAlpha:"ONE_MINUS_SRC_ALPHA",dstAlpha:"DST_ALPHA",oneMinusDstAlpha:"ONE_MINUS_DST_ALPHA",contantColor:"CONSTANT_COLOR",oneMinusConstantColor:"ONE_MINUS_CONSTANT_COLOR",constantAlpha:"CONSTANT_ALPHA",oneMinusConstantAlpha:"ONE_MINUS_CONSTANT_ALPHA",srcAlphaSaturate:"SRC_ALPHA_SATURATE",front:"FRONT",back:"BACK",frontAndBack:"FRONT_AND_BACK",never:"NEVER",less:"LESS",equal:"EQUAL",lequal:"LEQUAL",greater:"GREATER",notequal:"NOTEQUAL",gequal:"GEQUAL",always:"ALWAYS",cw:"CW",ccw:"CCW",linear:"LINEAR",nearest:"NEAREST",linearMipMapNearest:"LINEAR_MIPMAP_NEAREST",nearestMipMapNearest:"NEAREST_MIPMAP_NEAREST",nearestMipMapLinear:"NEAREST_MIPMAP_LINEAR",linearMipMapLinear:"LINEAR_MIPMAP_LINEAR",repeat:"REPEAT",clampToEdge:"CLAMP_TO_EDGE",mirroredRepeat:"MIRRORED_REPEAT",alpha:"ALPHA",rgb:"RGB",rgba:"RGBA",luminance:"LUMINANCE",luminanceAlpha:"LUMINANCE_ALPHA",textureBinding2D:"TEXTURE_BINDING_2D",textureBindingCubeMap:"TEXTURE_BINDING_CUBE_MAP",compareRToTexture:"COMPARE_R_TO_TEXTURE",unsignedByte:"UNSIGNED_BYTE"},SceneJS._webgl.RenderBuffer=function(a){this.allocated=!1,this.canvas=a.canvas,this.gl=a.canvas.gl,this.buf=null,this.bound=!1},SceneJS._webgl.RenderBuffer.prototype.webglRestored=function(a){this.gl=a,this.buf=null,this.allocated=!1,this.bound=!1},SceneJS._webgl.RenderBuffer.prototype.bind=function(){this._touch(),this.bound||(this.gl.bindFramebuffer(this.gl.FRAMEBUFFER,this.buf.framebuf),this.bound=!0)},SceneJS._webgl.RenderBuffer.prototype._touch=function(){var a=this.canvas.canvas.width,b=this.canvas.canvas.height;if(this.buf){if(this.buf.width==a&&this.buf.height==b)return;this.gl.deleteTexture(this.buf.texture),this.gl.deleteFramebuffer(this.buf.framebuf),this.gl.deleteRenderbuffer(this.buf.renderbuf)}this.buf={framebuf:this.gl.createFramebuffer(),renderbuf:this.gl.createRenderbuffer(),texture:this.gl.createTexture(),width:a,height:b},this.gl.bindFramebuffer(this.gl.FRAMEBUFFER,this.buf.framebuf),this.gl.bindTexture(this.gl.TEXTURE_2D,this.buf.texture),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_MAG_FILTER,this.gl.NEAREST),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_MIN_FILTER,this.gl.NEAREST),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_WRAP_S,this.gl.CLAMP_TO_EDGE),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_WRAP_T,this.gl.CLAMP_TO_EDGE);try{this.gl.texImage2D(this.gl.TEXTURE_2D,0,this.gl.RGBA,a,b,0,this.gl.RGBA,this.gl.UNSIGNED_BYTE,null)}catch(c){var d=new WebGLUnsignedByteArray(a*b*3);this.gl.texImage2D(this.gl.TEXTURE_2D,0,this.gl.RGBA,a,b,0,this.gl.RGBA,this.gl.UNSIGNED_BYTE,d)}if(this.gl.bindRenderbuffer(this.gl.RENDERBUFFER,this.buf.renderbuf),this.gl.renderbufferStorage(this.gl.RENDERBUFFER,this.gl.DEPTH_COMPONENT16,a,b),this.gl.framebufferTexture2D(this.gl.FRAMEBUFFER,this.gl.COLOR_ATTACHMENT0,this.gl.TEXTURE_2D,this.buf.texture,0),this.gl.framebufferRenderbuffer(this.gl.FRAMEBUFFER,this.gl.DEPTH_ATTACHMENT,this.gl.RENDERBUFFER,this.buf.renderbuf),this.gl.bindTexture(this.gl.TEXTURE_2D,null),this.gl.bindRenderbuffer(this.gl.RENDERBUFFER,null),this.gl.bindFramebuffer(this.gl.FRAMEBUFFER,null),this.gl.bindFramebuffer(this.gl.FRAMEBUFFER,this.buf.framebuf),!this.gl.isFramebuffer(this.buf.framebuf))throw SceneJS_error.fatalError(SceneJS.errors.INVALID_FRAMEBUFFER,"Invalid framebuffer");var e=this.gl.checkFramebufferStatus(this.gl.FRAMEBUFFER);switch(e){case this.gl.FRAMEBUFFER_COMPLETE:break;case this.gl.FRAMEBUFFER_INCOMPLETE_ATTACHMENT:throw SceneJS_error.fatalError(SceneJS.errors.ERROR,"Incomplete framebuffer: FRAMEBUFFER_INCOMPLETE_ATTACHMENT");case this.gl.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:throw SceneJS_error.fatalError(SceneJS.errors.ERROR,"Incomplete framebuffer: FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT");case this.gl.FRAMEBUFFER_INCOMPLETE_DIMENSIONS:throw SceneJS_error.fatalError(SceneJS.errors.ERROR,"Incomplete framebuffer: FRAMEBUFFER_INCOMPLETE_DIMENSIONS");case this.gl.FRAMEBUFFER_UNSUPPORTED:throw SceneJS_error.fatalError(SceneJS.errors.ERROR,"Incomplete framebuffer: FRAMEBUFFER_UNSUPPORTED");default:throw SceneJS_error.fatalError(SceneJS.errors.ERROR,"Incomplete framebuffer: "+e)}this.bound=!1},SceneJS._webgl.RenderBuffer.prototype.clear=function(){if(!this.bound)throw"Render buffer not bound";this.gl.clear(this.gl.COLOR_BUFFER_BIT|this.gl.DEPTH_BUFFER_BIT),this.gl.disable(this.gl.BLEND)},SceneJS._webgl.RenderBuffer.prototype.read=function(a,b){var c=a,d=this.canvas.canvas.height-b,e=new Uint8Array(4);return this.gl.readPixels(c,d,1,1,this.gl.RGBA,this.gl.UNSIGNED_BYTE,e),e},SceneJS._webgl.RenderBuffer.prototype.unbind=function(){this.gl.bindFramebuffer(this.gl.FRAMEBUFFER,null),this.bound=!1},SceneJS._webgl.RenderBuffer.prototype.getTexture=function(){var a=this;return{bind:function(b){return a.buf&&a.buf.texture?(a.gl.activeTexture(a.gl["TEXTURE"+b]),a.gl.bindTexture(a.gl.TEXTURE_2D,a.buf.texture),!0):!1},unbind:function(b){a.buf&&a.buf.texture&&(a.gl.activeTexture(a.gl["TEXTURE"+b]),a.gl.bindTexture(a.gl.TEXTURE_2D,null))}}},SceneJS._webgl.RenderBuffer.prototype.destroy=function(){this.buf&&(this.gl.deleteTexture(this.buf.texture),this.gl.deleteFramebuffer(this.buf.framebuf),this.gl.deleteRenderbuffer(this.buf.renderbuf),this.buf=null,this.bound=!1)},SceneJS._webgl.Program=function(a,b,c){this.allocated=!1,this.gl=a,this._uniforms={},this._samplers={},this._attributes={},this.uniformValues=[],this.materialSettings={specularColor:[0,0,0],specular:0,shine:0,emit:0,alpha:0},this._shaders=[];var d,e,f,g,h,i;for(e=0;ee;++e)f=a.getActiveUniform(this.handle,e),f&&(g=f.name,"\x00"==g[g.length-1]&&(g=g.substr(0,g.length-1)),h=a.getUniformLocation(this.handle,g),f.type==a.SAMPLER_2D||f.type==a.SAMPLER_CUBE||35682==f.type?this._samplers[g]=new SceneJS._webgl.Sampler(a,this.handle,g,f.type,f.size,h):(this._uniforms[g]=new SceneJS._webgl.Uniform(a,this.handle,g,f.type,f.size,h,k),this.uniformValues[k]=null,++k));var l=a.getProgramParameter(this.handle,a.ACTIVE_ATTRIBUTES);for(e=0;l>e;e++)d=a.getActiveAttrib(this.handle,e),d&&(h=a.getAttribLocation(this.handle,d.name),this._attributes[d.name]=new SceneJS._webgl.Attribute(a,this.handle,d.name,d.type,d.size,h));this.allocated=!0}},SceneJS._webgl.Program.prototype.bind=function(){this.allocated&&this.gl.useProgram(this.handle)},SceneJS._webgl.Program.prototype.getUniformLocation=function(a){if(this.allocated){var b=this._uniforms[a];return b?b.getLocation():void 0}},SceneJS._webgl.Program.prototype.getUniform=function(a){if(this.allocated){var b=this._uniforms[a];return b?b:void 0}},SceneJS._webgl.Program.prototype.getAttribute=function(a){if(this.allocated){var b=this._attributes[a];return b?b:void 0}},SceneJS._webgl.Program.prototype.bindFloatArrayBuffer=function(a,b){if(this.allocated){var c=this._attributes[a];c&&c.bindFloatArrayBuffer(b)}},SceneJS._webgl.Program.prototype.bindTexture=function(a,b,c){if(!this.allocated)return!1;var d=this._samplers[a];return d?d.bindTexture(b,c):!1},SceneJS._webgl.Program.prototype.destroy=function(){if(this.allocated){this.gl.deleteProgram(this.handle);for(var a in this._shaders)this.gl.deleteShader(this._shaders[a].handle);this.handle=null,this._attributes=null,this._uniforms=null,this._samplers=null,this.allocated=!1}},SceneJS._webgl.Program.prototype.setUniform=function(a,b){if(this.allocated){var c=this._uniforms[a];c&&(this.uniformValues[c.index]===b&&c.numberValue||(c.setValue(b),this.uniformValues[c.index]=b))}},SceneJS._webgl.Sampler=function(a,b,c,d,e,f){this.bindTexture=function(b,c){return b.bind(c)?(a.uniform1i(f,c),!0):!1}},SceneJS._webgl.Shader=function(a,b,c){if(this.allocated=!1,this.handle=a.createShader(b),!this.handle)throw SceneJS_error.fatalError(SceneJS.errors.OUT_OF_VRAM,"Failed to create WebGL shader");if(a.shaderSource(this.handle,c),a.compileShader(this.handle),this.valid=0!=a.getShaderParameter(this.handle,a.COMPILE_STATUS),!this.valid&&!a.isContextLost()){SceneJS.log.error("Shader program failed to compile: "+a.getShaderInfoLog(this.handle)),SceneJS.log.error("Shader source:");for(var d=c.split("\n"),e=0;eb){var d=b/c,e=a.width*d,f=a.height*d,g=document.createElement("canvas");g.width=SceneJS._webgl.nextHighestPowerOfTwo(e),g.height=SceneJS._webgl.nextHighestPowerOfTwo(f);var h=g.getContext("2d");h.drawImage(a,0,0,a.width,a.height,0,0,g.width,g.height),a=g}return a},SceneJS._webgl.ensureImageSizePowerOfTwo=function(a){if(!SceneJS._webgl.isPowerOfTwo(a.width)||!SceneJS._webgl.isPowerOfTwo(a.height)){var b=document.createElement("canvas");b.width=SceneJS._webgl.nextHighestPowerOfTwo(a.width),b.height=SceneJS._webgl.nextHighestPowerOfTwo(a.height);var c=b.getContext("2d");c.drawImage(a,0,0,a.width,a.height,0,0,b.width,b.height),a=b}return a},SceneJS._webgl.isPowerOfTwo=function(a){return 0==(a&a-1)},SceneJS._webgl.nextHighestPowerOfTwo=function(a){--a;for(var b=1;32>b;b<<=1)a|=a>>b;return a+1},SceneJS._webgl.Uniform=function(a,b,c,d,e,f,g,h){var i=null,j=null;if(d===a.BOOL)i=function(b){j!==b&&(j=b,a.uniform1i(f,b))};else if(d===a.BOOL_VEC2)i=function(b){(null===j||j[0]!==b[0]||j[1]!==b[1])&&(j=b,a.uniform2iv(f,b))};else if(d===a.BOOL_VEC3)i=function(b){(null===j||j[0]!==b[0]||j[1]!==b[1]||j[2]!==b[2])&&(j=b,a.uniform3iv(f,b))};else if(d===a.BOOL_VEC4)i=function(b){(null===j||j[0]!==b[0]||j[1]!==b[1]||j[2]!==b[2]||j[3]!==b[3])&&(j=b,a.uniform4iv(f,b))};else if(d===a.INT)i=function(b){j!==b&&(j=b,a.uniform1iv(f,b))};else if(d===a.INT_VEC2)i=function(b){(null===j||j[0]!==b[0]||j[1]!==b[1])&&(j=b,a.uniform2iv(f,b))};else if(d===a.INT_VEC3)i=function(b){(null===j||j[0]!==b[0]||j[1]!==b[1]||j[2]!==b[2])&&(j=b,a.uniform3iv(f,b))};else if(d===a.INT_VEC4)i=function(b){(null===j||j[0]!==b[0]||j[1]!==b[1]||j[2]!==b[2]||j[3]!==b[3])&&(j=b,a.uniform4iv(f,b))};else if(d===a.FLOAT)i=function(b){j!==b&&(j=b,a.uniform1f(f,b))};else if(d===a.FLOAT_VEC2)i=function(b){(null===j||j[0]!==b[0]||j[1]!==b[1])&&(j=b,a.uniform2fv(f,b))};else if(d===a.FLOAT_VEC3)i=function(b){(null===j||j[0]!==b[0]||j[1]!==b[1]||j[2]!==b[2])&&(j=b,a.uniform3fv(f,b))};else if(d===a.FLOAT_VEC4)i=function(b){(null===j||j[0]!==b[0]||j[1]!==b[1]||j[2]!==b[2]||j[3]!==b[3])&&(j=b,a.uniform4fv(f,b))};else if(d===a.FLOAT_MAT2)i=function(b){a.uniformMatrix2fv(f,a.FALSE,b)};else if(d===a.FLOAT_MAT3)i=function(b){a.uniformMatrix3fv(f,a.FALSE,b)};else{if(d!==a.FLOAT_MAT4)throw"Unsupported shader uniform type: "+d;i=function(b){a.uniformMatrix4fv(f,a.FALSE,b)}}this.setValue=i,this.getLocation=function(){return f},this.index=g};var SceneJS_nodeEventsModule=new function(){var a,b=[],c=[],d=0,e={type:"listeners",stateId:SceneJS._baseStateId++,empty:!0,listeners:[]};SceneJS_events.addListener(SceneJS_events.SCENE_COMPILING,function(){d=0,a=!0}),SceneJS_events.addListener(SceneJS_events.OBJECT_COMPILING,function(f){if(a){if(d>0){var g={type:"listeners",stateId:b[d-1],listeners:c.slice(0,d)};f.display.renderListeners=g}else f.display.renderListeners=e;a=!1}}),this.preVisitNode=function(e){var f=e._topicSubs.rendered,g=e._topicSubs.worldPos,h=e._topicSubs.viewPos,i=e._topicSubs.cameraPos,j=e._topicSubs.projPos,k=e._topicSubs.canvasPos;(f||g||h||i||j||k)&&(b[d]=e.id,c[d]=function(a){f&&e.publish("rendered",a,!0),g&&e.publish("worldPos",a.getWorldPos()),h&&e.publish("viewPos",a.getViewPos()),i&&e.publish("cameraPos",a.getCameraPos()),j&&e.publish("projPos",a.getProjPos()),k&&e.publish("canvasPos",a.getCanvasPos())},d++,a=!0)},this.postVisitNode=function(c){c.id==b[d-1]&&(d--,a=!0)}},SceneJS_Core=function(a){this.type=a,this.coreId=null,this.stateId=null,this.useCount=0},SceneJS_CoreFactory=function(){this._stateMap=new SceneJS_Map(null,SceneJS._baseStateId),this._cores={}};SceneJS_CoreFactory.coreTypes={},SceneJS_CoreFactory.createCoreType=function(a,b){},SceneJS_CoreFactory.addCoreBuilder=function(a,b){},SceneJS_CoreFactory.coreAliases={rotate:"xform",translate:"xform",scale:"xform",matrix:"xform",xform:"xform"},SceneJS_CoreFactory.prototype.getCore=function(a,b){var c=SceneJS_CoreFactory.coreAliases[a];c&&(a=c);var d=this._cores[a];d||(d=this._cores[a]={});var e;return b&&(e=d[b])?(e.useCount++,e):(e=new SceneJS_Core(a),e.useCount=1,e.stateId=this._stateMap.addItem(e),e.coreId=void 0!=b&&null!=b?b:e.stateId,d[e.coreId]=e,e)},SceneJS_CoreFactory.prototype.hasCore=function(a,b){var c=SceneJS_CoreFactory.coreAliases[a];c&&(a=c);var d=this._cores[a];return d&&d[b]},SceneJS_CoreFactory.prototype.putCore=function(a){if(0!=a.useCount&&--a.useCount<=0){var b=this._cores[a.type];delete b[a.coreId],this._stateMap.removeItem(a.stateId)}},SceneJS_CoreFactory.prototype.webglRestored=function(){var a,b;for(var c in this._cores)if(this._cores.hasOwnProperty(c)&&(a=this._cores[c]))for(var d in a)a.hasOwnProperty(d)&&(b=a[d],b&&b.webglRestored&&b.webglRestored())},SceneJS.Node=function(){},SceneJS.Node.prototype.constructor=SceneJS.Node,SceneJS.Node.prototype._construct=function(a,b,c,d){this._engine=a,this._core=b,this.coreId=b.coreId,this.id=c.id||c.nodeId||d,this.type=c.type||"node",this.data=c.data,this.parent=null,this.nodes=[],this._handleMap=new SceneJS_Map,this._topicSubs={},this._handleTopics={},this._topicPubs={},this._listeners={},this._numListeners=0,this.dirty=!1,this.branchDirty=!1,this._init&&this._init(c)},SceneJS.Node.prototype.taskStarted=function(a){return SceneJS_sceneStatusModule.taskStarted(this,a||"Task")},SceneJS.Node.prototype.taskFinished=function(a){return SceneJS_sceneStatusModule.taskFinished(a)},SceneJS.Node.prototype.taskFailed=function(a){return SceneJS_sceneStatusModule.taskFailed(a)},SceneJS.Node.prototype.log=function(){var a,b;switch(1==arguments.length?(a="info",b=arguments[0]):2==arguments.length&&(a=arguments[0],b=arguments[1]),a){case"warn":b="WARN; [SceneJS.Node type="+this.type+", id="+this.id+"] : "+b;break;case"error":b="ERROR; [SceneJS.Node type="+this.type+", id="+this.id+"] : "+b;break;default:b="INFO; [SceneJS.Node type="+this.type+", id="+this.id+"] : "+b}console[a]?console[a](b):console.log(b)},SceneJS.Node.prototype.publish=function(a,b,c){if(c||(this._topicPubs[a]=b),this._topicSubs[a]){var d=this._topicSubs[a];for(var e in d)d.hasOwnProperty(e)&&d[e].call(this,b)}},SceneJS.Node.prototype.unpublish=function(a){var b=this._topicSubs[a];if(b)for(var c in b)b.hasOwnProperty(c)&&b[c].call(this,null);delete this._topicPubs[a]},SceneJS.Node.prototype.on=function(a,b){var c=this._topicSubs[a];c||(c={},this._topicSubs[a]=c);var d=this._handleMap.addItem();c[d]=b,this._handleTopics[d]=a;var e=this._topicPubs[a];return e&&b.call(this,e),"rendered"==a&&this._engine.branchDirty(this),d},SceneJS.Node.prototype.off=function(a){var b=this._handleTopics[a];if(b){delete this._handleTopics[a];var c=this._topicSubs[b];c&&delete c[a],this._handleMap.removeItem(a),"rendered"==b&&this._engine.branchDirty(this)}},SceneJS.Node.prototype.once=function(a,b){var c=this,d=this.on(a,function(a){c.off(d),b(a)})},SceneJS.Node.prototype.getScene=function(){return this._engine.scene},SceneJS.Node.prototype.getCoreId=function(){return this._core.coreId},SceneJS.Node.prototype.getID=function(){return this.id},SceneJS.Node.prototype.getId=function(){return this.id},SceneJS.Node.prototype.getNodeId=function(){return this.id},SceneJS.Node.prototype.getType=function(){return this.type},SceneJS.Node.prototype.getData=function(){return this.data},SceneJS.Node.prototype.setData=function(a){return this.data=a,this},SceneJS.Node.prototype.getNumNodes=function(){return this.nodes.length},SceneJS.Node.prototype.getNodes=function(){return this.nodes.slice(0)},SceneJS.Node.prototype.getNodeAt=function(a){return 0>a||a>=this.nodes.length?null:this.nodes[a]},SceneJS.Node.prototype.getFirstNode=function(){return 0==this.nodes.length?null:this.nodes[0]},SceneJS.Node.prototype.getLastNode=function(){return 0==this.nodes.length?null:this.nodes[this.nodes.length-1]},SceneJS.Node.prototype.getNode=function(a){for(var b=0;b0?(b[0].parent=null,this._engine.display.objectListDirty=!0,b[0]):null},SceneJS.Node.prototype.disconnect=function(){if(this.parent){for(var a=0;ab;b++)this.nodes[b].parent=null;var c=this.nodes;return this.nodes=[],this._engine.display.objectListDirty=!0,c},SceneJS.Node.prototype.removeNodes=function(){for(var a=this.disconnectNodes(),b=0;ba;a++)d[a].parent=this.parent;for(a=0,b=c.nodes.length;b>a;a++)if(c.nodes[a]===this)return c.nodes.splice.apply(c.nodes,[a,1].concat(d)),this.nodes=[],this.parent=null,this.destroy(),this._engine.branchDirty(c),c},SceneJS.Node.prototype.addNodes=function(a,b){if(!a)throw SceneJS_error.fatalError(SceneJS.errors.ILLEGAL_NODE_CONFIG,"Node#addNodes - nodes argument is undefined");for(var c,d=[],e=a.length,f=a.length-1;f>=0;f--){var g=a[f];if("node"==g.type||this._engine.hasNodeType(g.type)){if(c=this.addNode(g),d[f]=c,0==--e)return b&&b(a),a}else{var h=this;!function(){var c=f;h.addNode(g,function(f){d[c]=f,0==--e&&b&&b(a)})}()}}return null},SceneJS.Node.prototype.addNode=function(a,b){if(a=a||{},a._compile){if(null!=a.parent)throw SceneJS_error.fatalError(SceneJS.errors.ILLEGAL_NODE_CONFIG,"Node#addNode - node argument is still attached to another parent");return this.nodes.push(a),a.parent=this,this._engine.branchDirty(a),b&&b(a),a}if("string"==typeof a){var c=this._engine.findNode(a);if(!c)throw SceneJS_error.fatalError(SceneJS.errors.ILLEGAL_NODE_CONFIG,"Node#addNode - node not found: '"+a+"'");if(a=c,null!=a.parent)throw SceneJS_error.fatalError(SceneJS.errors.ILLEGAL_NODE_CONFIG,"Node#addNode - node argument is still attached to another parent");return this.nodes.push(a),a.parent=this,this._engine.branchDirty(a),b&&b(a),a}if(a.type=a.type||"node","node"==a.type||this._engine.hasNodeType(a.type))return a=this._engine.createNode(a),this.nodes.push(a),a.parent=this,this._engine.branchDirty(a),b&&b(a),a;var d=this;return this._engine.createNode(a,function(a){d.nodes.push(a),a.parent=d,d._engine.branchDirty(a),b&&b(a)}),null},SceneJS.Node.prototype.insertNode=function(a,b){if(!a)throw SceneJS_error.fatalError(SceneJS.errors.ILLEGAL_NODE_CONFIG,"SceneJS.Node#insertNode - node argument is undefined");if(a._compile||(a=this._engine.createNode(a)),!a._compile)throw SceneJS_error.fatalError(SceneJS.errors.ILLEGAL_NODE_CONFIG,"SceneJS.Node#insertNode - node argument is not a SceneJS.Node");if(null!=a.parent)throw SceneJS_error.fatalError(SceneJS.errors.ILLEGAL_NODE_CONFIG,"SceneJS.Node#insertNode - node argument is still attached to another parent");if(void 0===b||null===b)a.addNodes(this.disconnectNodes()),this.addNode(a);else{if(0>b)throw SceneJS_error.fatalError(SceneJS.errors.ILLEGAL_NODE_CONFIG,"SceneJS.Node#insertNode - node index out of range: -1");b>=this.nodes.length?this.nodes.push(a):this.nodes.splice(b,0,a)}return a.parent=this,a},SceneJS.Node.prototype.mapNodes=function(a){if(a(this))return this;for(var b,c=0;cg;g++)e=d[g],e.options.scope?e.fn.call(e.options.scope,f):e.fn.call(this,f)}},SceneJS.Node.prototype.removeListener=function(a,b){var c=this._listeners[a];if(!c)return null;for(var d=0;d0},SceneJS.Node.prototype.removeListeners=function(){return this._listeners={},this._numListeners=0,this},SceneJS.Node.prototype.getParent=function(a){return this.parent},SceneJS.Node.prototype.getParentOfType=function(a){for(var b=this.parent;b&&b.type!=a;)b=b.parent;return b},SceneJS.Node.prototype.eachParent=function(a){if(!a)throw"SceneJS.Node.eachParent param 'fn' is null or undefined";for(var b=0,c=this;c.parent;){if(a.call(c.parent,b++)===!0)return c.parent;c=c.parent}return null},SceneJS.Node.prototype.hasNode=function(a){if(null===a||void 0===a)throw"SceneJS.Node.hasNode param 'node' is null or undefined";var b,c=typeof a;if("number"==c)b=this.getNodeAt(a);else{if("string"!=c)throw"SceneJS.Node.hasNode param 'node' should be either an index number or an ID string";b=this.getNode(a)}return void 0!=b&&null!=b},SceneJS.Node.prototype.node=function(a){if(null===a||void 0===a)throw"SceneJS.Node.node param 'node' is null or undefined";var b,c=typeof a;if("number"==c)b=this.getNodeAt(a);else{if("string"!=c)throw"SceneJS.Node.node param 'node' should be either an index number or an ID string";b=this.getNode(a)}if(!b)throw"SceneJS.Node.node - node not found: '"+a+"'";return b},SceneJS.Node.prototype.eachNode=function(a,b){if(!a)throw"SceneJS.Node.eachNode param 'fn' is null or undefined";if("function"!=typeof a)throw"SceneJS.Node.eachNode param 'fn' should be a function";var c;b=b||{};var d=0;return b.andSelf&&a.call(this,d++)===!0?this:(b.depthFirst||b.breadthFirst?b.depthFirst&&(c=this._iterateEachNodeDepthFirst(a,this,d,!1)):c=this._iterateEachNode(a,this,d),c?c:void 0)},SceneJS.Node.prototype.numNodes=function(){return this.nodes.length},SceneJS.Node.prototype._iterateEachNode=function(a,b,c){for(var d,e=b.nodes.length,f=0;e>f;f++)if(d=b.nodes[f],a.call(d,c++)===!0)return d;return null},SceneJS.Node.prototype._iterateEachNodeDepthFirst=function(a,b,c,d){if(d&&a.call(b,c++)===!0)return b;d=!0;for(var e,f=b.nodes.length,g=0;f>g;g++)if(e=this._iterateEachNodeDepthFirst(a,b.nodes[g],c,d))return e;return null},SceneJS.Node.prototype.findNodesByType=function(a,b){return this._findNodesByType(a,[],b)},SceneJS.Node.prototype._findNodesByType=function(a,b,c){var d;for(d=0;dd;d++)c=this.nodes[d],c.branchDirty=c.branchDirty||this.branchDirty,(c.dirty||c.branchDirty||this._engine.sceneDirty)&&(c._compile(a),c.dirty=!1,c.branchDirty=!1);b&&SceneJS_nodeEventsModule.postVisitNode(this)},SceneJS.Node.prototype.destroy=function(){if(!this.destroyed){if(this.parent)for(var a=0;aa;a++)this.nodes[a]._destroyTree()},SceneJS.Node.prototype._doDestroy=function(){return this._destroy&&this._destroy(),this},SceneJS_PubSubProxy=function(a,b){this.scene=a,this.proxy=b};var SceneJS_NodeFactory=function(){this.nodes=new SceneJS_Map({})};SceneJS_NodeFactory.nodeTypes={},SceneJS_NodeFactory._subs={},SceneJS_NodeFactory.createNodeType=function(a,b,c){if(SceneJS_NodeFactory.nodeTypes[a])throw"Node type already defined: "+a;var d=function(){SceneJS.Node.apply(this,arguments),this.type=a};d.prototype=new SceneJS.Node,d.prototype.constructor=d,SceneJS_NodeFactory.nodeTypes[a]=d;var e=SceneJS_NodeFactory.nodeTypes[a];if(!e)throw"Node type plugin did not install itself correctly";c&&c(d);var f=SceneJS_NodeFactory._subs[a];if(f){for(;f.length>0;)f.pop()(e);delete f[a]}return d},SceneJS_NodeFactory.prototype.getNode=function(a,b,c,d){b.type=b.type||"node";var e;if(e="node"==b.type?SceneJS.Node:SceneJS_NodeFactory.nodeTypes[b.type])return this._createNode(e,a,b,c,d);var f=this;this._getType(a,b.type,function(e){f._createNode(e,a,b,c,d)})},SceneJS_NodeFactory.prototype._createNode=function(a,b,c,d,e){var f=new a,g=c.id||c.nodeId;return g?this.nodes.addItem(g,f):g=this.nodes.addItem(f),f._construct(b,d,c,g),e&&e(f),f},SceneJS_NodeFactory.prototype._getType=function(a,b,c){var d=SceneJS_NodeFactory.nodeTypes[b];if(d)return void c(d);var e=SceneJS_NodeFactory._subs[b]||(SceneJS_NodeFactory._subs[b]=[]);if(e.push(c),!(e.length>1)){var f=SceneJS_sceneStatusModule.taskStarted(a.scene,"Loading plugin");e.push(function(){SceneJS_sceneStatusModule.taskFinished(f)});var g=SceneJS_configsModule.configs.pluginPath; +if(!g)throw"no typePath config";this._loadScript(g+"/node/"+b+".js",function(){SceneJS_sceneStatusModule.taskFailed(f)})}},SceneJS_NodeFactory.prototype._loadScript=function(a,b){var c=document.createElement("script");c.type="text/javascript",c.src=a,c.onerror=b,document.getElementsByTagName("head")[0].appendChild(c)},SceneJS_NodeFactory.prototype.putNode=function(a){this.nodes.removeItem(a.id)},function(){function a(a){var b=a.optics;if("ortho"==b.type?a.matrix=SceneJS_math_orthoMat4c(b.left,b.right,b.bottom,b.top,b.near,b.far):"frustum"==b.type?a.matrix=SceneJS_math_frustumMatrix4(b.left,b.right,b.bottom,b.top,b.near,b.far):"perspective"==b.type&&(a.matrix=SceneJS_math_perspectiveMatrix4(b.fovy*Math.PI/180,b.aspect,b.near,b.far)),a.pan){var c=a.pan,d=SceneJS_math_translationMat4v([c.x||0,c.y||0,c.z||0]);a.matrix=SceneJS_math_mulMat4(d,a.matrix,[])}a.mat?a.mat.set(a.matrix):a.mat=new Float32Array(a.matrix)}var b=SceneJS_math_perspectiveMatrix4(45,1,.1,1e4),c=new Float32Array(b),d={type:"camera",stateId:SceneJS._baseStateId++,matrix:b,mat:c,optics:{type:"perspective",fovy:45,aspect:1,near:.1,far:1e4},checkAspect:function(b,c){b.optics.aspect!=c&&(b.optics.aspect=c,a(this))}},e=[],f=0;SceneJS_events.addListener(SceneJS_events.SCENE_COMPILING,function(a){a.engine.display.projTransform=d,f=0}),SceneJS.Camera=SceneJS_NodeFactory.createNodeType("camera"),SceneJS.Camera.prototype._init=function(b){if(1==this._core.useCount){b.optics=b.optics||{};var c=this.getScene().getCanvas();b.optics.aspect=c.width/c.height,this.setOptics(b.optics),b.pan&&this.setPan(b.pan);var d=this;this._canvasSizeSub=this.getScene().on("canvasSize",function(b){d._core.optics.aspect=b.aspect,a(d._core),d._engine.display.imageDirty=!0})}},SceneJS.Camera.getDefaultMatrix=function(){return c},SceneJS.Camera.prototype.setOptics=function(b){var c=this._core;if(b){var d=b.type||c.optics.type||"perspective";if("ortho"==d)c.optics=SceneJS._applyIf(SceneJS_math_ORTHO_OBJ,{type:d,left:b.left,bottom:b.bottom,near:b.near,right:b.right,top:b.top,far:b.far});else if("frustum"==d)c.optics={type:d,left:b.left||-1,bottom:b.bottom||-1,near:b.near||.1,right:b.right||1,top:b.top||1,far:b.far||1e4};else{if("perspective"!=d)throw b.type?SceneJS_error.fatalError(SceneJS.errors.ILLEGAL_NODE_CONFIG,"SceneJS.Camera configuration invalid: optics type not supported - supported types are 'perspective', 'frustum' and 'ortho'"):SceneJS_error.fatalError(SceneJS.errors.ILLEGAL_NODE_CONFIG,"SceneJS.Camera configuration invalid: optics type not specified - supported types are 'perspective', 'frustum' and 'ortho'");c.optics={type:d,fovy:b.fovy||60,aspect:void 0==b.aspect?1:b.aspect,near:b.near||.1,far:b.far||1e4}}}else c.optics={type:"perspective",fovy:60,aspect:1,near:.1,far:1e4};this._core.optics.pan=b.pan,a(this._core),this.publish("matrix",this._core.matrix),this._engine.display.imageDirty=!0},SceneJS.Camera.prototype.setPan=function(b){this._core.pan=b,a(this._core),this.publish("matrix",this._core.matrix),this._engine.display.imageDirty=!0},SceneJS.Camera.prototype.getOptics=function(){var a={};for(var b in this._core.optics)this._core.optics.hasOwnProperty(b)&&(a[b]=this._core.optics[b]);return a},SceneJS.Camera.prototype.getMatrix=function(){return this._core.matrix.slice(0)},SceneJS.Camera.prototype._compile=function(a){this._engine.display.projTransform=e[f++]=this._core,this._compileNodes(a),this._engine.display.projTransform=--f>0?e[f-1]:d},SceneJS.Camera.prototype._destroy=function(){this.getScene().off(this._canvasSizeSub)}}(),function(){var a={type:"clips",stateId:SceneJS._baseStateId++,empty:!0,hash:"",clips:[]},b=[],c=0;SceneJS_events.addListener(SceneJS_events.SCENE_COMPILING,function(b){b.engine.display.clips=a,c=0}),SceneJS.Clips=SceneJS_NodeFactory.createNodeType("clips"),SceneJS.Clips.prototype._init=function(a){if(1==this._core.useCount){var b=a.clips;if(!b)throw SceneJS_error.fatalError(SceneJS.errors.NODE_CONFIG_EXPECTED,"clips node attribute missing : 'clips'");this._core.clips=this._core.clips||[];for(var c=0,d=b.length;d>c;c++)this._setClip(c,b[c])}},SceneJS.Clips.prototype.setClips=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.clips.length)throw SceneJS_error.fatalError(SceneJS.errors.ILLEGAL_NODE_CONFIG,"Invalid argument to set 'clips': index out of range ("+this._core.clips.length+" clips defined)");this._setClip(b,a[c]||{})}this._engine.display.imageDirty=!0},SceneJS.Clips.prototype._setClip=function(a,b){var c=this._core.clips[a]||(this._core.clips[a]={});c.normalAndDist=[b.x||0,b.y||0,b.z||0,b.dist||0];var d=b.mode||c.mode||"disabled";if("inside"!=d&&"outside"!=d&&"disabled"!=d)throw SceneJS_error.fatalError(SceneJS.errors.ILLEGAL_NODE_CONFIG,"clips node invalid value for property 'mode': should be 'inside' or 'outside' or 'disabled'");c.mode=d,this._core.hash=null},SceneJS.Clips.prototype._compile=function(d){this._core.hash||(this._core.hash=this._core.clips.length),this._engine.display.clips=b[c++]=this._core,this._compileNodes(d),this._engine.display.clips=--c>0?b[c-1]:a}}(),function(){var a={stateId:SceneJS._baseStateId++,type:"enable",enabled:!0},b=[],c=0;SceneJS_events.addListener(SceneJS_events.SCENE_COMPILING,function(b){b.engine.display.enable=a,c=0}),SceneJS.Enable=SceneJS_NodeFactory.createNodeType("enable"),SceneJS.Enable.prototype._init=function(a){1==this._core.useCount&&(this._core.enabled=!0,void 0!=a.enabled&&this.setEnabled(a.enabled))},SceneJS.Enable.prototype.setEnabled=function(a){return a!==this._core.enabled&&(this._core.enabled=a,this._engine.display.drawListDirty=!0,this.publish("enabled",a)),this},SceneJS.Enable.prototype.getEnabled=function(){return this._core.enabled},SceneJS.Enable.prototype._compile=function(d){this._engine.display.enable=b[c++]=this._core,this._compileNodes(d),this._engine.display.enable=--c>0?b[c-1]:a}}(),function(){var a={stateId:SceneJS._baseStateId++,type:"flags",picking:!0,clipping:!0,enabled:!0,transparent:!1,backfaces:!0,frontface:"ccw",reflective:!0,solid:!1,hash:"refl;;"},b=[],c=0;SceneJS_events.addListener(SceneJS_events.SCENE_COMPILING,function(b){b.engine.display.flags=a,c=0}),SceneJS.Flags=SceneJS_NodeFactory.createNodeType("flags"),SceneJS.Flags.prototype._init=function(a){1==this._core.useCount&&(this._core.picking=!0,this._core.clipping=!0,this._core.enabled=!0,this._core.transparent=!1,this._core.backfaces=!0,this._core.frontface="ccw",this._core.reflective=!0,this._core.solid=!1,a.flags&&this.setFlags(a.flags))},SceneJS.Flags.prototype.setFlags=function(a){var b=this._core;return void 0!=a.picking&&(b.picking=!!a.picking,this._engine.display.drawListDirty=!0),void 0!=a.clipping&&(b.clipping=!!a.clipping,this._engine.display.imageDirty=!0),void 0!=a.enabled&&(b.enabled=!!a.enabled,this._engine.display.drawListDirty=!0),void 0!=a.transparent&&(b.transparent=!!a.transparent,this._engine.display.stateSortDirty=!0),void 0!=a.backfaces&&(b.backfaces=!!a.backfaces,this._engine.display.imageDirty=!0),void 0!=a.frontface&&(b.frontface=a.frontface,this._engine.display.imageDirty=!0),void 0!=a.reflective&&(b.reflective=a.reflective,b.hash=b.reflective?"refl":"",this._engine.branchDirty(this),this._engine.display.imageDirty=!0),void 0!=a.solid&&(b.solid=a.solid,b.hash=b.reflective?"refl":"",this._engine.branchDirty(this),this._engine.display.imageDirty=!0),this},SceneJS.Flags.prototype.addFlags=function(a){return this.setFlags(a)},SceneJS.Flags.prototype.getFlags=function(){var a=this._core;return{picking:a.picking,clipping:a.clipping,enabled:a.enabled,transparent:a.transparent,backfaces:a.backfaces,frontface:a.frontface,reflective:a.reflective,solid:a.solid}},SceneJS.Flags.prototype.setPicking=function(a){return a=!!a,this._core.picking!=a&&(this._core.picking=a,this._engine.display.drawListDirty=!0),this},SceneJS.Flags.prototype.getPicking=function(){return this._core.picking},SceneJS.Flags.prototype.setClipping=function(a){return a=!!a,this._core.clipping!=a&&(this._core.clipping=a,this._engine.display.imageDirty=!0),this},SceneJS.Flags.prototype.getClipping=function(){return this._core.clipping},SceneJS.Flags.prototype.setEnabled=function(a){return a=!!a,this._core.enabled!=a&&(this._core.enabled=a,this._engine.display.drawListDirty=!0),this},SceneJS.Flags.prototype.getEnabled=function(){return this._core.enabled},SceneJS.Flags.prototype.setTransparent=function(a){return a=!!a,this._core.transparent!=a&&(this._core.transparent=a,this._engine.display.stateOrderDirty=!0),this},SceneJS.Flags.prototype.getTransparent=function(){return this._core.transparent},SceneJS.Flags.prototype.setBackfaces=function(a){return a=!!a,this._core.backfaces!=a&&(this._core.backfaces=a,this._engine.display.imageDirty=!0),this},SceneJS.Flags.prototype.getBackfaces=function(){return this._core.backfaces},SceneJS.Flags.prototype.setFrontface=function(a){return this._core.frontface!=a&&(this._core.frontface=a,this._engine.display.imageDirty=!0),this},SceneJS.Flags.prototype.getFrontface=function(){return this._core.frontface},SceneJS.Flags.prototype.setReflective=function(a){return a=!!a,this._core.reflective!=a&&(this._core.reflective=a,this._core.hash=(a?"refl":"")+this._core.solid?";s":";;",this._engine.branchDirty(this),this._engine.display.imageDirty=!0),this},SceneJS.Flags.prototype.getReflective=function(){return this._core.reflective},SceneJS.Flags.prototype.setSolid=function(a){return a=!!a,this._core.solid!=a&&(this._core.solid=a,this._core.hash=(this._core.reflective?"refl":"")+a?";s;":";;",this._engine.branchDirty(this),this._engine.display.imageDirty=!0),this},SceneJS.Flags.prototype.getSolid=function(){return this._core.solid},SceneJS.Flags.prototype._compile=function(d){this._engine.display.flags=b[c++]=this._core,this._compileNodes(d),this._engine.display.flags=--c>0?b[c-1]:a}}(),new function(){var a={type:"renderTarget",stateId:SceneJS._baseStateId++,targets:null},b={},c=[],d=0;SceneJS_events.addListener(SceneJS_events.SCENE_COMPILING,function(b){b.engine.display.renderTarget=a,d=0}),SceneJS_events.addListener(SceneJS_events.WEBGL_CONTEXT_RESTORED,function(){for(var a in b)b.hasOwnProperty(a)&&b[a]._core.renderBuf.webglRestored()}),SceneJS.ColorTarget=SceneJS_NodeFactory.createNodeType("colorTarget"),SceneJS.ColorTarget.prototype._init=function(a){b[this._core.coreId]=this,this._core.bufType="color",this._core.renderBuf=new SceneJS._webgl.RenderBuffer({canvas:this._engine.canvas})},SceneJS.ColorTarget.prototype._compile=function(b){this.__core||(this.__core=this._engine._coreFactory.getCore("renderTarget"));var e=this._engine.display.renderTarget;this._core.empty||(this.__core.targets=e&&e.targets?e.targets.concat([this._core]):[this._core]),c[d++]=this.__core,this._engine.display.renderTarget=this.__core,this._compileNodes(b),this._engine.display.renderTarget=--d>0?c[d-1]:a},SceneJS.ColorTarget.prototype._destroy=function(){this._core&&(this._core.renderBuf&&this._core.renderBuf.destroy(),delete b[this._core.coreId])}},new function(){var a={type:"renderTarget",stateId:SceneJS._baseStateId++,targets:null},b={},c=[],d=0;SceneJS_events.addListener(SceneJS_events.SCENE_COMPILING,function(b){b.engine.display.renderTarget=a,d=0}),SceneJS_events.addListener(SceneJS_events.WEBGL_CONTEXT_RESTORED,function(){for(var a in b)b.hasOwnProperty(a)&&b[a]._buildNodeCore()}),SceneJS.DepthTarget=SceneJS_NodeFactory.createNodeType("depthTarget"),SceneJS.DepthTarget.prototype._init=function(a){b[this._core.coreId]=this,this._core.bufType="depth",this._core.renderBuf=new SceneJS._webgl.RenderBuffer({canvas:this._engine.canvas})},SceneJS.DepthTarget.prototype._compile=function(b){this.__core||(this.__core=this._engine._coreFactory.getCore("renderTarget"));var e=this._engine.display.renderTarget;this._core.empty||(this.__core.targets=e&&e.targets?e.targets.concat([this._core]):[this._core]),c[d++]=this.__core,this._engine.display.renderTarget=this.__core,this._compileNodes(b),this._engine.display.renderTarget=--d>0?c[d-1]:a},SceneJS.DepthTarget.prototype._destroy=function(){this._core&&(this._core.renderBuf&&this._core.renderBuf.destroy(),delete b[this._core.coreId])}},new function(){var a=[],b=0;SceneJS_events.addListener(SceneJS_events.SCENE_COMPILING,function(){b=0}),SceneJS.Geometry=SceneJS_NodeFactory.createNodeType("geometry"),SceneJS.Geometry.prototype._init=function(a){if(1==this._core.useCount){this._initNodeCore(a,{origin:a.origin,scale:a.scale,autoNormals:"auto"==a.normals}),this._buildNodeCore(this._engine.canvas.gl,this._core);var b=this;this._core.webglRestored=function(){b._buildNodeCore(b._engine.canvas.gl,b._core)}}},SceneJS.Geometry.prototype._initNodeCore=function(a,b){var c=this;b=b||{};var d=a.primitive||"triangles",e=this._core,f=this._engine.canvas.UINT_INDEX_ENABLED?Uint32Array:Uint16Array;e.primitive=this._getPrimitiveType(d),a.normals&&"triangles"==d&&("auto"===a.normals||a.normals===!0)&&a.positions&&a.indices&&this._buildNormals(a),e.arrays={positions:a.positions?new Float32Array(b.scale||b.origin?this._applyOptions(a.positions,b):a.positions):void 0,normals:a.normals?new Float32Array(a.normals):void 0,uv:a.uv?new Float32Array(a.uv):void 0,uv2:a.uv2?new Float32Array(a.uv2):void 0,colors:a.colors?new Float32Array(a.colors):void 0,indices:a.indices?new f(a.indices):void 0},delete a.positions,delete a.normals,delete a.uv,delete a.uv2,delete a.indices,delete a.colors,e.getTangentBuf=function(){if(e.tangentBuf)return e.tangentBuf;var a=e.arrays;if(a.positions&&a.indices&&a.uv){var b=c._engine.canvas.gl,d=new Float32Array(c._buildTangents(a));e.arrays.tangents=d;var f=b.STATIC_DRAW;return e.tangentBuf=new SceneJS._webgl.ArrayBuffer(b,b.ARRAY_BUFFER,d,d.length,3,f)}}},SceneJS.Geometry.prototype._getPrimitiveType=function(a){var b=this._engine.canvas.gl;switch(a){case"points":return b.POINTS;case"lines":return b.LINES;case"line-loop":return b.LINE_LOOP;case"line-strip":return b.LINE_STRIP;case"triangles":return b.TRIANGLES;case"triangle-strip":return b.TRIANGLE_STRIP;case"triangle-fan":return b.TRIANGLE_FAN;default:throw SceneJS_error.fatalError(SceneJS.errors.ILLEGAL_NODE_CONFIG,"geometry primitive unsupported: '"+a+"' - supported types are: 'points', 'lines', 'line-loop', 'line-strip', 'triangles', 'triangle-strip' and 'triangle-fan'")}},SceneJS.Geometry.prototype._applyOptions=function(a,b){var c=a.slice?a.slice(0):new Float32Array(a);if(b.scale)for(var d=void 0!=b.scale.x?b.scale.x:1,e=void 0!=b.scale.y?b.scale.y:1,f=void 0!=b.scale.z?b.scale.z:1,g=0,h=c.length;h>g;g+=3)c[g]*=d,c[g+1]*=e,c[g+2]*=f;if(b.origin)for(var i=void 0!=b.origin.x?b.origin.x:0,j=void 0!=b.origin.y?b.origin.y:0,k=void 0!=b.origin.z?b.origin.z:0,g=0,h=c.length;h>g;g+=3)c[g]-=i,c[g+1]-=j,c[g+2]-=k;return c};var c=function(a){a.vertexBuf&&(a.vertexBuf.destroy(),a.vertexBuf=null),a.normalBuf&&(a.normalBuf.destroy(),a.normalBuf=null),a.uvBuf&&(a.uvBuf.destroy(),a.uvBuf=null),a.uvBuf2&&(a.uvBuf2.destroy(),a.uvBuf2=null),a.colorBuf&&(a.colorBuf.destroy(),a.colorBuf=null),a.tangentBuf&&(a.tangentBuf.destroy(),a.tangentBuf=null),a.indexBuf&&(a.indexBuf.destroy(),a.indexBuf=null),a.interleavedBuf&&(a.interleavedBuf.destroy(),a.interleavedBuf=null)};SceneJS.Geometry.prototype._buildNodeCore=function(a,b){var d=a.STATIC_DRAW;try{var e=b.arrays,f=SceneJS.getConfigs("enableInterleaving")!==!1,g=0,h=0,i=[],j=[],k=function(a,b){return 0==g?g=a.length/b:a.length/b!=g&&(f=!1),i.push(a),j.push(b),h+=b,4*(h-b)};if(e.positions&&(f&&(b.interleavedPositionOffset=k(e.positions,3)),b.vertexBuf=new SceneJS._webgl.ArrayBuffer(a,a.ARRAY_BUFFER,e.positions,e.positions.length,3,d)),e.normals&&(f&&(b.interleavedNormalOffset=k(e.normals,3)),b.normalBuf=new SceneJS._webgl.ArrayBuffer(a,a.ARRAY_BUFFER,e.normals,e.normals.length,3,d)),e.uv&&(f&&(b.interleavedUVOffset=k(e.uv,2)),b.uvBuf=new SceneJS._webgl.ArrayBuffer(a,a.ARRAY_BUFFER,e.uv,e.uv.length,2,d)),e.uv2&&(f&&(b.interleavedUV2Offset=k(e.uv2,2)),b.uvBuf2=new SceneJS._webgl.ArrayBuffer(a,a.ARRAY_BUFFER,e.uv2,e.uv2.length,2,d)),e.colors&&(f&&(b.interleavedColorOffset=k(e.colors,4)),b.colorBuf=new SceneJS._webgl.ArrayBuffer(a,a.ARRAY_BUFFER,e.colors,e.colors.length,4,d)),e.indices&&(b.indexBuf=new SceneJS._webgl.ArrayBuffer(a,a.ELEMENT_ARRAY_BUFFER,e.indices,e.indices.length,1,d)),h>0&&f){for(var l=[],m=i.length,n=0;g>n;++n)for(var o=0;m>o;++o)for(var p=j[o],q=0;p>q;++q)l.push(i[o][n*p+q]);b.interleavedStride=4*h,b.interleavedBuf=new SceneJS._webgl.ArrayBuffer(a,a.ARRAY_BUFFER,new Float32Array(l),l.length,h,d),b.interleavedBuf.dirty=!1}}catch(r){throw c(b),SceneJS_error.fatalError(SceneJS.errors.ERROR,"Failed to allocate geometry: "+r)}},SceneJS.Geometry.prototype._updateArray=function(a,b,c){var d=a.length,e=b.length;e+c>d&&(e-=e+c-d);for(var f=c,g=0;e>g;f++,g++)a[f]=b[g]},SceneJS.Geometry.prototype._buildNormals=function(a){for(var b,c,d,e,f,g,h=a.positions,i=a.indices,j=new Array(h.length/3),k=0,l=i.length-3;l>k;k+=3){b=i[k+0],c=i[k+1],d=i[k+2],e=[h[3*b+0],h[3*b+1],h[3*b+2]],f=[h[3*c+0],h[3*c+1],h[3*c+2]],g=[h[3*d+0],h[3*d+1],h[3*d+2]],f=SceneJS_math_subVec4(f,e,[0,0,0,0]),g=SceneJS_math_subVec4(g,e,[0,0,0,0]);var m=SceneJS_math_normalizeVec4(SceneJS_math_cross3Vec4(f,g,[0,0,0,0]),[0,0,0,0]);j[b]||(j[b]=[]),j[c]||(j[c]=[]),j[d]||(j[d]=[]),j[b].push(m),j[c].push(m),j[d].push(m)}for(var n=new Array(h.length),k=0,l=j.length;l>k;k++){for(var o=j[k].length,p=0,q=0,r=0,s=0;o>s;s++)p+=j[k][s][0],q+=j[k][s][1],r+=j[k][s][2];n[3*k+0]=p/o,n[3*k+1]=q/o,n[3*k+2]=r/o}a.normals=n},SceneJS.Geometry.prototype._buildTangents=function(a){for(var b=a.positions,c=a.indices,d=a.uv,e=[],f=0;ft;t++){var u=c[f+t];"undefined"!=typeof e[u]?e[u]=SceneJS_math_addVec3(e[u],s,[]):e[u]=s}}for(var v=[],w=0;wf;f+=3)c=b[f],d=b[f+1],e=b[f+2],cthis._boundary.xmax&&(this._boundary.xmax=c),d>this._boundary.ymax&&(this._boundary.ymax=d),e>this._boundary.zmax&&(this._boundary.zmax=e);return this._boundary},SceneJS.Geometry.prototype._compile=function(c){if(this._core._loading)return void this._compileNodes(c);var d=this._core;d.vertexBuf||(d=this._inheritVBOs(d)),d.indexBuf?(d.hash=[d.normalBuf?"t":"f",d.arrays&&d.arrays.tangents?"t":"f",d.uvBuf?"t":"f",d.uvBuf2?"t":"f",d.colorBuf?"t":"f",d.primitive].join(""),d.stateId=this._core.stateId,d.type="geometry",this._engine.display.geometry=a[b++]=d,SceneJS_events.fireEvent(SceneJS_events.OBJECT_COMPILING,{display:this._engine.display}),this._engine.display.buildObject(this.id)):a[b++]=this._core,this._compileNodes(c),b--},SceneJS.Geometry.prototype._inheritVBOs=function(c){for(var d={primitive:c.primitive,boundary:c.boundary,normalBuf:c.normalBuf,uvBuf:c.uvBuf,uvBuf2:c.uvBuf2,colorBuf:c.colorBuf,interleavedBuf:c.interleavedBuf,indexBuf:c.indexBuf,interleavedStride:c.interleavedStride,interleavedPositionOffset:c.interleavedPositionOffset,interleavedNormalOffset:c.interleavedNormalOffset,interleavedUVOffset:c.interleavedUVOffset,interleavedUV2Offset:c.interleavedUV2Offset,interleavedColorOffset:c.interleavedColorOffset},e=b-1;e>=0;e--)if(a[e].vertexBuf)return d.vertexBuf=a[e].vertexBuf,d.boundary=a[e].boundary,d.normalBuf=a[e].normalBuf,d.uvBuf=a[e].uvBuf,d.uvBuf2=a[e].uvBuf2,d.colorBuf=a[e].colorBuf,d.interleavedBuf=a[e].interleavedBuf,d.interleavedStride=a[e].interleavedStride,d.interleavedPositionOffset=a[e].interleavedPositionOffset,d.interleavedNormalOffset=a[e].interleavedNormalOffset,d.interleavedUVOffset=a[e].interleavedUVOffset,d.interleavedUV2Offset=a[e].interleavedUV2Offset,d.interleavedColorOffset=a[e].interleavedColorOffset,d;return d},SceneJS.Geometry.prototype._destroy=function(){this._engine.display.removeObject(this.id),1==this._core.useCount&&(this._destroyNodeCore(),this._source&&this._source.destroy&&this._source.destroy())},SceneJS.Geometry.prototype._destroyNodeCore=function(){document.getElementById(this._engine.canvas.canvasId)&&c(this._core)}},function(){var a={type:"stage",stateId:SceneJS._baseStateId++,priority:0,pickable:!0,enabled:!0},b=[],c=0;SceneJS_events.addListener(SceneJS_events.SCENE_COMPILING,function(b){b.engine.display.stage=a,c=0}),SceneJS.Stage=SceneJS_NodeFactory.createNodeType("stage"),SceneJS.Stage.prototype._init=function(a){1==this._core.useCount&&(this._core.priority=a.priority||0,this._core.enabled=a.enabled!==!1,this._core.pickable=!!a.pickable)},SceneJS.Stage.prototype.setPriority=function(a){a=a||0,this._core.priority!=a&&(this._core.priority=a,this._engine.display.stateOrderDirty=!0)},SceneJS.Stage.prototype.getPriority=function(){return this._core.priority},SceneJS.Stage.prototype.setEnabled=function(a){a=!!a,this._core.enabled!=a&&(this._core.enabled=a,this._engine.display.drawListDirty=!0)},SceneJS.Stage.prototype.getEnabled=function(){return this._core.enabled},SceneJS.Stage.prototype.getEnabled=function(){return this._core.enabled},SceneJS.Stage.prototype._compile=function(d){this._engine.display.stage=b[c++]=this._core,this._compileNodes(d),this._engine.display.stage=--c>0?b[c-1]:a}}(),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}}(),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}}(),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},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],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.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.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}},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){if(this._sourceConfigs=a.source,this._source=null,a.source){if(!a.source.type)throw SceneJS_error.fatalError(SceneJS.errors.ILLEGAL_NODE_CONFIG,"morphGeometry config expected: source.type");var b=this;SceneJS.Plugins.getPlugin("morphGeometry",this._sourceConfigs.type,function(c){if(!c)throw SceneJS_error.fatalError(SceneJS.errors.PLUGIN_INVALID,"morphGeometry: no support for source type '"+b._sourceConfigs.type+"' - need to include plugin for self source type, or install a custom source service with SceneJS.Plugins.addPlugin(SceneJS.Plugins.MORPH_GEO_SOURCE_PLUGIN, '"+b._sourceConfigs.type+"', ).");if(!c.getSource)throw SceneJS_error.fatalError(SceneJS.errors.PLUGIN_INVALID,"morphGeometry: 'getSource' method not found on MorphGeoFactoryService (SceneJS.Plugins.MORPH_GEO_SOURCE_PLUGIN)");if(b._source=c.getSource(),!b._source.subscribe)throw SceneJS_error.fatalError(SceneJS.errors.PLUGIN_INVALID,"morphGeometry: 'subscribe' method not found on source provided by plugin type '"+a.source.type+"'");var d=!1;b._source.subscribe(function(a){if(d){if(a.targets)for(var c,e,f,g=a.targets,h=b._core.targets,i=0,j=g.length;j>i;i++)c=g[i],e=c.targetIndex,f=h[e],c.positions&&f.vertexBuf&&(f.vertexBuf.bind(),f.vertexBuf.setData(c.positions,0));b._display.imageDirty=!0}else b._buildNodeCore(a),b._core._loading=!1,b._fireEvent("loaded"),b._engine.branchDirty(b),d=!0}),b._core._loading=!0,b._fireEvent("loading"),b._source.configure(b._sourceConfigs)})}else a.create instanceof Function?this._buildNodeCore(a.create()):this._buildNodeCore(a);this._core.webglRestored=function(){},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="Float32Array"==typeof o?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="Float32Array"==typeof o?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="Float32Array"==typeof o?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="Float32Array"==typeof o?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)}},SceneJS.MorphGeometry.prototype.setSource=function(a){this._sourceConfigs=a;var b=this._source;b&&b.configure(a)},SceneJS.MorphGeometry.prototype.getSource=function(){return this._sourceConfigs},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},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){if(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.normalBuf&&a.normalBuf.destroy(),a.uvBuf&&a.uvBuf.destroy(),a.uvBuf2&&a.uvBuf2.destroy();this._source&&this._source.destroy&&this._source.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}}(),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}},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}}(),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,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}}(),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.setSSAAMultiplier=function(a){return this._engine.canvas.setSSAAMultiplier(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.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){return this._engine.readPixels(a,b)},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}}(),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}}(),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=SceneJS_sceneStatusModule.taskStarted(this,"Loading texture"),g=new Image;g.onload=function(){var d=a.createTexture();a.bindTexture(a.TEXTURE_2D,d);var e=SceneJS_configsModule.configs.maxTextureSize;e&&(g=SceneJS._webgl.clampImageSize(g,e)),a.texImage2D(a.TEXTURE_2D,0,a.RGBA,a.RGBA,a.UNSIGNED_BYTE,c._ensureImageSizePowerOfTwo(g)),c._setLayerTexture(a,b,d),SceneJS_sceneStatusModule.taskFinished(f),c._engine.display.imageDirty=!0},g.onerror=function(){SceneJS_sceneStatusModule.taskFailed(f)},0==e.indexOf("data")?g.src=e:(g.crossOrigin="Anonymous",g.src=e)}},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},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){if(b.applyFrom&&"uv"!=b.applyFrom&&"uv2"!=b.applyFrom&&"normal"!=b.applyFrom&&"geometry"!=b.applyFrom)throw SceneJS_error.fatalError(SceneJS.errors.NODE_CONFIG_EXPECTED,"texture applyFrom value is unsupported - should be either 'uv', 'uv2', 'normal' or 'geometry'");if(b.applyTo&&"baseColor"!=b.applyTo&&"color"!=b.applyTo&&"specular"!=b.applyTo&&"emit"!=b.applyTo&&"alpha"!=b.applyTo&&"normals"!=b.applyTo&&"shine"!=b.applyTo)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,applyFrom:b.applyFrom?b.applyFrom:"uv",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._core.src=b.src,this._loadTexture(b.src)):b.image?(this._core.image=b.image,this._initTexture(b.image)):b.target&&this.getScene().getNode(b.target,function(a){c.setTarget(a)}),this._core.webglRestored=function(){c._core.image?c._initTexture(c._core.image):c._core.src?c._loadTexture(c._core.src):c._core.target}}},SceneJS.TextureMap.prototype._loadTexture=function(a){var b=this,c=SceneJS_sceneStatusModule.taskStarted(this,"Loading texture"),d=new Image;d.onload=function(){b._initTexture(d),SceneJS_sceneStatusModule.taskFinished(c),b._engine.display.imageDirty=!0},d.onerror=function(){SceneJS_sceneStatusModule.taskFailed(c)},0==a.indexOf("data")?d.src=a:(d.crossOrigin="Anonymous",d.src=a)},SceneJS.TextureMap.prototype._initTexture=function(a){var b=this._engine.canvas.gl,c=b.createTexture();b.bindTexture(b.TEXTURE_2D,c);var d=SceneJS_configsModule.configs.maxTextureSize;d&&(a=SceneJS._webgl.clampImageSize(a,d)),b.texImage2D(b.TEXTURE_2D,0,b.RGBA,b.RGBA,b.UNSIGNED_BYTE,SceneJS._webgl.ensureImageSizePowerOfTwo(a)),this._core.image=a,this._core.texture=new SceneJS._webgl.Texture2D(b,{texture:c,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._initTexture(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},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)}},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},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)}}(),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,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.cubemap=null,this.modelTransform=null,this.viewTransform=null,this.projTransform=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._drawList=[],this._drawListLen=0,this._pickDrawList=[],this._pickDrawListLen=0,this._targetList=[],this._targetListLen=0,this._frameCtx={pickNames:[],canvas:this._canvas,VAO:null},this._frameCtx.renderListenerCtx=new SceneJS.RenderContext(this._frameCtx),this.objectListDirty=!0,this.stateOrderDirty=!0,this.stateSortDirty=!0,this.drawListDirty=!0,this.imageDirty=!0,this.pickBufDirty=!0,this.rayPickBufDirty=!0};SceneJS_Display.prototype.webglRestored=function(){this._programFactory.webglRestored(),this._chunkFactory.webglRestored();var a=this._canvas.gl;this.pickBuf&&this.pickBuf.webglRestored(a),this.rayPickBuf&&this.rayPickBuf.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.stage=this.stage,b.layer=this.layer,b.renderTarget=this.renderTarget,b.texture=this.texture,b.cubemap=this.cubemap,b.geometry=this.geometry,b.enable=this.enable,b.flags=this.flags,b.tag=this.tag;var c=[this.geometry.hash,this.shader.hash,this.clips.hash,this.morphGeometry.hash,this.texture.hash,this.cubemap.hash,this.lights.hash,this.flags.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,"name",this.name),this._setChunk(b,12,"lights",this.lights),this._setChunk(b,13,"material",this.material),this._setChunk(b,14,"texture",this.texture),this._setChunk(b,15,"cubemap",this.cubemap),this._setChunk(b,16,"clips",this.clips),this._setChunk(b,17,"renderer",this.renderer),this._setChunk(b,18,"geometry",this.morphGeometry,this.geometry),this._setChunk(b,19,"listeners",this.renderListeners),this._setChunk(b,20,"draw",this.geometry)},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];b&&(this._programFactory.putProgram(b.program),b.program=null,b.hash=null,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)&&(this._doDrawList({clear:a.clear!==!1}),this.imageDirty=!1,this.pickBufDirty=!0)},SceneJS_Display.prototype._buildObjectList=function(){this._objectListLen=0;for(var a in this._objects)this._objects.hasOwnProperty(a)&&(this._objectList[this._objectListLen++]=this._objects[a])},SceneJS_Display.prototype._makeStateSortKeys=function(){for(var a,b=0,c=this._objectListLen;c>b;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||[];for(var a=0;23>a;a++)this._lastStateId[a]=null,this._lastPickStateId[a]=null;this._drawListLen=0,this._pickDrawListLen=0;var b,c,d,e,f,g={},h=[],i=[];this._tagSelector&&(c=this._tagSelector.mask,d=this._tagSelector.regex),this._objectDrawList=this._objectDrawList||[],this._objectDrawListLen=0;for(var a=0,j=this._objectListLen;j>a;a++)if(b=this._objectList[a],b.enable.enabled!==!1&&(f=b.flags,f.enabled!==!1&&b.layer.enabled&&(!c||(e=b.tag,!e.tag||(e.mask!=c&&(e.mask=c,e.matches=d.test(e.tag)),e.matches)))))if(b.renderTarget.targets)for(var k,l,m,n=b.renderTarget.targets,o=0,p=n.length;p>o;o++)k=n[o],l=k.coreId,m=g[l],m||(m=[],g[l]=m,h.push(m),i.push(this._chunkFactory.getChunk(k.stateId,"renderTarget",b.program,k))),m.push(b);else this._objectDrawList[this._objectDrawListLen++]=b;for(var m,k,b,q,a=0,j=h.length;j>a;a++){m=h[a],k=i[a],this._appendRenderTargetChunk(k);for(var o=0,p=m.length;p>o;o++)b=m[o],q=b.stage&&b.stage.pickable,this._appendObjectToDrawLists(b,q)}b&&this._appendRenderTargetChunk(this._chunkFactory.getChunk(-1,"renderTarget",b.program,{}));for(var a=0,j=this._objectDrawListLen;j>a;a++)b=this._objectDrawList[a],q=!b.stage||b.stage&&b.stage.pickable,this._appendObjectToDrawLists(b,q);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=a.flags.picking,f=0,g=d.length;g>f;f++)c=d[f],c&&(c.draw&&(c.unique||this._lastStateId[f]!=c.id)&&(this._drawList[this._drawListLen++]=c,this._lastStateId[f]=c.id),c.pick&&b!==!1&&e&&(c.unique||this._lastPickStateId[f]!=c.id)&&(this._pickDrawList[this._pickDrawListLen++]=c,this._lastPickStateId[f]=c.id))},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("--------------------------------------------------------------------------------------------------")},SceneJS_Display.prototype.pick=function(a){var b=this._canvas.canvas,c=this._canvas.ssaaMultiplier,d=null,e=a.canvasX*c,f=a.canvasY*c,g=this.pickBuf;g||(g=this.pickBuf=new SceneJS._webgl.RenderBuffer({canvas:this._canvas}),this.pickBufDirty=!0),this.render(),g.bind(),this.pickBufDirty&&(g.clear(),this._doDrawList({pick:!0,clear:!0}),this._canvas.gl.finish(),this.pickBufDirty=!1,this.rayPickBufDirty=!0);var h=g.read(e,f),i=h[0]+256*h[1]+65536*h[2],j=i>=1?i-1:-1;g.unbind();var k=this._frameCtx.pickNames[j];if(k&&(d={name:k.name,path:k.path,nodeId:k.nodeId,canvasPos:[e,f]},a.rayPick)){var l=this.rayPickBuf;l||(l=this.rayPickBuf=new SceneJS._webgl.RenderBuffer({canvas:this._canvas}),this.rayPickBufDirty=!0),l.bind(),this.rayPickBufDirty&&(l.clear(),this._doDrawList({pick:!0,rayPick:!0,clear:!0}),this.rayPickBufDirty=!1),h=l.read(e,f),l.unbind();var m=this._unpackDepth(h),n=b.width,o=b.height,p=(e-n/2)/(n/2),q=-(f-o/2)/(o/2),r=this._frameCtx.cameraMat,s=this._frameCtx.viewMat,t=SceneJS_math_mulMat4(r,s,[]),u=SceneJS_math_inverseMat4(t,[]),v=SceneJS_math_transformVector4(u,[p,q,-1,1]);v=SceneJS_math_mulVec4Scalar(v,1/v[3]);var w=SceneJS_math_transformVector4(u,[p,q,1,1]);w=SceneJS_math_mulVec4Scalar(w,1/w[3]);var x=SceneJS_math_subVec3(w,v,[]),y=SceneJS_math_addVec3(v,SceneJS_math_mulVec4Scalar(x,m,[]),[]);d.worldPos=y}return d},SceneJS_Display.prototype.readPixels=function(a,b){this._readPixelBuf||(this._readPixelBuf=new SceneJS._webgl.RenderBuffer({canvas:this._canvas})),this._readPixelBuf.bind(),this._readPixelBuf.clear(),this.render({force:!0});for(var c,d,e=0;b>e;e++)c=a[e]||(a[e]={}),d=this._readPixelBuf.read(c.x,c.y),c.r=d[0],c.g=d[1],c.b=d[2],c.a=d[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._doDrawList=function(a){var b=this._canvas.gl,c=this._frameCtx;c.renderTarget=null,c.targetIndex=0,c.renderBuf=null,c.viewMat=null,c.modelMat=null,c.cameraMat=null,c.renderer=null,c.depthbufEnabled=null,c.clearDepth=null,c.depthFunc=b.LESS,c.scissorTestEnabled=!1,c.blendEnabled=!1,c.backfaces=!0,c.frontface="ccw",c.pick=!!a.pick,c.rayPick=!!a.rayPick,c.pickIndex=0,c.textureUnit=0,c.lineWidth=1,c.transparent=!1,c.ambientColor=this._ambientColor,c.aspect=this._canvas.canvas.width/this._canvas.canvas.height,this._canvas.UINT_INDEX_ENABLED&&b.getExtension("OES_element_index_uint");var d=b.getExtension("OES_vertex_array_object");if(c.VAO=d?d:null,b.viewport(0,0,b.drawingBufferWidth,b.drawingBufferHeight),this.transparent?b.clearColor(0,0,0,0):b.clearColor(this._ambientColor[0],this._ambientColor[1],this._ambientColor[2],1),a.clear&&b.clear(b.COLOR_BUFFER_BIT|b.DEPTH_BUFFER_BIT|b.STENCIL_BUFFER_BIT),b.frontFace(b.CCW),b.disable(b.CULL_FACE),b.disable(b.BLEND),a.pick)for(var e=0,f=this._pickDrawListLen;f>e;e++)this._pickDrawList[e].pick(c);else for(var e=0,f=this._drawListLen;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.destroy=function(){this._programFactory.destroy()};var SceneJS_ProgramSourceFactory=new function(){function a(a){if(a.renderTarget&&a.renderTarget.targets)for(var b=a.renderTarget.targets,c=0,d=b.length;d>c;c++)if("depth"===b[c].bufType)return!0;return!1}function b(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"}this._sourceCache={},this.getSource=function(a,b){var c=this._sourceCache[a];return c?(c.useCount++,c):this._sourceCache[a]=new SceneJS_ProgramSource(a,this._composePickingVertexShader(b),this._composePickingFragmentShader(b),this._composeRenderingVertexShader(b),this._composeRenderingFragmentShader(b))},this.putSource=function(a){var b=this._sourceCache[a];b&&0==--b.useCount&&(this._sourceCache[b.hash]=null)},this._composePickingVertexShader=function(a){var b=!!a.morphGeometry.targets,c=["attribute vec3 SCENEJS_aVertex;","uniform mat4 SCENEJS_uMMatrix;","uniform mat4 SCENEJS_uVMatrix;","uniform mat4 SCENEJS_uVNMatrix;","uniform mat4 SCENEJS_uPMatrix;"];return c.push("varying vec4 SCENEJS_vWorldVertex;"),c.push("varying vec4 SCENEJS_vViewVertex;"),b&&(c.push("uniform float SCENEJS_uMorphFactor;"),a.morphGeometry.targets[0].vertexBuf&&c.push("attribute vec3 SCENEJS_aMorphVertex;")),c.push("void main(void) {"),c.push(" vec4 tmpVertex=vec4(SCENEJS_aVertex, 1.0); "),b&&a.morphGeometry.targets[0].vertexBuf&&c.push(" tmpVertex = vec4(mix(tmpVertex.xyz, SCENEJS_aMorphVertex, SCENEJS_uMorphFactor), 1.0); "),c.push(" SCENEJS_vWorldVertex = SCENEJS_uMMatrix * tmpVertex; "),c.push(" SCENEJS_vViewVertex = SCENEJS_uVMatrix * SCENEJS_vWorldVertex;"),c.push(" gl_Position = SCENEJS_uPMatrix * SCENEJS_vViewVertex;"),c.push("}"),c},this._composePickingFragmentShader=function(a){var c=a.clips.clips.length>0,d=b(a._canvas.gl),e=["precision "+d+" float;"];if(e.push("varying vec4 SCENEJS_vWorldVertex;"),e.push("varying vec4 SCENEJS_vViewVertex;"),e.push("uniform bool SCENEJS_uRayPickMode;"),e.push("uniform vec3 SCENEJS_uPickColor;"),e.push("uniform float SCENEJS_uZNear;"),e.push("uniform float SCENEJS_uZFar;"),e.push("uniform bool SCENEJS_uClipping;"),c)for(var f=0;f 0.0) { discard; }"),e.push("}")}return e.push(" if (SCENEJS_uRayPickMode) {"),e.push(" float zNormalizedDepth = abs((SCENEJS_uZNear + SCENEJS_vViewVertex.z) / (SCENEJS_uZFar - SCENEJS_uZNear));"),e.push(" gl_FragColor = packDepth(zNormalizedDepth); "),e.push(" } else {"),e.push(" gl_FragColor = vec4(SCENEJS_uPickColor.rgb, 1.0); "),e.push(" }"),e.push("}"),e},this._isTexturing=function(a){if(a.texture.layers&&a.texture.layers.length>0){if(a.geometry.uvBuf||a.geometry.uvBuf2)return!0;if(a.morphGeometry.targets&&(a.morphGeometry.targets[0].uvBuf||a.morphGeometry.targets[0].uvBuf2))return!0}return!1},this._isCubeMapping=function(a){return a.flags.reflective&&a.cubemap.layers&&a.cubemap.layers.length>0&&a.geometry.normalBuf},this._hasNormals=function(a){return a.geometry.normalBuf?!0:a.morphGeometry.targets&&a.morphGeometry.targets[0].normalBuf?!0:!1},this._hasTangents=function(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},this._composeRenderingVertexShader=function(a){var b=a.shader.shaders||{};if(b.vertex&&b.vertex.code&&""!=b.vertex.code&&SceneJS._isEmpty(b.vertex.hooks))return[b.vertex.code];var c=b.vertex||{},d=c.hooks||{},e=b.fragment||{},f=e.hooks||{},g=this._isTexturing(a),h=this._hasNormals(a),i=this._hasTangents(a),j=a.clips.clips.length>0,k=!!a.morphGeometry.targets,l=[];if(l.push("uniform mat4 SCENEJS_uMMatrix;"),l.push("uniform mat4 SCENEJS_uVMatrix;"),l.push("uniform mat4 SCENEJS_uPMatrix;"),l.push("attribute vec3 SCENEJS_aVertex;"),l.push("uniform vec3 SCENEJS_uWorldEye;"),l.push("varying vec3 SCENEJS_vViewEyeVec;"),h){l.push("attribute vec3 SCENEJS_aNormal;"),l.push("uniform mat4 SCENEJS_uMNMatrix;"),l.push("uniform mat4 SCENEJS_uVNMatrix;"),l.push("varying vec3 SCENEJS_vViewNormal;"),i&&l.push("attribute vec4 SCENEJS_aTangent;");for(var m=0;m0,m=b(c._canvas.gl),n=["\n"];if(n.push("precision "+m+" float;"),l&&n.push("varying vec4 SCENEJS_vWorldVertex;"),n.push("varying vec4 SCENEJS_vViewVertex;"),n.push("uniform float SCENEJS_uZNear;"),n.push("uniform float SCENEJS_uZFar;"),l)for(var o=0;oo;o++)p=c.texture.layers[o],n.push("uniform sampler2D SCENEJS_uSampler"+o+";"),p.matrix&&n.push("uniform mat4 SCENEJS_uLayer"+o+"Matrix;"),n.push("uniform float SCENEJS_uLayer"+o+"BlendFactor;")}if(i&&h)for(var p,o=0,q=c.cubemap.layers.length;q>o;o++)p=c.cubemap.layers[o],n.push("uniform samplerCube SCENEJS_uCubeMapSampler"+o+";"),n.push("uniform float SCENEJS_uCubeMapIntensity"+o+";");if(n.push("uniform bool SCENEJS_uClipping;"),n.push("uniform bool SCENEJS_uSolid;"),n.push("uniform bool SCENEJS_uDepthMode;"),n.push("uniform bool SCENEJS_uTransparent;"),c.geometry.colorBuf&&n.push("varying vec4 SCENEJS_vColor;"),n.push("uniform vec3 SCENEJS_uAmbientColor;"),n.push("uniform vec3 SCENEJS_uMaterialColor;"),n.push("uniform float SCENEJS_uMaterialAlpha;"),n.push("uniform float SCENEJS_uMaterialEmit;"),n.push("uniform vec3 SCENEJS_uMaterialSpecularColor;"),n.push("uniform float SCENEJS_uMaterialSpecular;"),n.push("uniform float SCENEJS_uMaterialShine;"),n.push("varying vec3 SCENEJS_vViewEyeVec;"),i){n.push("varying vec3 SCENEJS_vViewNormal;");for(var r,o=0;o 0.0) { discard; }"),n.push("}")}i&&j&&(n.push(" float a = dot(normalize(SCENEJS_vViewNormal), normalize(SCENEJS_vViewEyeVec));"),n.push(" if (a < 0.0) {"),n.push(" gl_FragColor = vec4(0.4, 0.4, 1.0, 1.0);"),n.push(" return;"),n.push(" }")),n.push(" vec3 ambient= SCENEJS_uAmbientColor;"),g&&c.geometry.uvBuf&&f.texturePos&&n.push(f.texturePos+"(SCENEJS_vUVCoord);"),f.viewPos&&n.push(f.viewPos+"(SCENEJS_vViewVertex);"),i&&f.viewNormal&&n.push(f.viewNormal+"(SCENEJS_vViewNormal);"),c.geometry.colorBuf?n.push(" vec3 color = SCENEJS_vColor.rgb;"):n.push(" vec3 color = SCENEJS_uMaterialColor;"),n.push(" float alpha = SCENEJS_uMaterialAlpha;"),n.push(" float emit = SCENEJS_uMaterialEmit;"),n.push(" float specular = SCENEJS_uMaterialSpecular;"),n.push(" vec3 specularColor = SCENEJS_uMaterialSpecularColor;"),n.push(" float shine = SCENEJS_uMaterialShine;"),f.materialBaseColor&&n.push("color="+f.materialBaseColor+"(color);"),f.materialAlpha&&n.push("alpha="+f.materialAlpha+"(alpha);"),f.materialEmit&&n.push("emit="+f.materialEmit+"(emit);"),f.materialSpecular&&n.push("specular="+f.materialSpecular+"(specular);"),f.materialSpecularColor&&n.push("specularColor="+f.materialSpecularColor+"(specularColor);"),f.materialShine&&n.push("shine="+f.materialShine+"(shine);"),i&&(n.push(" float attenuation = 1.0;"),k?n.push(" vec3 viewNormalVec = vec3(0.0, 1.0, 0.0);"):n.push(" vec3 viewNormalVec = normalize(SCENEJS_vViewNormal);"));var p;if(g){n.push(" vec4 texturePos;"),n.push(" vec2 textureCoord=vec2(0.0,0.0);");for(var o=0,q=c.texture.layers.length;q>o;o++){if(p=c.texture.layers[o],"normal"==p.applyFrom&&i){if(!c.geometry.normalBuf){SceneJS.log.warn("Texture layer applyFrom='normal' but geo has no normal vectors");continue}n.push("texturePos=vec4(viewNormalVec.xyz, 1.0);")}if("uv"==p.applyFrom){if(!c.geometry.uvBuf){SceneJS.log.warn("Texture layer applyTo='uv' but geometry has no UV coordinates");continue}n.push("texturePos = vec4(SCENEJS_vUVCoord.s, SCENEJS_vUVCoord.t, 1.0, 1.0);")}if("uv2"==p.applyFrom){if(!c.geometry.uvBuf2){SceneJS.log.warn("Texture layer applyTo='uv2' but geometry has no UV2 coordinates");continue}n.push("texturePos = vec4(SCENEJS_vUVCoord2.s, SCENEJS_vUVCoord2.t, 1.0, 1.0);")}p.matrix?n.push("textureCoord=(SCENEJS_uLayer"+o+"Matrix * texturePos).xy;"):n.push("textureCoord=texturePos.xy;"),"alpha"==p.applyTo&&("multiply"==p.blendMode?n.push("alpha = alpha * (SCENEJS_uLayer"+o+"BlendFactor * texture2D(SCENEJS_uSampler"+o+", vec2(textureCoord.x, 1.0 - textureCoord.y)).b);"):"add"==p.blendMode&&n.push("alpha = ((1.0 - SCENEJS_uLayer"+o+"BlendFactor) * alpha) + (SCENEJS_uLayer"+o+"BlendFactor * texture2D(SCENEJS_uSampler"+o+", vec2(textureCoord.x, 1.0 - textureCoord.y)).b);")),"baseColor"==p.applyTo&&("multiply"==p.blendMode?n.push("color = color * (SCENEJS_uLayer"+o+"BlendFactor * texture2D(SCENEJS_uSampler"+o+", vec2(textureCoord.x, 1.0 - textureCoord.y)).rgb);"):n.push("color = ((1.0 - SCENEJS_uLayer"+o+"BlendFactor) * color) + (SCENEJS_uLayer"+o+"BlendFactor * texture2D(SCENEJS_uSampler"+o+", vec2(textureCoord.x, 1.0 - textureCoord.y)).rgb);")),"emit"==p.applyTo&&("multiply"==p.blendMode?n.push("emit = emit * (SCENEJS_uLayer"+o+"BlendFactor * texture2D(SCENEJS_uSampler"+o+", vec2(textureCoord.x, 1.0 - textureCoord.y)).r);"):n.push("emit = ((1.0 - SCENEJS_uLayer"+o+"BlendFactor) * emit) + (SCENEJS_uLayer"+o+"BlendFactor * texture2D(SCENEJS_uSampler"+o+", vec2(textureCoord.x, 1.0 - textureCoord.y)).r);")),"specular"==p.applyTo&&i&&("multiply"==p.blendMode?n.push("specular = specular * (SCENEJS_uLayer"+o+"BlendFactor * texture2D(SCENEJS_uSampler"+o+", vec2(textureCoord.x, 1.0 - textureCoord.y)).r);"):n.push("specular = ((1.0 - SCENEJS_uLayer"+o+"BlendFactor) * specular) + (SCENEJS_uLayer"+o+"BlendFactor * texture2D(SCENEJS_uSampler"+o+", vec2(textureCoord.x, 1.0 - textureCoord.y)).r);")),"shine"==p.applyTo&&("multiply"==p.blendMode?n.push("shine = shine * (SCENEJS_uLayer"+o+"BlendFactor * texture2D(SCENEJS_uSampler"+o+", vec2(textureCoord.x, 1.0 - textureCoord.y)).r);"):n.push("shine = ((1.0 - SCENEJS_uLayer"+o+"BlendFactor) * shine) + (SCENEJS_uLayer"+o+"BlendFactor * texture2D(SCENEJS_uSampler"+o+", vec2(textureCoord.x, 1.0 - textureCoord.y)).r);")),"normals"==p.applyTo&&i&&n.push("viewNormalVec = normalize(texture2D(SCENEJS_uSampler"+o+", vec2(textureCoord.x, -textureCoord.y)).xyz * 2.0 - 1.0);")}}if(i&&h){n.push("vec3 envLookup = reflect(SCENEJS_vViewEyeVec, viewNormalVec);"),n.push("envLookup.y = envLookup.y * -1.0;"),n.push("vec4 envColor;");for(var o=0,q=c.cubemap.layers.length;q>o;o++)p=c.cubemap.layers[o],n.push("envColor = textureCube(SCENEJS_uCubeMapSampler"+o+", envLookup);"),n.push("color = mix(color, envColor.rgb, specular * SCENEJS_uCubeMapIntensity"+o+");")}if(n.push(" vec4 fragColor;"),i){n.push(" vec3 lightValue = vec3(0.0, 0.0, 0.0);"),n.push(" vec3 specularValue = vec3(0.0, 0.0, 0.0);"),n.push(" vec3 viewLightVec;"),n.push(" float dotN;"),n.push(" float lightDist;");for(var r,o=0,q=c.lights.lights.length;q>o;o++)r=c.lights.lights[o],"ambient"!=r.mode&&(n.push("viewLightVec = SCENEJS_vViewLightVecAndDist"+o+".xyz;"),"point"==r.mode&&(n.push("dotN = max(dot(normalize(viewNormalVec), normalize(viewLightVec)), 0.0);"),n.push("lightDist = SCENEJS_vViewLightVecAndDist"+o+".w;"),n.push("attenuation = 1.0 - ( SCENEJS_uLightAttenuation"+o+"[0] + SCENEJS_uLightAttenuation"+o+"[1] * lightDist + SCENEJS_uLightAttenuation"+o+"[2] * lightDist * lightDist);"),r.diffuse&&n.push(" lightValue += dotN * SCENEJS_uLightColor"+o+" * attenuation;"),r.specular&&n.push(" specularValue += specularColor * SCENEJS_uLightColor"+o+" * specular * pow(max(dot(reflect(normalize(-viewLightVec), normalize(-viewNormalVec)), normalize(-SCENEJS_vViewVertex.xyz)), 0.0), shine) * attenuation;")),"dir"==r.mode&&(n.push("dotN = max(dot(normalize(viewNormalVec), normalize(viewLightVec)), 0.0);"),r.diffuse&&n.push(" lightValue += dotN * SCENEJS_uLightColor"+o+";"),r.specular&&n.push("specularValue += specularColor * SCENEJS_uLightColor"+o+" * specular * pow(max(dot(reflect(normalize(-viewLightVec), normalize(-viewNormalVec)), normalize(-SCENEJS_vViewVertex.xyz)), 0.0), shine);")));n.push(" fragColor = vec4((specularValue.rgb + color.rgb * (lightValue.rgb + ambient.rgb)) + (emit * color.rgb), alpha);")}else n.push("fragColor = vec4((color.rgb + (emit * color.rgb)) * (vec3(1.0, 1.0, 1.0) + ambient.rgb), alpha);");return f.pixelColor&&n.push("fragColor="+f.pixelColor+"(fragColor);"),a(c)?(n.push(" if (SCENEJS_uDepthMode) {"),n.push(" float depth = length(SCENEJS_vViewVertex) / (SCENEJS_uZFar - SCENEJS_uZNear);"),n.push(" const vec4 bias = vec4(1.0 / 255.0,"),n.push(" 1.0 / 255.0,"),n.push(" 1.0 / 255.0,"),n.push(" 0.0);"),n.push(" float r = depth;"),n.push(" float g = fract(r * 255.0);"),n.push(" float b = fract(g * 255.0);"),n.push(" float a = fract(b * 255.0);"),n.push(" vec4 colour = vec4(r, g, b, a);"),n.push(" gl_FragColor = colour - (colour.yzww * bias);"),n.push(" } else {"),n.push(" gl_FragColor = fragColor;"),n.push(" };")):n.push(" gl_FragColor = fragColor;"),n.push("}"),n}},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.UINT_INDEX_ENABLED=!!d.getExtension("OES_element_index_uint"),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){this._freeObjects[this._numFreeObjects++]=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.ssaaMultiplier,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];if(g)return g.useCount++,g;var h=SceneJS_ChunkFactory._freeChunks[b];return h.chunksLen>0&&(g=h.chunks[--h.chunksLen]),g?g.init(a,c,d,e):g=new f(a,c,d,e),g.type=b,g.useCount=1,this._chunks[a]=g,g},SceneJS_ChunkFactory.prototype.putChunk=function(a){if(0!=a.useCount&&--a.useCount<=0){a.recycle&&a.recycle(),delete this._chunks[a.id];var b=SceneJS_ChunkFactory._freeChunks[a.type];b.chunks[b.chunksLen++]=a}},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.pick?this._pick:this._draw,f=this.core.clips,g=(this.program.gl,0),h=f.length;h>g;g++)a.pick?(b=e[g].uClipMode,c=e[g].uClipNormalAndDist):(b=e[g].uClipMode,c=e[g].uClipNormalAndDist),b&&c&&(d=f[g],"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._depthModePick=this.program.pick.getUniform("SCENEJS_uDepthMode")},drawAndPick:function(a){var b=this.program.gl,c=this.program.UINT_INDEX_ENABLED?b.UNSIGNED_INT:b.UNSIGNED_SHORT;a.pick?this._depthModePick&&this._depthModePick.setValue(a.depthMode):this._depthModeDraw&&this._depthModeDraw.setValue(a.depthMode),b.drawElements(this.core.primitive,this.core.indexBuf.numItems,c,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");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=this.core.transparent;a.transparent!=e&&(a.pick||(e?(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=e),a.pick?this._uClippingPick&&this._uClippingPick.setValue(this.core.clipping):(this._uClippingDraw&&this._uClippingDraw.setValue(this.core.clipping),this._uSolidDraw&&this._uSolidDraw.setValue(this.core.solid))}}),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._aVertexDraw=a.getAttribute("SCENEJS_aVertex"),this._aNormalDraw=a.getAttribute("SCENEJS_aNormal"),this._aUVDraw=a.getAttribute("SCENEJS_aUVCoord"),this._aUV2Draw=a.getAttribute("SCENEJS_aUVCoord2"),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._uMorphFactorDraw=a.getUniform("SCENEJS_uMorphFactor");var b=this.program.pick;this._aVertexPick=b.getAttribute("SCENEJS_aVertex"),this._aMorphVertexPick=b.getAttribute("SCENEJS_aMorphVertex"),this._uMorphFactorPick=b.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(){this.VAOMorphKey1=this.core.key1,this.VAOMorphKey2=this.core.key2;var a=this.core.targets[this.core.key1],b=this.core.targets[this.core.key2];this._aMorphVertexDraw?(this._aVertexDraw.bindFloatArrayBuffer(a.vertexBuf),this._aMorphVertexDraw.bindFloatArrayBuffer(b.vertexBuf)):this._aVertexDraw&&this._aVertexDraw.bindFloatArrayBuffer(this.core2.vertexBuf),this._aMorphNormalDraw?(this._aNormalDraw.bindFloatArrayBuffer(a.normalBuf),this._aMorphNormalDraw.bindFloatArrayBuffer(b.normalBuf)):this._aNormalDraw&&this._aNormalDraw.bindFloatArrayBuffer(this.core2.normalBuf),this._aUVDraw&&this._aUVDraw.bindFloatArrayBuffer(this.core2.uvBuf),this._aUV2Draw&&this._aUV2Draw.bindFloatArrayBuffer(this.core2.uvBuf2),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){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 if(a.VAO){a.VAO.bindVertexArrayOES(null),this.VAO=a.VAO.createVertexArrayOES(),a.VAO.bindVertexArrayOES(this.VAO);this.program.gl}b?this.morphDraw():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),this._aUVDraw&&this._aUVDraw.bindInterleavedFloatArrayBuffer(2,this.core2.interleavedStride,this.core2.interleavedUVOffset),this._aUV2Draw&&this._aUV2Draw.bindInterleavedFloatArrayBuffer(2,this.core2.interleavedStride,this.core2.interleavedUV2Offset),this._aColorDraw&&this._aColorDraw.bindInterleavedFloatArrayBuffer(4,this.core2.interleavedStride,this.core2.interleavedColorOffset),this._aTangentDraw&&this._aTangentDraw.bindFloatArrayBuffer(this.core2.tangentBuf||this.core2.getTangentBuf())):(this.VAOHasInterleavedBuf=!1,this._aVertexDraw&&this._aVertexDraw.bindFloatArrayBuffer(this.core2.vertexBuf),this._aNormalDraw&&this._aNormalDraw.bindFloatArrayBuffer(this.core2.normalBuf),this._aUVDraw&&this._aUVDraw.bindFloatArrayBuffer(this.core2.uvBuf),this._aUV2Draw&&this._aUV2Draw.bindFloatArrayBuffer(this.core2.uvBuf2),this._aColorDraw&&this._aColorDraw.bindFloatArrayBuffer(this.core2.colorBuf),this._aTangentDraw&&this._aTangentDraw.bindFloatArrayBuffer(this.core2.tangentBuf||this.core2.getTangentBuf())),this.core2.indexBuf.bind()},morphPick:function(){var a=this.core.targets[this.core.key1],b=this.core.targets[this.core.key2];this._aMorphVertexPick?(this._aVertexPick.bindFloatArrayBuffer(a.vertexBuf),this._aMorphVertexPick.bindFloatArrayBuffer(b.vertexBuf)):this._aVertexPick&&this._aVertexPick.bindFloatArrayBuffer(this.core2.vertexBuf),this._uMorphFactorPick&&this._uMorphFactorPick.setValue(this.core.factor)},pick:function(a){this.core.targets&&this.core.targets.length?this.morphPick():this._aVertexPick&&this._aVertexPick.bindFloatArrayBuffer(this.core2.vertexBuf),this.core2.indexBuf.bind()}}),SceneJS_ChunkFactory.createChunkType({type:"lights",build:function(){this._uAmbientColor=this._uAmbientColor||[],this._uLightColor=this._uLightColor||[],this._uLightDir=this._uLightDir||[],this._uLightPos=this._uLightPos||[],this._uLightCutOff=this._uLightCutOff||[],this._uLightSpotExp=this._uLightSpotExp||[],this._uLightAttenuation=this._uLightAttenuation||[];for(var a=this.core.lights,b=this.program,c=0,d=a.length;d>c;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._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._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:"name",build:function(){this._uPickColor=this.program.pick.getUniform("SCENEJS_uPickColor")},pick:function(a){if(this._uPickColor&&this.core.name){a.pickNames[a.pickIndex++]=this.core;var b=a.pickIndex>>16&255,c=a.pickIndex>>8&255,d=255&a.pickIndex;this._uPickColor.setValue([d/255,c/255,b/255])}}}),SceneJS_ChunkFactory.createChunkType({type:"program",build:function(){this._depthModeDraw=this.program.draw.getUniform("SCENEJS_uDepthMode"),this._depthModePick=this.program.pick.getUniform("SCENEJS_uDepthMode"),this._rayPickMode=this.program.pick.getUniform("SCENEJS_uRayPickMode")},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;this._rayPickMode&&this._rayPickMode.setValue(a.rayPick),this._depthModePick&&this._depthModePick.setValue(a.depthMode),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:"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.pick?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.pick?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;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++),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));a.textureUnit>10&&(a.textureUnit=0)}}),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++),this._uCubeMapIntensity[e]&&this._uCubeMapIntensity[e].setValue(c.intensity));a.textureUnit>10&&(a.textureUnit=0)}}),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 diff --git a/examples/benchmarks_10000boxes.html b/examples/benchmarks_10000boxes.html index 4df258be..01f3a213 100644 --- a/examples/benchmarks_10000boxes.html +++ b/examples/benchmarks_10000boxes.html @@ -21,6 +21,11 @@ + +
+ 10000 boxes with unique materials +
+ diff --git a/examples/benchmarks_400000boxes.html b/examples/benchmarks_400000boxes.html index 871b8d56..626ec8c5 100644 --- a/examples/benchmarks_400000boxes.html +++ b/examples/benchmarks_400000boxes.html @@ -21,6 +21,11 @@ + +
+ 400000 boxes with unique materials +
+ diff --git a/examples/benchmarks_40000boxes.html b/examples/benchmarks_40000boxes.html index 8e68893c..e2dad017 100644 --- a/examples/benchmarks_40000boxes.html +++ b/examples/benchmarks_40000boxes.html @@ -21,6 +21,11 @@ + +
+ 40000 boxes with unique materials +
+ diff --git a/examples/benchmarks_5000boxes.html b/examples/benchmarks_5000boxes.html index df557db1..2b92bac5 100644 --- a/examples/benchmarks_5000boxes.html +++ b/examples/benchmarks_5000boxes.html @@ -47,7 +47,7 @@ type:"cameras/orbit", yaw:30, pitch:-30, - zoom:200, + zoom:800, zoomSensitivity:10.0, spin: 0.1, // Slowly spin about X axis @@ -65,18 +65,18 @@ }); - // var container = document.createElement('div'); - // document.body.appendChild(container); - // - // var stats = new Stats(); - // stats.domElement.style.position = 'absolute'; - // stats.domElement.style.top = '0px'; - // // stats.domElement.style["z-index"] = 100000; - // container.appendChild(stats.domElement); - // - // scene.on("tick", function () { - // stats.update(); - // }); + var container = document.createElement('div'); + document.body.appendChild(container); + + var stats = new Stats(); + stats.domElement.style.position = 'absolute'; + stats.domElement.style.top = '0px'; + // stats.domElement.style["z-index"] = 100000; + container.appendChild(stats.domElement); + + scene.on("tick", function () { + stats.update(); + }); diff --git a/package.json b/package.json index c626bc86..7b5c281b 100644 --- a/package.json +++ b/package.json @@ -17,15 +17,15 @@ "grunt-contrib-yuidoc": "~0.7.0" }, "devDependencies": { - "grunt": "^0.4.5", - "grunt-contrib-clean": "^0.6.0", - "grunt-contrib-concat": "^0.5.1", - "grunt-contrib-copy": "^0.8.0", + "grunt": "~0.4.5", + "grunt-contrib-concat": "~0.5.1", + "grunt-contrib-uglify": "~0.9.1", + "grunt-contrib-yuidoc": "~0.7.0", + "grunt-contrib-jshint": "~0.11.2", + "grunt-contrib-clean": "~0.6.0", + "grunt-contrib-copy": "~0.8.0", "grunt-contrib-jasmine": "~0.8.2", - "grunt-contrib-jshint": "~0.11.1", - "grunt-contrib-qunit": "~0.5.2", - "grunt-contrib-uglify": "^0.9.1", - "grunt-contrib-yuidoc": "~0.7.0" + "grunt-contrib-qunit": "~0.5.2" }, "engines": { "node": ">=0.10.17", diff --git a/src/core/display/chunks/cameraChunk.js b/src/core/display/chunks/cameraChunk.js index b6c54623..b4127306 100644 --- a/src/core/display/chunks/cameraChunk.js +++ b/src/core/display/chunks/cameraChunk.js @@ -4,13 +4,13 @@ SceneJS_ChunkFactory.createChunkType({ build : function() { - this._uPMatrixDraw = this.program.draw.getUniformLocation("SCENEJS_uPMatrix"); - this._uZNearDraw = this.program.draw.getUniformLocation("SCENEJS_uZNear"); - this._uZFarDraw = this.program.draw.getUniformLocation("SCENEJS_uZFar"); + 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.getUniformLocation("SCENEJS_uPMatrix"); - this._uZNearPick = this.program.pick.getUniformLocation("SCENEJS_uZNear"); - this._uZFarPick = this.program.pick.getUniformLocation("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(frameCtx) { @@ -22,15 +22,15 @@ SceneJS_ChunkFactory.createChunkType({ var gl = this.program.gl; if (this._uPMatrixDraw) { - gl.uniformMatrix4fv(this._uPMatrixDraw, gl.FALSE, this.core.mat); + this._uPMatrixDraw.setValue(this.core.mat); } if (this._uZNearDraw) { - gl.uniform1f(this._uZNearDraw, this.core.optics.near); + this._uZNearDraw.setValue(this.core.optics.near); } if (this._uZFarDraw) { - gl.uniform1f(this._uZFarDraw, this.core.optics.far); + this._uZFarDraw.setValue(this.core.optics.far); } frameCtx.cameraMat = this.core.mat; // Query only in draw pass @@ -46,17 +46,17 @@ SceneJS_ChunkFactory.createChunkType({ var gl = this.program.gl; if (this._uPMatrixPick) { - gl.uniformMatrix4fv(this._uPMatrixPick, gl.FALSE, this.core.mat); + this._uPMatrixPick.setValue(this.core.mat); } if (frameCtx.rayPick) { // Z-pick pass: feed near and far clip planes into shader if (this._uZNearPick) { - gl.uniform1f(this._uZNearPick, this.core.optics.near); + this._uZNearPick.setValue(this.core.optics.near); } if (this._uZFarPick) { - gl.uniform1f(this._uZFarPick, this.core.optics.far); + this._uZFarPick.setValue(this.core.optics.far); } } diff --git a/src/core/display/chunks/clipsChunk.js b/src/core/display/chunks/clipsChunk.js index 7cd8c084..c051d708 100644 --- a/src/core/display/chunks/clipsChunk.js +++ b/src/core/display/chunks/clipsChunk.js @@ -13,8 +13,8 @@ SceneJS_ChunkFactory.createChunkType({ for (var i = 0, len = this.core.clips.length; i < len; i++) { this._draw[i] = { - uClipMode :draw.getUniformLocation("SCENEJS_uClipMode" + i), - uClipNormalAndDist: draw.getUniformLocation("SCENEJS_uClipNormalAndDist" + i) + uClipMode :draw.getUniform("SCENEJS_uClipMode" + i), + uClipNormalAndDist: draw.getUniform("SCENEJS_uClipNormalAndDist" + i) }; } @@ -24,8 +24,8 @@ SceneJS_ChunkFactory.createChunkType({ for (var i = 0, len = this.core.clips.length; i < len; i++) { this._pick[i] = { - uClipMode :pick.getUniformLocation("SCENEJS_uClipMode" + i), - uClipNormalAndDist: pick.getUniformLocation("SCENEJS_uClipNormalAndDist" + i) + uClipMode :pick.getUniform("SCENEJS_uClipMode" + i), + uClipNormalAndDist: pick.getUniform("SCENEJS_uClipNormalAndDist" + i) }; } }, @@ -56,16 +56,16 @@ SceneJS_ChunkFactory.createChunkType({ if (clip.mode == "inside") { - gl.uniform1f(mode, 2); - gl.uniform4fv(normalAndDist, clip.normalAndDist); + mode.setValue(2); + normalAndDist.setValue(clip.normalAndDist); } else if (clip.mode == "outside") { - gl.uniform1f(mode, 1); - gl.uniform4fv(normalAndDist, clip.normalAndDist); + mode.setValue(1); + normalAndDist.setValue(clip.normalAndDist); } else { // disabled - gl.uniform1f(mode, 0); + mode.setValue(0); } } } diff --git a/src/core/display/chunks/drawChunk.js b/src/core/display/chunks/drawChunk.js index ae03679b..95b9e3a4 100644 --- a/src/core/display/chunks/drawChunk.js +++ b/src/core/display/chunks/drawChunk.js @@ -3,7 +3,7 @@ */ SceneJS_ChunkFactory.createChunkType({ - type:"draw", + type: "draw", /** * As we apply a list of state chunks in a {@link SceneJS_Display}, we track the ID of each chunk @@ -12,18 +12,31 @@ SceneJS_ChunkFactory.createChunkType({ * We don't want that for draw chunks however, because they contain GL drawElements calls, * which we need to do for each object. */ - unique:true, + unique: true, - build:function () { - this._depthModeDraw = this.program.draw.getUniformLocation("SCENEJS_uDepthMode"); - this._depthModePick = this.program.pick.getUniformLocation("SCENEJS_uDepthMode"); + build: function () { + this._depthModeDraw = this.program.draw.getUniform("SCENEJS_uDepthMode"); + this._depthModePick = this.program.pick.getUniform("SCENEJS_uDepthMode"); }, - drawAndPick:function (frameCtx) { + drawAndPick: function (frameCtx) { + var gl = this.program.gl; + var indexType = this.program.UINT_INDEX_ENABLED ? gl.UNSIGNED_INT : gl.UNSIGNED_SHORT; - gl.uniform1i(frameCtx.pick ? this._depthModePick : this._depthModeDraw, frameCtx.depthMode); + + if (frameCtx.pick) { + if (this._depthModePick) { + this._depthModePick.setValue(frameCtx.depthMode); + } + } else { + if (this._depthModeDraw) { + this._depthModeDraw.setValue(frameCtx.depthMode); + } + } + gl.drawElements(this.core.primitive, this.core.indexBuf.numItems, indexType, 0); + //frameCtx.textureUnit = 0; } }); diff --git a/src/core/display/chunks/flagsChunk.js b/src/core/display/chunks/flagsChunk.js index dd0350c4..94685b2c 100644 --- a/src/core/display/chunks/flagsChunk.js +++ b/src/core/display/chunks/flagsChunk.js @@ -9,11 +9,12 @@ SceneJS_ChunkFactory.createChunkType({ var draw = this.program.draw; - this._uClippingDraw = draw.getUniformLocation("SCENEJS_uClipping"); + this._uClippingDraw = draw.getUniform("SCENEJS_uClipping"); + this._uSolidDraw = draw.getUniform("SCENEJS_uSolid"); var pick = this.program.pick; - this._uClippingPick = pick.getUniformLocation("SCENEJS_uClipping"); + this._uClippingPick = pick.getUniform("SCENEJS_uClipping"); }, drawAndPick: function (frameCtx) { @@ -66,13 +67,19 @@ SceneJS_ChunkFactory.createChunkType({ } if (frameCtx.pick) { - gl.uniform1i(this._uClippingPick, this.core.clipping); + + if (this._uClippingPick) { + this._uClippingPick.setValue(this.core.clipping); + } } else { - var drawUniforms = (this.core.clipping ? 1 : 0); - if (this.program.drawUniformFlags != drawUniforms) { - gl.uniform1i(this._uClippingDraw, this.core.clipping); - this.program.drawUniformFlags = drawUniforms; + + if (this._uClippingDraw) { + this._uClippingDraw.setValue(this.core.clipping); + } + + if (this._uSolidDraw) { + this._uSolidDraw.setValue(this.core.solid); } } } diff --git a/src/core/display/chunks/geometryChunk.js b/src/core/display/chunks/geometryChunk.js index f091031a..25cfaa00 100644 --- a/src/core/display/chunks/geometryChunk.js +++ b/src/core/display/chunks/geometryChunk.js @@ -18,13 +18,13 @@ SceneJS_ChunkFactory.createChunkType({ this._aMorphVertexDraw = draw.getAttribute("SCENEJS_aMorphVertex"); this._aMorphNormalDraw = draw.getAttribute("SCENEJS_aMorphNormal"); - this._uMorphFactorDraw = draw.getUniformLocation("SCENEJS_uMorphFactor"); + this._uMorphFactorDraw = draw.getUniform("SCENEJS_uMorphFactor"); var pick = this.program.pick; this._aVertexPick = pick.getAttribute("SCENEJS_aVertex"); this._aMorphVertexPick = pick.getAttribute("SCENEJS_aMorphVertex"); - this._uMorphFactorPick = pick.getUniformLocation("SCENEJS_uMorphFactor"); + this._uMorphFactorPick = pick.getUniform("SCENEJS_uMorphFactor"); this.VAO = null; this.VAOMorphKey1 = 0; @@ -80,7 +80,7 @@ SceneJS_ChunkFactory.createChunkType({ setDrawMorphFactor:function () { if (this._uMorphFactorDraw) { - this.program.gl.uniform1f(this._uMorphFactorDraw, this.core.factor); // Bind LERP factor + this._uMorphFactorDraw.setValue*(this.core.factor); // Bind LERP factor } }, @@ -176,7 +176,7 @@ SceneJS_ChunkFactory.createChunkType({ } if (this._uMorphFactorPick) { - this.program.gl.uniform1f(this._uMorphFactorPick, this.core.factor); // Bind LERP factor + this._uMorphFactorPick.setValue(this.core.factor); // Bind LERP factor } }, diff --git a/src/core/display/chunks/lightsChunk.js b/src/core/display/chunks/lightsChunk.js index f7851aea..cac96e98 100644 --- a/src/core/display/chunks/lightsChunk.js +++ b/src/core/display/chunks/lightsChunk.js @@ -23,20 +23,20 @@ SceneJS_ChunkFactory.createChunkType({ switch (lights[i].mode) { case "ambient": - this._uAmbientColor[i] = (program.draw.getUniformLocation("SCENEJS_uAmbientColor")); + this._uAmbientColor[i] = (program.draw.getUniform("SCENEJS_uAmbientColor")); break; case "dir": - this._uLightColor[i] = program.draw.getUniformLocation("SCENEJS_uLightColor" + i); + this._uLightColor[i] = program.draw.getUniform("SCENEJS_uLightColor" + i); this._uLightPos[i] = null; - this._uLightDir[i] = program.draw.getUniformLocation("SCENEJS_uLightDir" + i); + this._uLightDir[i] = program.draw.getUniform("SCENEJS_uLightDir" + i); break; case "point": - this._uLightColor[i] = program.draw.getUniformLocation("SCENEJS_uLightColor" + i); - this._uLightPos[i] = program.draw.getUniformLocation("SCENEJS_uLightPos" + i); + this._uLightColor[i] = program.draw.getUniform("SCENEJS_uLightColor" + i); + this._uLightPos[i] = program.draw.getUniform("SCENEJS_uLightPos" + i); this._uLightDir[i] = null; - this._uLightAttenuation[i] = program.draw.getUniformLocation("SCENEJS_uLightAttenuation" + i); + this._uLightAttenuation[i] = program.draw.getUniform("SCENEJS_uLightAttenuation" + i); break; } } @@ -58,24 +58,24 @@ SceneJS_ChunkFactory.createChunkType({ light = lights[i]; if (this._uAmbientColor[i]) { - gl.uniform3fv(this._uAmbientColor[i], light.color); + this._uAmbientColor[i].setValue(light.color); } else { if (this._uLightColor[i]) { - gl.uniform3fv(this._uLightColor[i], light.color); + this._uLightColor[i].setValue(light.color); } if (this._uLightPos[i]) { - gl.uniform3fv(this._uLightPos[i], light.pos); + this._uLightPos[i].setValue(light.pos); if (this._uLightAttenuation[i]) { - gl.uniform3fv(this._uLightAttenuation[i], light.attenuation); + this._uLightAttenuation[i].setValue(light.attenuation); } } if (this._uLightDir[i]) { - gl.uniform3fv(this._uLightDir[i], light.dir); + this._uLightDir[i].setValue(light.dir); } } } diff --git a/src/core/display/chunks/lookAtChunk.js b/src/core/display/chunks/lookAtChunk.js index 91c13adf..be5ffae2 100644 --- a/src/core/display/chunks/lookAtChunk.js +++ b/src/core/display/chunks/lookAtChunk.js @@ -7,11 +7,11 @@ SceneJS_ChunkFactory.createChunkType({ build : function() { - this._uvMatrixDraw = this.program.draw.getUniformLocation("SCENEJS_uVMatrix"); - this._uVNMatrixDraw = this.program.draw.getUniformLocation("SCENEJS_uVNMatrix"); - this._uWorldEyeDraw = this.program.draw.getUniformLocation("SCENEJS_uWorldEye"); + 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.getUniformLocation("SCENEJS_uVMatrix"); + this._uvMatrixPick = this.program.pick.getUniform("SCENEJS_uVMatrix"); }, draw : function(frameCtx) { @@ -23,15 +23,15 @@ SceneJS_ChunkFactory.createChunkType({ var gl = this.program.gl; if (this._uvMatrixDraw) { - gl.uniformMatrix4fv(this._uvMatrixDraw, gl.FALSE, this.core.mat); + this._uvMatrixDraw.setValue(this.core.mat); } if (this._uVNMatrixDraw) { - gl.uniformMatrix4fv(this._uVNMatrixDraw, gl.FALSE, this.core.normalMat); + this._uVNMatrixDraw.setValue(this.core.normalMat); } if (this._uWorldEyeDraw) { - gl.uniform3fv(this._uWorldEyeDraw, this.core.lookAt.eye); + this._uWorldEyeDraw.setValue(this.core.lookAt.eye); } frameCtx.viewMat = this.core.mat; @@ -42,7 +42,7 @@ SceneJS_ChunkFactory.createChunkType({ var gl = this.program.gl; if (this._uvMatrixPick) { - gl.uniformMatrix4fv(this._uvMatrixPick, gl.FALSE, this.core.mat); + this._uvMatrixPick.setValue(this.core.mat); } frameCtx.viewMat = this.core.mat; diff --git a/src/core/display/chunks/materialChunk.js b/src/core/display/chunks/materialChunk.js index 791e7f0d..404c8f71 100644 --- a/src/core/display/chunks/materialChunk.js +++ b/src/core/display/chunks/materialChunk.js @@ -5,55 +5,44 @@ SceneJS_ChunkFactory.createChunkType({ type: "material", - build : function() { + build: function () { var draw = this.program.draw; - this._uMaterialBaseColor = draw.getUniformLocation("SCENEJS_uMaterialColor"); - this._uMaterialSpecularColor = draw.getUniformLocation("SCENEJS_uMaterialSpecularColor"); - this._uMaterialSpecular = draw.getUniformLocation("SCENEJS_uMaterialSpecular"); - this._uMaterialShine = draw.getUniformLocation("SCENEJS_uMaterialShine"); - this._uMaterialEmit = draw.getUniformLocation("SCENEJS_uMaterialEmit"); - this._uMaterialAlpha = draw.getUniformLocation("SCENEJS_uMaterialAlpha"); + this._uMaterialBaseColor = draw.getUniform("SCENEJS_uMaterialColor"); + this._uMaterialSpecularColor = draw.getUniform("SCENEJS_uMaterialSpecularColor"); + this._uMaterialSpecular = draw.getUniform("SCENEJS_uMaterialSpecular"); + this._uMaterialShine = draw.getUniform("SCENEJS_uMaterialShine"); + this._uMaterialEmit = draw.getUniform("SCENEJS_uMaterialEmit"); + this._uMaterialAlpha = draw.getUniform("SCENEJS_uMaterialAlpha"); }, - draw : function() { + draw: function () { var gl = this.program.gl; - var materialSettings = this.program.draw.materialSettings; if (this._uMaterialBaseColor) { - gl.uniform3fv(this._uMaterialBaseColor, this.core.baseColor); + this._uMaterialBaseColor.setValue(this.core.baseColor); } - if (this._uMaterialSpecularColor && - (materialSettings.specularColor[0] != this.core.specularColor[0] || - materialSettings.specularColor[1] != this.core.specularColor[1] || - materialSettings.specularColor[2] != this.core.specularColor[2])) { - gl.uniform3fv(this._uMaterialSpecularColor, this.core.specularColor); - materialSettings.specularColor[0] = this.core.specularColor[0]; - materialSettings.specularColor[1] = this.core.specularColor[1]; - materialSettings.specularColor[2] = this.core.specularColor[2]; + if (this._uMaterialSpecularColor) { + this._uMaterialSpecularColor.setValue(this.core.specularColor); } - if (this._uMaterialSpecular && materialSettings.specular != this.core.specular) { - gl.uniform1f(this._uMaterialSpecular, this.core.specular); - materialSettings.specular = this.core.specular; + if (this._uMaterialSpecular) { + this._uMaterialSpecular.setValue(this.core.specular); } - if (this._uMaterialShine && materialSettings.shine != this.core.shine) { - gl.uniform1f(this._uMaterialShine, this.core.shine); - materialSettings.shine = this.core.shine; + if (this._uMaterialShine) { + this._uMaterialShine.setValue(this.core.shine); } - if (this._uMaterialEmit && materialSettings.emit != this.core.emit) { - gl.uniform1f(this._uMaterialEmit, this.core.emit); - materialSettings.emit = this.core.emit; + if (this._uMaterialEmit) { + this._uMaterialEmit.setValue(this.core.emit); } - if (this._uMaterialAlpha && materialSettings.alpha != this.core.alpha) { - gl.uniform1f(this._uMaterialAlpha, this.core.alpha); - materialSettings.alpha = this.core.alpha; + if (this._uMaterialAlpha) { + this._uMaterialAlpha.setValue(this.core.alpha); } } }); diff --git a/src/core/display/chunks/nameChunk.js b/src/core/display/chunks/nameChunk.js index a3bd7b83..18cdc652 100644 --- a/src/core/display/chunks/nameChunk.js +++ b/src/core/display/chunks/nameChunk.js @@ -5,11 +5,11 @@ SceneJS_ChunkFactory.createChunkType({ type: "name", - build : function() { - this._uPickColor = this.program.pick.getUniformLocation("SCENEJS_uPickColor"); + build: function () { + this._uPickColor = this.program.pick.getUniform("SCENEJS_uPickColor"); }, - pick : function(frameCtx) { + pick: function (frameCtx) { if (this._uPickColor && this.core.name) { @@ -19,7 +19,7 @@ SceneJS_ChunkFactory.createChunkType({ var g = frameCtx.pickIndex >> 8 & 0xFF; var r = frameCtx.pickIndex & 0xFF; - this.program.gl.uniform3fv(this._uPickColor, [r / 255, g / 255, b / 255]); + this._uPickColor.setValue([r / 255, g / 255, b / 255]); } } }); \ No newline at end of file diff --git a/src/core/display/chunks/programChunk.js b/src/core/display/chunks/programChunk.js index dbbac5cf..c1085044 100644 --- a/src/core/display/chunks/programChunk.js +++ b/src/core/display/chunks/programChunk.js @@ -5,9 +5,9 @@ SceneJS_ChunkFactory.createChunkType({ build : function() { // Note that "program" chunks are always after "renderTarget" chunks - this._depthModeDraw = this.program.draw.getUniformLocation("SCENEJS_uDepthMode"); - this._depthModePick = this.program.pick.getUniformLocation("SCENEJS_uDepthMode"); - this._rayPickMode = this.program.pick.getUniformLocation("SCENEJS_uRayPickMode"); + this._depthModeDraw = this.program.draw.getUniform("SCENEJS_uDepthMode"); + this._depthModePick = this.program.pick.getUniform("SCENEJS_uDepthMode"); + this._rayPickMode = this.program.pick.getUniform("SCENEJS_uRayPickMode"); }, draw : function(frameCtx) { @@ -15,7 +15,9 @@ SceneJS_ChunkFactory.createChunkType({ drawProgram.bind(); frameCtx.textureUnit = 0; var gl = this.program.gl; - gl.uniform1i(this._depthModeDraw, frameCtx.depthMode); + if (this._depthModeDraw) { + this._depthModeDraw.setValue(frameCtx.depthMode); + } if (!frameCtx.VAO) { for (var i = 0; i < 10; i++) { gl.disableVertexAttribArray(i); @@ -29,8 +31,12 @@ SceneJS_ChunkFactory.createChunkType({ var pickProgram = this.program.pick; pickProgram.bind(); var gl = this.program.gl; - gl.uniform1i(this._rayPickMode, frameCtx.rayPick); - gl.uniform1i(this._depthModePick, frameCtx.depthMode); + if (this._rayPickMode) { + this._rayPickMode.setValue(frameCtx.rayPick); + } + if (this._depthModePick) { + this._depthModePick.setValue(frameCtx.depthMode); + } frameCtx.textureUnit = 0; for (var i = 0; i < 10; i++) { gl.disableVertexAttribArray(i); diff --git a/src/core/display/chunks/xformChunk.js b/src/core/display/chunks/xformChunk.js index 529ab5a5..08e135f5 100644 --- a/src/core/display/chunks/xformChunk.js +++ b/src/core/display/chunks/xformChunk.js @@ -2,19 +2,19 @@ SceneJS_ChunkFactory.createChunkType({ type: "xform", - build : function() { + build: function () { var draw = this.program.draw; - this._uMatLocationDraw = draw.getUniformLocation("SCENEJS_uMMatrix"); - this._uNormalMatLocationDraw = draw.getUniformLocation("SCENEJS_uMNMatrix"); + this._uMatLocationDraw = draw.getUniform("SCENEJS_uMMatrix"); + this._uNormalMatLocationDraw = draw.getUniform("SCENEJS_uMNMatrix"); var pick = this.program.pick; - this._uMatLocationPick = pick.getUniformLocation("SCENEJS_uMMatrix"); + this._uMatLocationPick = pick.getUniform("SCENEJS_uMMatrix"); }, - draw : function(frameCtx) { + draw: function (frameCtx) { /* Rebuild core's matrix from matrices at cores on path up to root */ @@ -25,17 +25,17 @@ SceneJS_ChunkFactory.createChunkType({ var gl = this.program.gl; if (this._uMatLocationDraw) { - gl.uniformMatrix4fv(this._uMatLocationDraw, gl.FALSE, this.core.mat); + this._uMatLocationDraw.setValue(this.core.mat); } if (this._uNormalMatLocationDraw) { - gl.uniformMatrix4fv(this._uNormalMatLocationDraw, gl.FALSE, this.core.normalMat); + this._uNormalMatLocationDraw.setValue(this.core.normalMat); } frameCtx.modelMat = this.core.mat; }, - pick : function(frameCtx) { + pick: function (frameCtx) { /* Rebuild core's matrix from matrices at cores on path up to root */ @@ -46,7 +46,7 @@ SceneJS_ChunkFactory.createChunkType({ var gl = this.program.gl; if (this._uMatLocationPick) { - gl.uniformMatrix4fv(this._uMatLocationPick, gl.FALSE, this.core.mat); + this._uMatLocationPick.setValue(this.core.mat); } frameCtx.modelMat = this.core.mat; diff --git a/src/core/display/display.js b/src/core/display/display.js index 2d36c6c3..86dfe8ee 100644 --- a/src/core/display/display.js +++ b/src/core/display/display.js @@ -1036,7 +1036,6 @@ SceneJS_Display.prototype._doDrawList = function (params) { var VAO = gl.getExtension("OES_vertex_array_object"); frameCtx.VAO = (VAO) ? VAO : null; - frameCtx.VAO = null; gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight); diff --git a/src/core/display/program.js b/src/core/display/program.js index 0eaac1ed..c5e5d905 100644 --- a/src/core/display/program.js +++ b/src/core/display/program.js @@ -65,11 +65,6 @@ var SceneJS_Program = function(id, hash, source, gl) { * This is also re-called to re-create them after WebGL context loss. */ SceneJS_Program.prototype.build = function(gl) { - /** - * Current draw uniform state cached as a bitfield to avoid costly extra uniform1i calls - * @type Number - */ - this.drawUniformFlags = 0; this.gl = gl; this.draw = new SceneJS._webgl.Program(gl, [this.source.drawVertexSrc.join("\n")], [this.source.drawFragmentSrc.join("\n")]); diff --git a/src/core/display/programSourceFactory.js b/src/core/display/programSourceFactory.js index 858ff303..f7cb7921 100644 --- a/src/core/display/programSourceFactory.js +++ b/src/core/display/programSourceFactory.js @@ -6,7 +6,6 @@ var SceneJS_ProgramSourceFactory = new (function () { this._sourceCache = {}; // Source codes are shared across all scenes - /** * Get sourcecode for a program to render the given states */ @@ -43,9 +42,6 @@ var SceneJS_ProgramSourceFactory = new (function () { this._composePickingVertexShader = function (states) { var morphing = !!states.morphGeometry.targets; var src = [ - - "precision mediump float;", - "attribute vec3 SCENEJS_aVertex;", "uniform mat4 SCENEJS_uMMatrix;", "uniform mat4 SCENEJS_uVMatrix;", @@ -88,8 +84,10 @@ var SceneJS_ProgramSourceFactory = new (function () { var clipping = states.clips.clips.length > 0; + var floatPrecision = getFSFloatPrecision(states._canvas.gl); + var src = [ - "precision mediump float;" + "precision " + floatPrecision + " float;" ]; src.push("varying vec4 SCENEJS_vWorldVertex;"); @@ -210,9 +208,7 @@ var SceneJS_ProgramSourceFactory = new (function () { var clipping = states.clips.clips.length > 0; var morphing = !!states.morphGeometry.targets; - var src = [ - "precision mediump float;" - ]; + var src = []; src.push("uniform mat4 SCENEJS_uMMatrix;"); // Model matrix src.push("uniform mat4 SCENEJS_uVMatrix;"); // View matrix @@ -506,12 +502,15 @@ var SceneJS_ProgramSourceFactory = new (function () { var texturing = this._isTexturing(states); var cubeMapping = this._isCubeMapping(states); var normals = this._hasNormals(states); + var solid = states.flags.solid; var tangents = this._hasTangents(states); var clipping = states.clips.clips.length > 0; + var floatPrecision = getFSFloatPrecision(states._canvas.gl); + var src = ["\n"]; - src.push("precision mediump float;"); + src.push("precision " + floatPrecision + " float;"); if (clipping) { @@ -564,10 +563,13 @@ var SceneJS_ProgramSourceFactory = new (function () { } } - /* True when lighting - */ + // True when lighting src.push("uniform bool SCENEJS_uClipping;"); + // True when interior surfaces of solid cross-sections + // are to be rendered without texture and shading + src.push("uniform bool SCENEJS_uSolid;"); + // Added in v4.0 to support depth targets src.push("uniform bool SCENEJS_uDepthMode;"); @@ -630,6 +632,18 @@ var SceneJS_ProgramSourceFactory = new (function () { src.push("}"); } + if (normals) { + + if (solid) { + + src.push(" float a = dot(normalize(SCENEJS_vViewNormal), normalize(SCENEJS_vViewEyeVec));"); + src.push(" if (a < 0.0) {"); + src.push(" gl_FragColor = vec4(0.4, 0.4, 1.0, 1.0);"); + src.push(" return;"); + src.push(" }"); + } + } + src.push(" vec3 ambient= SCENEJS_uAmbientColor;"); if (texturing && states.geometry.uvBuf && fragmentHooks.texturePos) { @@ -906,4 +920,20 @@ var SceneJS_ProgramSourceFactory = new (function () { return false; } + function getFSFloatPrecision(gl) { + if (!gl.getShaderPrecisionFormat) { + return "mediump"; + } + + if (gl.getShaderPrecisionFormat(gl.FRAGMENT_SHADER, gl.HIGH_FLOAT).precision > 0) { + return "highp"; + } + + if (gl.getShaderPrecisionFormat(gl.FRAGMENT_SHADER, gl.MEDIUM_FLOAT).precision > 0) { + return "mediump"; + } + + return "lowp"; + } + })(); \ No newline at end of file diff --git a/src/core/scene/flags.js b/src/core/scene/flags.js index 99503d75..2f059973 100644 --- a/src/core/scene/flags.js +++ b/src/core/scene/flags.js @@ -15,7 +15,8 @@ backfaces: true, // Show backfaces frontface: "ccw", // Default vertex winding for front face reflective: true, // Reflects reflection node cubemap, if it exists, by default. - hash: "refl" + solid: false, // When true, renders backfaces without texture or shading, for a cheap solid cross-section effect + hash: "refl;;" }; var coreStack = []; @@ -45,7 +46,8 @@ this._core.backfaces = true; // Show backfaces this._core.frontface = "ccw"; // Default vertex winding for front face this._core.reflective = true; // Reflects reflection node cubemap, if it exists, by default. - if (params.flags) { // 'flags' property is actually optional in the node definition + this._core.solid = false; // Renders backfaces without texture or shading, for a cheap solid cross-section effect + if (params.flags) { // 'flags' property is actually optional in the node definition this.setFlags(params.flags); } } @@ -91,6 +93,14 @@ this._engine.branchDirty(this); this._engine.display.imageDirty = true; } + + if (flags.solid != undefined) { + core.solid = flags.solid; + core.hash = core.reflective ? "refl" : ""; + this._engine.branchDirty(this); + this._engine.display.imageDirty = true; + } + return this; }; @@ -117,7 +127,8 @@ transparent: core.transparent, backfaces: core.backfaces, frontface: core.frontface, - reflective: core.reflective + reflective: core.reflective, + solid: core.solid }; }; @@ -202,7 +213,7 @@ reflective = !!reflective; if (this._core.reflective != reflective) { this._core.reflective = reflective; - this._core.hash = reflective ? "refl" : ""; + this._core.hash = (reflective ? "refl" : "") + this._core.solid ? ";s" : ";;"; this._engine.branchDirty(this); this._engine.display.imageDirty = true; } @@ -213,6 +224,22 @@ return this._core.reflective; }; + SceneJS.Flags.prototype.setSolid = function(solid) { + solid = !!solid; + if (this._core.solid != solid) { + this._core.solid = solid; + this._core.hash = (this._core.reflective ? "refl" : "") + solid ? ";s;" : ";;"; + this._engine.branchDirty(this); + this._engine.display.imageDirty = true; + } + return this; + }; + + SceneJS.Flags.prototype.getSolid = function() { + return this._core.solid; + }; + + SceneJS.Flags.prototype._compile = function(ctx) { this._engine.display.flags = coreStack[stackLen++] = this._core; this._compileNodes(ctx); diff --git a/src/core/scene/morphGeometry.js b/src/core/scene/morphGeometry.js index d2c98432..40a138ef 100644 --- a/src/core/scene/morphGeometry.js +++ b/src/core/scene/morphGeometry.js @@ -321,6 +321,8 @@ new (function () { */ core.factor = (factor - keys[key1]) / (keys[key2] - keys[key1]); + this._factor = factor; + var morphUpdate = frameUpdate || oldFactor != core.factor; core.key1 = key1; @@ -338,7 +340,7 @@ new (function () { }; SceneJS.MorphGeometry.prototype.getFactor = function () { - return this._core.factor; + return this._factor; }; SceneJS.MorphGeometry.prototype.getKeys = function () { diff --git a/src/core/webgl/uniform.js b/src/core/webgl/uniform.js index 01482908..7f754b5f 100644 --- a/src/core/webgl/uniform.js +++ b/src/core/webgl/uniform.js @@ -1,82 +1,156 @@ - SceneJS._webgl.Uniform = function (gl, program, name, type, size, location, index, logging) { var func = null; - this.numberValue = false; - if (type == gl.BOOL) { - this.numberValue = true; + + var value = null; + + if (type === gl.BOOL) { + func = function (v) { + if (value === v) { + return; + } + value = v; gl.uniform1i(location, v); }; - } else if (type == gl.BOOL_VEC2) { + + } else if (type === gl.BOOL_VEC2) { + func = function (v) { + if (value !== null && value[0] === v[0] && value[1] === v[1]) { + return; + } + value = v; gl.uniform2iv(location, v); }; - } else if (type == gl.BOOL_VEC3) { + + } else if (type === gl.BOOL_VEC3) { + func = function (v) { + if (value !== null && value[0] === v[0] && value[1] === v[1] && value[2] === v[2]) { + return; + } + value = v; gl.uniform3iv(location, v); }; - } else if (type == gl.BOOL_VEC4) { + + } else if (type === gl.BOOL_VEC4) { + func = function (v) { + if (value !== null && value[0] === v[0] && value[1] === v[1] && value[2] === v[2] && value[3] === v[3]) { + return; + } + value = v; gl.uniform4iv(location, v); }; - } else if (type == gl.INT) { - this.numberValue = true; + + } else if (type === gl.INT) { + func = function (v) { + if (value === v) { + return; + } + value = v; gl.uniform1iv(location, v); }; - } else if (type == gl.INT_VEC2) { + + } else if (type === gl.INT_VEC2) { + func = function (v) { + if (value !== null && value[0] === v[0] && value[1] === v[1]) { + return; + } + value = v; gl.uniform2iv(location, v); }; - } else if (type == gl.INT_VEC3) { + + } else if (type === gl.INT_VEC3) { + func = function (v) { + if (value !== null && value[0] === v[0] && value[1] === v[1] && value[2] === v[2]) { + return; + } + value = v; gl.uniform3iv(location, v); }; - } else if (type == gl.INT_VEC4) { + + } else if (type === gl.INT_VEC4) { + func = function (v) { + if (value !== null && value[0] === v[0] && value[1] === v[1] && value[2] === v[2] && value[3] === v[3]) { + return; + } + value = v; gl.uniform4iv(location, v); }; - } else if (type == gl.FLOAT) { - this.numberValue = true; + + } else if (type === gl.FLOAT) { + func = function (v) { + if (value === v) { + return; + } + value = v; gl.uniform1f(location, v); }; - } else if (type == gl.FLOAT_VEC2) { + + } else if (type === gl.FLOAT_VEC2) { + func = function (v) { + if (value !== null && value[0] === v[0] && value[1] === v[1]) { + return; + } + value = v; gl.uniform2fv(location, v); }; - } else if (type == gl.FLOAT_VEC3) { + + } else if (type === gl.FLOAT_VEC3) { + func = function (v) { + if (value !== null && value[0] === v[0] && value[1] === v[1] && value[2] === v[2]) { + return; + } + value = v; gl.uniform3fv(location, v); }; - } else if (type == gl.FLOAT_VEC4) { + + } else if (type === gl.FLOAT_VEC4) { + func = function (v) { + if (value !== null && value[0] === v[0] && value[1] === v[1] && value[2] === v[2] && value[3] === v[3]) { + return; + } + value = v; gl.uniform4fv(location, v); }; - } else if (type == gl.FLOAT_MAT2) { + + } else if (type === gl.FLOAT_MAT2) { + func = function (v) { gl.uniformMatrix2fv(location, gl.FALSE, v); }; - } else if (type == gl.FLOAT_MAT3) { + + } else if (type === gl.FLOAT_MAT3) { + func = function (v) { gl.uniformMatrix3fv(location, gl.FALSE, v); }; - } else if (type == gl.FLOAT_MAT4) { + + } else if (type === gl.FLOAT_MAT4) { + func = function (v) { + + // Caching this matrix is actually slower than not caching + gl.uniformMatrix4fv(location, gl.FALSE, v); }; + } else { throw "Unsupported shader uniform type: " + type; } this.setValue = func; - - this.getValue = function () { - return gl.getUniform(program, location); - }; - this.getLocation = function () { return location; };